Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 1x 1x 1x 1x 1x 25x 25x 25x 1x 1x 1x 1x 1x 26x 26x 26x 26x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // @ts-check
const { expect } = require('@playwright/test');
const { BasePage } = require('./BasePage');
const { HeaderComponent } = require('./components/HeaderComponent');
const { environment } = require('../config/environment');
/**
* HomePage represents the landing page of automationexercise.com.
*/
class HomePage extends BasePage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
super(page);
this.header = new HeaderComponent(page);
// Primary Home Elements
this.sliderCarousel = page.locator('#slider-carousel');
this.sliderBannerText = page.locator('#slider-carousel .item.active').getByText(
'Full-Fledged practice website for Automation Engineers',
{ exact: false },
);
this.featuresItems = page.locator('.features_items');
this.scrollUpButton = page.locator('#scrollUp');
// Sidebar Categories & Brands
this.leftSidebar = page.locator('.left-sidebar');
this.categorySection = page.locator('.left-sidebar').getByText('Category', { exact: true });
this.brandLinks = page.locator('.brands-name a');
// Recommended Items
this.recommendedItemsSection = page.locator('.recommended_items');
this.recommendedHeading = page.locator('.recommended_items h2.title');
this.recommendedActiveAddToCart = page.locator('.recommended_items .item.active .add-to-cart').first();
// Footer & Subscription
this.footer = page.locator('#footer');
this.subscriptionHeading = page.locator('#footer').getByRole('heading', { name: 'Subscription', exact: false });
this.subscriptionInput = page.locator('#susbscribe_email');
this.subscribeButton = page.locator('#subscribe');
this.subscriptionSuccessAlert = page.locator('#success-subscribe');
}
/**
* Navigates directly to the Home page.
*/
async navigate() {
await this.goto(environment.routes.home);
await this.verifyHomePageVisible();
}
/**
* Verifies that the home page is visible successfully.
*/
async verifyHomePageVisible() {
await expect(this.page).toHaveURL(new RegExp(`${environment.baseURL}/?$`));
await this.header.verifyLogoVisible();
await expect(this.sliderCarousel.or(this.featuresItems).first()).toBeVisible();
}
/**
* Clicks 'Test Cases' link in the header.
*/
async clickTestCases() {
await this.header.clickTestCases();
}
/**
* Scrolls to the bottom footer.
*/
async scrollToFooter() {
await this.footer.scrollIntoViewIfNeeded();
await expect(this.subscriptionHeading).toBeVisible();
}
/**
* Enters email and submits subscription form.
* @param {string} email
*/
async subscribe(email) {
await this.subscriptionInput.fill(email);
await this.subscribeButton.click();
await expect(this.subscriptionSuccessAlert).toContainText('You have been successfully subscribed!');
}
/**
* Scrolls up using the bottom-right arrow button.
*/
async scrollUpWithArrow() {
await this.scrollUpButton.click();
await expect.poll(() => this.page.evaluate(() => window.scrollY)).toBeLessThan(150);
}
/**
* Scrolls up manually to the top.
*/
async scrollUpManually() {
await this.page.evaluate(() => window.scrollTo({ top: 0, behavior: 'instant' }));
await expect.poll(() => this.page.evaluate(() => window.scrollY)).toBeLessThan(150);
}
/**
* Verifies the top banner header text is visible.
*/
async verifyTopBannerVisible() {
await expect(
this.page.locator('#slider-carousel').getByText('Full-Fledged practice website for Automation Engineers', {
exact: false,
}).first(),
).toBeVisible();
}
/**
* Selects category and subcategory from left sidebar.
* @param {'Women' | 'Men' | 'Kids'} parentCategory
* @param {string} subCategory
*/
async selectCategory(parentCategory, subCategory) {
await expect(this.categorySection).toBeVisible();
const parentToggle = this.page.locator(`#accordian a[href="#${parentCategory}"]`);
const categoryCollapse = this.page.locator(`#${parentCategory}`);
await parentToggle.scrollIntoViewIfNeeded();
// Poll click until category accordion expands
await expect.poll(async () => {
const isOpen = await categoryCollapse.evaluate((el) => el.classList.contains('in')).catch(() => false);
if (isOpen) return true;
await parentToggle.click();
return false;
}, { timeout: 15000, intervals: [500, 1000, 1500] }).toBeTruthy();
const subLink = this.page.locator(`#${parentCategory} a`, { hasText: subCategory });
await subLink.waitFor({ state: 'visible' });
await subLink.click();
}
/**
* Clicks brand link from sidebar.
* @param {number | string} brand
*/
async selectBrand(brand) {
if (typeof brand === 'number') {
await this.brandLinks.nth(brand).click();
} else {
await this.page.locator('.brands-name a', { hasText: brand }).click();
}
}
/**
* Scrolls down to recommended items.
*/
async scrollToRecommendedItems() {
await this.recommendedItemsSection.scrollIntoViewIfNeeded();
await expect(this.recommendedHeading).toBeVisible();
}
/**
* Adds an item from recommended items to cart.
* @returns {Promise<string | null>} Added product ID
*/
async addRecommendedProductToCart() {
await this.scrollToRecommendedItems();
const productId = await this.recommendedActiveAddToCart.getAttribute('data-product-id');
await this.recommendedActiveAddToCart.click();
await expect(this.page.locator('.modal-content')).toBeVisible();
return productId;
}
}
module.exports = { HomePage };
|