diff --git a/.gitignore b/.gitignore index 6bab96e..84059af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ node_modules/ reports/ cucumber-report.html jsonlogs/ +screenshots/ +videos/ +downloads/ \ No newline at end of file diff --git a/cypress/e2e/feature/login.feature b/cypress/e2e/feature/login.feature index 9cc9cf6..0539bd4 100644 --- a/cypress/e2e/feature/login.feature +++ b/cypress/e2e/feature/login.feature @@ -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 \ No newline at end of file diff --git a/cypress/e2e/step_definitions/cart.js b/cypress/e2e/step_definitions/cart.js index 16aeadd..95fef31 100644 --- a/cypress/e2e/step_definitions/cart.js +++ b/cypress/e2e/step_definitions/cart.js @@ -1,6 +1,7 @@ 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(); @@ -8,7 +9,7 @@ Given("the user adds a product to the cart", () => { 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) => { diff --git a/cypress/e2e/step_definitions/checkout.js b/cypress/e2e/step_definitions/checkout.js index f5e0fde..69d5bca 100644 --- a/cypress/e2e/step_definitions/checkout.js +++ b/cypress/e2e/step_definitions/checkout.js @@ -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("/"); @@ -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( diff --git a/cypress/e2e/step_definitions/inventory.js b/cypress/e2e/step_definitions/inventory.js index 791940b..2dd2fa9 100644 --- a/cypress/e2e/step_definitions/inventory.js +++ b/cypress/e2e/step_definitions/inventory.js @@ -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", () => { @@ -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; } }); diff --git a/cypress/e2e/step_definitions/login.js b/cypress/e2e/step_definitions/login.js index aa0d5f3..93bf350 100644 --- a/cypress/e2e/step_definitions/login.js +++ b/cypress/e2e/step_definitions/login.js @@ -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); } ); diff --git a/cypress/fixtures/credentials.json b/cypress/fixtures/credentials.json new file mode 100644 index 0000000..a886414 --- /dev/null +++ b/cypress/fixtures/credentials.json @@ -0,0 +1,5 @@ +{ + "username": "standard_user", + "password": "secret_sauce", + "locked_user": "locked_out_user" +} \ No newline at end of file diff --git a/cypress/fixtures/endpoints.json b/cypress/fixtures/endpoints.json new file mode 100644 index 0000000..f45d7a2 --- /dev/null +++ b/cypress/fixtures/endpoints.json @@ -0,0 +1,5 @@ +{ + "inventory": "/inventory.html", + "checkout_step_two": "/checkout-step-two.html", + "cart" : "/cart.html" +} diff --git a/package-lock.json b/package-lock.json index 260dd78..e5d92e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,9 @@ "requires": true, "packages": { "": { + "dependencies": { + "@faker-js/faker": "^8.4.1" + }, "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "^20.1.0", "@bahmutov/cypress-esbuild-preprocessor": "^2.2.1", @@ -1450,6 +1453,21 @@ "node": ">=12" } }, + "node_modules/@faker-js/faker": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz", + "integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/fakerjs" + } + ], + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0", + "npm": ">=6.14.13" + } + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", diff --git a/package.json b/package.json index 30351c9..4d49569 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } }