Skip to content

product tests #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion tests/cart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,50 @@ test('Check header elements exist', async ({ page }) => {
// Check if the shopping cart button exists
const cartButton = header.locator('.cart-btn-container paper-icon-button[icon="shopping-cart"]');
await expect(cartButton).toBeVisible();
});
});


test('Check if product details exist on the page', async ({ page }) => {
await page.goto('http://localhost:8081/detail/mens_outerwear/Tri-blend+Full-Zip+Hoodie');

// Check if the <h1> title with the product name exists
const productName = page.locator('h1:has-text("Tri-blend Full-Zip Hoodie")');
await expect(productName).toBeVisible();

// Check if the price element exists and has the correct value
const price = page.locator('.price');
await expect(price).toHaveText('$52.20');

// Check if the size select element exists
const sizeSelect = page.locator('#sizeSelect');
await expect(sizeSelect).toBeVisible();

// Check if the quantity select element exists
const quantitySelect = page.locator('#quantitySelect');
await expect(quantitySelect).toBeVisible();

// Check if the description exists and contains the correct text
const description = page.locator('#desc');
await expect(description).toHaveText(/Comfy cool/); // Partial match for the description text

// Check if the "Add to Cart" button exists
const addToCartButton = page.locator('button[aria-label="Add this item to cart"]');
await expect(addToCartButton).toBeVisible();
});




test('Check existence of cart elements', async ({ page }) => {

await page.goto('http://localhost:8081/cart');

const linkLocator = page.locator('a[href="/detail/mens_outerwear/Tri-blend+Full-Zip+Hoodie"][title="Tri-blend Full-Zip Hoodie"]');

// Verify that the anchor tag is visible
await expect(linkLocator).toBeVisible();

// Verify that the <shop-image> child element exists within the <a> tag
const shopImageLocator = linkLocator.locator('shop-image');
await expect(shopImageLocator).toBeVisible();
});
37 changes: 37 additions & 0 deletions tests/product.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,40 @@ test('Check product detail elements exist', async ({ page }) => {
const addToCartButton = page.locator('shop-button button[aria-label="Add this item to cart"]');
await expect(addToCartButton).toBeVisible();
});


test('check first three shop list items exist', async ({ page }) => {
// Navigate to the page containing the list
await page.goto('http://localhost:8081/list/ladies_tshirts');

const firstItem = page.locator('ul.grid > li:nth-of-type(1) > a');
const secondItem = page.locator('ul.grid > li:nth-of-type(2) > a');
const thirdItem = page.locator('ul.grid > li:nth-of-type(3) > a');

// Define locators for titles and prices within each item
const firstItemTitle = firstItem.locator('shop-list-item >> .title');
const firstItemPrice = firstItem.locator('shop-list-item >> .price');

const secondItemTitle = secondItem.locator('shop-list-item >> .title');
const secondItemPrice = secondItem.locator('shop-list-item >> .price');

const thirdItemTitle = thirdItem.locator('shop-list-item >> .title');
const thirdItemPrice = thirdItem.locator('shop-list-item >> .price');

// Check that each of the first three items is visible
await expect(firstItem).toBeVisible();
await expect(secondItem).toBeVisible();
await expect(thirdItem).toBeVisible();

// Verify the title and price for the first item
await expect(firstItemTitle).toHaveText('Ladies Chrome T-Shirt');
await expect(firstItemPrice).toHaveText('$13.30');

// Verify the title and price for the second item
await expect(secondItemTitle).toHaveText('Ladies Google New York T-Shirt');
await expect(secondItemPrice).toHaveText('$18.35');

// Verify the title and price for the third item
await expect(thirdItemTitle).toHaveText('Ladies Gmail T-Shirt');
await expect(thirdItemPrice).toHaveText('$16.40');
});