Skip to content

Commit d46ec4f

Browse files
author
Abhi Singh
committed
initial commit
1 parent 880db69 commit d46ec4f

File tree

14 files changed

+9767
-1
lines changed

14 files changed

+9767
-1
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
screenshots
3+
videos
4+
downloads
5+
mochawesome-report
6+
report
7+
log
8+
*.log
9+
results
10+
build_artifacts

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
# cucumber-js-cypress-browserstack
2-
Creating a sample repo for Cypress - Cucumber
2+
3+
## Introduction
4+
5+
Cypress is a next generation front end testing tool built for the modern web. Cucumber is a software tool that supports behavior-driven development (BDD).
6+
7+
This BrowserStack Example repository demonstrates a Cypress framework with parallel testing capabilities. The Cypress test scripts are written for the open source [BrowserStack Demo web application](https://bstackdemo.com) ([Github](https://github.com/browserstack/browserstack-demo-app)). This BrowserStack Demo App is an e-commerce web application which showcases multiple real-world user scenarios. The app is bundled with offers data, orders data and products data that contains everything you need to start using the app and run tests out-of-the-box.
8+
9+
The Cypress tests are run on different platforms like on-prem and BrowserStack using various run configurations and test capabilities.
10+
11+
## Pre-requisites
12+
13+
You need BrowserStack credentials to be able to run Cypress tests. You have to replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in the sample scripts in this repository with your BrowserStack credentials which can be found in your [Account Settings](https://www.browserstack.com/accounts/settings) page.
14+
15+
**Alternatively, you can set the environment variables `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your credentials and all the scripts in this repository should work fine**
16+
17+
## Run Cypress test on BrowserStack
18+
19+
1. Clone this repository
20+
2. Install the dependencies using `npm install`
21+
3. Run the sample script using `npm run bstack`
22+
23+
## Run sample test on privately hosted websites
24+
25+
1. Clone the [BrowserStack demo application](https://github.com/browserstack/browserstack-demo-app) repository.
26+
27+
```sh
28+
git clone https://github.com/browserstack/browserstack-demo-app
29+
```
30+
31+
2. Please follow the README.md on the BrowserStack demo application repository to install and start the dev server on localhost.
32+
3. You can then run the sample Local test using `npm run bstack-local`
33+
34+
## Additional Resources
35+
36+
- View your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
37+
- Documentation for writing [Automate test scripts in Cypress](https://www.browserstack.com/docs/automate/cypress)
38+
- [List of Browsers & mobile devices](https://www.browserstack.com/list-of-browsers-and-platforms/cypress_testing) for automation testing on BrowserStack
39+
- For testing public web applications behind IP restriction, [Inbound IP Whitelisting](https://www.browserstack.com/local-testing/inbound-ip-whitelisting) can be enabled with the [BrowserStack Enterprise](https://www.browserstack.com/enterprise) offering

cypress.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { defineConfig } = require("cypress");
2+
const cucumber = require("cypress-cucumber-preprocessor").default;
3+
4+
module.exports = defineConfig({
5+
watchForFileChanges: true,
6+
reporter: "mochawesome",
7+
8+
e2e: {
9+
setupNodeEvents(on, config) {
10+
on("file:preprocessor", cucumber());
11+
},
12+
specPattern: "**/*.feature",
13+
baseUrl: "https://bstackdemo.com/",
14+
excludeSpecPattern: ["*.js"],
15+
},
16+
});

cypress/e2e/e2e.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: End to End Feature
2+
3+
@e2e
4+
Scenario: End to End Scenario
5+
Given I navigate to website
6+
And I SignIn as "fav_user" with "testingisfun99" password
7+
And I add three products to cart
8+
And I click on Buy Button
9+
And I enter shipping details "first", "last", "test address", "test province" and "123456"
10+
And I click on Checkout Button
11+
And I click on "Orders" link
12+
Then I should see elements in list

cypress/support/e2e.js

Whitespace-only changes.

cypress/support/pages/login.page.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class login {
2+
username() {
3+
return cy.get("#username", { timeout: 30000 });
4+
}
5+
password() {
6+
return cy.get("#password", { timeout: 30000 });
7+
}
8+
logInButton() {
9+
return cy.get("#login-btn", { timeout: 30000 });
10+
}
11+
logOutButton() {
12+
return cy.get("#logout", { timeout: 30000 });
13+
}
14+
}
15+
export default login;

cypress/support/pages/orders.page.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class orders {
2+
checkout() {
3+
return cy.get("#checkout-shipping-continue", { timeout: 30000 });
4+
}
5+
return() {
6+
return cy.get(
7+
".button.button--tertiary.optimizedCheckout-buttonSecondary",
8+
{ timeout: 30000 }
9+
);
10+
}
11+
orders() {
12+
return cy.get("#orders", { timeout: 30000 });
13+
}
14+
}
15+
export default orders;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class purchase {
2+
item1() {
3+
return cy
4+
.get("#1", { timeout: 30000 })
5+
.should("be.visible")
6+
.children(".shelf-item__buy-btn");
7+
}
8+
item2() {
9+
return cy.get("#2").children(".shelf-item__buy-btn");
10+
}
11+
item3() {
12+
return cy.get("#5").children(".shelf-item__buy-btn");
13+
}
14+
buyButton() {
15+
return cy.get(".buy-btn");
16+
}
17+
}
18+
export default purchase;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const { Given, Then, And } = require("cypress-cucumber-preprocessor/steps");
2+
3+
require("cypress-xpath");
4+
5+
import Login from "../pages/login.page";
6+
import Purchase from "../pages/purchase.page";
7+
import Orders from "../pages/orders.page";
8+
9+
const login = new Login();
10+
const purchase = new Purchase();
11+
const orders = new Orders();
12+
13+
Given("I navigate to website", () => {
14+
cy.visit(Cypress.config().baseUrl + "signin");
15+
});
16+
17+
And("I SignIn as {string} with {string} password", (username, password) => {
18+
login
19+
.username()
20+
.should("be.visible")
21+
.click({ force: true })
22+
.type(username + "{enter}");
23+
login
24+
.password()
25+
.click({ force: true })
26+
.type(password + "{enter}");
27+
login.logInButton().click();
28+
});
29+
And("I add three products to cart", () => {
30+
purchase.item1().click({ force: true });
31+
purchase.item2().click({ force: true });
32+
purchase.item3().click({ force: true });
33+
});
34+
And("I click on Buy Button", () => {
35+
purchase.buyButton().click({ force: true });
36+
});
37+
And(
38+
"I enter shipping details {string}, {string}, {string}, {string} and {string}",
39+
(first, last, address, province, pincode) => {
40+
cy.get("#firstNameInput").type(first);
41+
cy.get("#lastNameInput").type(last);
42+
cy.get("#addressLine1Input").type(address);
43+
cy.get("#provinceInput").type(province);
44+
cy.get("#postCodeInput").type(pincode);
45+
}
46+
);
47+
And("I click on Checkout Button", () => {
48+
orders.checkout().click();
49+
cy.contains("Continue ").click();
50+
});
51+
And("I click on {string} link", (link) => {
52+
cy.contains(link).click();
53+
});
54+
Then("I should see elements in list", () => {
55+
cy.xpath("/html/body/div/main/div/div/div/div[2]/div/div[2]")
56+
.children("div")
57+
.should("have.length", 3);
58+
});

cypress_local.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { defineConfig } = require("cypress");
2+
const cucumber = require("cypress-cucumber-preprocessor").default;
3+
4+
module.exports = defineConfig({
5+
watchForFileChanges: true,
6+
reporter: "mochawesome",
7+
8+
e2e: {
9+
setupNodeEvents(on, config) {
10+
on("file:preprocessor", cucumber());
11+
},
12+
specPattern: "**/*.feature",
13+
baseUrl: "http://localhost:3000/",
14+
excludeSpecPattern: ["*.js"],
15+
},
16+
});

0 commit comments

Comments
 (0)