-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated product items sorting scenarios
- Added login command - Added page objects - Started using POM for automation framework Signed-off-by: Ganesh Hubale <ganeshhubale03@gmail.com>
- Loading branch information
1 parent
b1485a5
commit 406f94a
Showing
5 changed files
with
217 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const inventoryPage = require("../../pages/inventoryPage") | ||
|
||
describe("Sort product items", () => { | ||
beforeEach("login", () => { | ||
cy.login() | ||
}) | ||
|
||
afterEach(() => { | ||
cy.clearCookies(); | ||
cy.clearLocalStorage(); | ||
}); | ||
|
||
it("Verify sort items by Name: A-Z", () => { | ||
// Sort by name: A to Z | ||
inventoryPage.sort_by_name("az") | ||
|
||
// Confirm item list is not empty | ||
cy.get("div[data-test=inventory-item-name]").should("have.length.greaterThan", 0); | ||
|
||
// List the product names | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const itemNames = [...items].map((item) => item.textContent.trim()) | ||
|
||
// Verify names are sorted in ascending order | ||
const sortedNames = [...itemNames].sort(); | ||
expect(itemNames).to.deep.equal(sortedNames); | ||
}); | ||
}) | ||
|
||
it("Verify sort items by Name: Z-A", () => { | ||
inventoryPage.sort_by_name("za") | ||
|
||
// Confirm item list is not empty | ||
cy.get("div[data-test=inventory-item-name]").should("have.length.greaterThan", 0); | ||
|
||
// List the product names | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const itemNames = [...items].map((item) => item.textContent.trim()) | ||
|
||
// Verify names are sorted in descending order | ||
const sortedNames = [...itemNames].sort((a,b) => b.localeCompare(a)); | ||
expect(itemNames).to.deep.equal(sortedNames); | ||
}); | ||
}) | ||
|
||
it("Verify sort items by price: low to high", () => { | ||
inventoryPage.sort_by_price("lohi") | ||
|
||
// Confirm item prices list not empty | ||
cy.get("div[data-test=inventory-item-price]").should("have.length.greaterThan", 0); | ||
|
||
// List the item prices | ||
cy.get("div[data-test=inventory-item-price]").then((prices) => { | ||
const itemPrices = [...prices].map((price) => parseFloat(price.textContent.replace("$", "").trim())); | ||
|
||
// Verify item prices sorted in ascending order | ||
const sortedPrices = [...itemPrices].sort((a, b) => a - b);; | ||
expect(itemPrices).to.deep.equal(sortedPrices); | ||
}); | ||
}) | ||
|
||
it("Verify sort items by price: high to low", () => { | ||
inventoryPage.sort_by_price("hilo") | ||
|
||
// Confirm item prices list not empty | ||
cy.get("div[data-test=inventory-item-price]").should("have.length.greaterThan", 0); | ||
|
||
// List the item prices | ||
cy.get("div[data-test=inventory-item-price]").then((prices) => { | ||
const itemPrices = [...prices].map((price) => parseFloat(price.textContent.replace("$", "").trim())); | ||
|
||
// Verify item prices sorted in descending order | ||
const sortedPrices = [...itemPrices].sort((a, b) => b - a); | ||
expect(itemPrices).to.deep.equal(sortedPrices); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Inventory{ | ||
|
||
elements = { | ||
|
||
sortOptions: () => cy.get("select[data-test=product-sort-container]") | ||
} | ||
|
||
sort_by_name(type){ | ||
this.elements.sortOptions().select(type); | ||
} | ||
|
||
sort_by_price(type){ | ||
this.elements.sortOptions().select(type); | ||
} | ||
|
||
} | ||
module.exports = new Inventory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters