-
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 cart functionality test scenarios
Signed-off-by: Ganesh Hubale <ganeshhubale03@gmail.com>
- Loading branch information
1 parent
e8988ba
commit c13cd80
Showing
5 changed files
with
158 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const items = require("../../fixtures/items.json"); | ||
const cart = require("../../pages/cartPage"); | ||
|
||
describe("Cart Functionality", () => { | ||
|
||
beforeEach("login", () => { | ||
cy.login() | ||
}); | ||
|
||
afterEach("CleanUp", () => { | ||
cy.clearCookies(); | ||
cy.clearLocalStorage(); | ||
}); | ||
|
||
it("Add a Single Item to the Cart", () => { | ||
// Choose item and Click on it. For example - Item name - Sauce Labs Backpack | ||
const itemName = items.sauceLabsBackpack.name; | ||
|
||
cart.addSingleItem(itemName); | ||
|
||
// Go to cart | ||
cart.goToCart(); | ||
|
||
// Confirm only one item in cart | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const totalItems = [...items].map((item) => item.textContent.trim()) | ||
|
||
expect(totalItems.length).to.equal(1); | ||
expect(totalItems[0]).to.equals(itemName) | ||
}); | ||
}); | ||
|
||
it("Add Multiple Items to the Cart", () => { | ||
// Add multiple items to cart | ||
const itemNames = Object.values(items).map(item => item.name); | ||
|
||
cart.addMultipleItems(itemNames); | ||
|
||
// Go to cart | ||
cart.goToCart(); | ||
|
||
// Confirm multiple items added in cart | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const totalItems = [...items].map((item) => item.textContent.trim()) | ||
|
||
expect(totalItems.length).to.equal(itemNames.length); | ||
}); | ||
}); | ||
|
||
it("Remove an Item from the Cart", () => { | ||
// Add multiple items to cart | ||
const itemNames = Object.values(items).map(item => item.name); | ||
|
||
cart.addMultipleItems(itemNames); | ||
|
||
// Go to cart | ||
cart.goToCart(); | ||
|
||
// Remove an item from cart and check count reduced | ||
cart.removeFromCart([itemNames[0]]); | ||
|
||
// Confirm total count reduced by one | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const totalItems = [...items].map((item) => item.textContent.trim()) | ||
|
||
expect(totalItems.length).to.equal(itemNames.length-1); | ||
}); | ||
}); | ||
|
||
it("Empty the Cart", () => { | ||
// Add multiple items to cart | ||
const itemNames = Object.values(items).map(item => item.name); | ||
|
||
cart.addMultipleItems(itemNames); | ||
|
||
// Go to cart | ||
cart.goToCart(); | ||
|
||
// Remove an item from cart and check count reduced | ||
cart.removeFromCart(itemNames); | ||
|
||
// Confirm the cart is empty | ||
cy.get("div[data-test=inventory-item-name]").should("not.exist"); | ||
}); | ||
|
||
it("Verify Cart Persistence", () => { | ||
// Add multiple items to cart | ||
const itemNames = Object.values(items).map(item => item.name); | ||
|
||
cart.addMultipleItems(itemNames); | ||
|
||
// Reload the inventory | ||
cy.reload(); | ||
|
||
// Go to cart | ||
cart.goToCart(); | ||
|
||
// Confirm total count of items is equal to total items in cart | ||
cy.get("div[data-test=inventory-item-name]").then((items) => { | ||
const totalItems = [...items].map((item) => item.textContent.trim()) | ||
|
||
expect(totalItems.length).to.equal(itemNames.length); | ||
}); | ||
}); | ||
}); |
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,11 @@ | ||
{ | ||
"sauceLabsBackpack": { | ||
"name": "Sauce Labs Backpack" | ||
}, | ||
"sauceLabsBikelight": { | ||
"name": "Sauce Labs Bike Light" | ||
}, | ||
"testallthings": { | ||
"name": "Test.allTheThings() T-Shirt (Red)" | ||
} | ||
} |
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,36 @@ | ||
class Cart{ | ||
|
||
elements = { | ||
itemName: () => cy.get("div[data-test=inventory-item-name]"), | ||
addToCart: () => cy.get("button[id=add-to-cart]"), | ||
cartBtn: () => cy.get("div[id=shopping_cart_container]") | ||
} | ||
|
||
addSingleItem(name){ | ||
// Click on item | ||
this.elements.itemName().contains(name).click(); | ||
|
||
// Add to card | ||
this.elements.addToCart().click() | ||
}; | ||
|
||
addMultipleItems(itemNames){ | ||
itemNames.forEach((itemName) => { | ||
const name = itemName.trim().toLowerCase().replace(/\s+/g, '-'); | ||
cy.get(`button[id='add-to-cart-${name}']`).click(); | ||
}); | ||
}; | ||
|
||
removeFromCart(itemNames){ | ||
itemNames.forEach((itemName) => { | ||
const name = itemName.trim().toLowerCase().replace(/\s+/g, '-'); | ||
cy.get(`button[id='remove-${name}']`).click(); | ||
}); | ||
}; | ||
|
||
goToCart(){ | ||
// Click on cart button | ||
this.elements.cartBtn().click(); | ||
} | ||
}; | ||
module.exports = new Cart(); |
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ class Inventory{ | |
} | ||
|
||
} | ||
module.exports = new Inventory(); | ||
module.exports = new Inventory(); |