Skip to content

Commit

Permalink
Add credentials and endpoints file in fixtures, updated login.feature…
Browse files Browse the repository at this point in the history
… and login.js file
  • Loading branch information
haite4 committed Jul 29, 2024
1 parent 6c712bd commit 7a45676
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modules/
reports/
cucumber-report.html
jsonlogs/
screenshots/
videos/
downloads/
12 changes: 4 additions & 8 deletions cypress/e2e/feature/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ Feature: Login Page
Given the user is on the login page of the Saucedemo website

Scenario: Login with valid credentials
When the user enters the username "standard_user" and the password "secret_sauce" and clicks on the login button
When user logs in
Then the user should be redirected to the inventory page and see "Products" title on the page

Scenario: Login with blocked credentials
When the user enters the username "locked_out_user" and the password "secret_sauce" and clicks on the login button
When user logs in with locked out user creds
Then the error message "Epic sadface: Sorry, this user has been locked out." is displayed

Scenario: Login with incorrect Username
When a user provides incorrect credentials, and click on the login button
| username | password |
| testUsername | secret_sauce |
When user types in an invalid username
Then the error message "Epic sadface: Username and password do not match any user in this service" is displayed

Scenario: Login with incorrect Password
When a user provides incorrect credentials, and click on the login button
| username | password |
| standard_user | testPassword |
When user types in an invalid password
Then the error message "Epic sadface: Username and password do not match any user in this service" is displayed
3 changes: 2 additions & 1 deletion cypress/e2e/step_definitions/cart.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import cartPage from "../../pages/cartPage";
import inventoryPage from "../../pages/inventoryPage";
import endpoints from "../../fixtures/endpoints.json";

Given("the user adds a product to the cart", () => {
inventoryPage.clickAddToCartButton();
});

When("the user navigate to the cart page", () => {
inventoryPage.clickShoppingCartLink();
cy.url().should("include", "/cart.html");
cy.url().should("include", endpoints.cart);
});

When("the user clicks the {string} button for the product", (buttonLabel) => {
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/step_definitions/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import loginPage from "../../pages/loginPage";
import inventoryPage from "../../pages/inventoryPage";
import cartPage from "../../pages/cartPage";
import checkoutPage from "../../pages/checkoutPage";
import endpoints from "../../fixtures/endpoints.json";

Given("the user is on the checkout page of the Saucedemo website", () => {
cy.visit("/");
Expand Down Expand Up @@ -59,7 +60,7 @@ Then("the ckeckout page should display the following elements:", (table) => {
});

Then("the checkout page should display the order review page", () => {
cy.url().should("include", "/checkout-step-two.html");
cy.url().should("include", endpoints.checkout_step_two);
});

Then(
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/step_definitions/inventory.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import inventoryPage from "../../pages/inventoryPage";
import loginPage from "../../pages/loginPage";
import endpoints from "../../fixtures/endpoints.json";

Given("the user is on the inventory page of the Saucedemo website", () => {
cy.visit("/");
loginPage.login("standard_user", "secret_sauce");
cy.url().should("include", "/inventory.html");
cy.url().should("include", endpoints.inventory);
});

When("user view the list of products", () => {
Expand Down Expand Up @@ -115,5 +116,6 @@ Then("products should be sorted from {string} name", (sortOrder) => {
const sortedNames = [...names].sort((a, b) => b.localeCompare(a));
expect(names).to.deep.equal(sortedNames);
});
break;
}
});
33 changes: 18 additions & 15 deletions cypress/e2e/step_definitions/login.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";
import loginPage from "../../pages/loginPage";
import inventoryPage from "../../pages/inventoryPage";
import credentials from "../../fixtures/credentials.json";
import { faker } from "@faker-js/faker";
import endpoints from "../../fixtures/endpoints.json";

Given("the user is on the login page of the Saucedemo website", () => {
cy.visit("/");
});

When(
"the user enters the username {string} and the password {string} and clicks on the login button",
(username, password) => {
loginPage.login(username, password);
}
);
When("user logs in", () => {
loginPage.login(credentials.username, credentials.password);
});

When(
"a user provides incorrect credentials, and click on the login button",
(table) => {
table.hashes().forEach((row) => {
loginPage.login(row.username, row.password);
});
}
);
When("user logs in with locked out user creds", () => {
loginPage.login(credentials.locked_user, credentials.password);
});

When("user types in an invalid username", () => {
loginPage.login(faker.internet.password(), credentials.password);
});

When("user types in an invalid password", () => {
loginPage.login(credentials.username, faker.internet.password());
});

Then(
"the user should be redirected to the inventory page and see {string} title on the page",
(title) => {
cy.url().should("include", "/inventory.html");
cy.url().should("include", endpoints.inventory);
inventoryPage.titleOnPage.should("contain", title);
}
);
Expand Down
5 changes: 5 additions & 0 deletions cypress/fixtures/credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"username": "standard_user",
"password": "secret_sauce",
"locked_user": "locked_out_user"
}
5 changes: 5 additions & 0 deletions cypress/fixtures/endpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"inventory": "/inventory.html",
"checkout_step_two": "/checkout-step-two.html",
"cart" : "/cart.html"
}
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test:edge": "cypress run --browser edge --config-file configs/cypress.config.js",
"test:mobile": "cypress run --config-file configs/cypress.config.mobile.js",
"test:login:run": "cypress run --spec cypress/e2e/feature/login.feature --config-file configs/cypress.config.js",
"test:inventory:run": "cypress run --spec cypress/e2e/feature/inventory.feature --config-file configs/cypress.config.js",
"test:inventory:run": "cypress run --spec cypress/e2e/feature/inventory.feature --config-file configs/cypress.config.js",
"test:checkout:run": "cypress run --spec cypress/e2e/feature/checkout.feature --config-file configs/cypress.config.js",
"test:cart:run": "cypress run --spec cypress/e2e/feature/cart.feature --config-file configs/cypress.config.js"
},
Expand All @@ -17,5 +17,8 @@
"@bahmutov/cypress-esbuild-preprocessor": "^2.2.1",
"cypress": "^13.13.1",
"multiple-cucumber-html-reporter": "^3.7.0"
},
"dependencies": {
"@faker-js/faker": "^8.4.1"
}
}

0 comments on commit 7a45676

Please sign in to comment.