Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests - Add new test 'FO > Menu and navigation > Check breadcrumb links' #34466

Merged
merged 3 commits into from
Nov 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import pages
import {homePage} from '@pages/FO/home';
import categoryPage from '@pages/FO/category';

// Import data
import Categories from '@data/demo/categories';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';

const baseContext: string = 'functional_FO_classic_menuAndNavigation_navigateInCategories_breadcrumb';

describe('FO - Menu and Navigation : Breadcrumb', async () => {
let browserContext: BrowserContext;
let page: Page;

// before and after functions
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});

after(async () => {
await helper.closeBrowserContext(browserContext);
});

it('should open the shop page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFO', baseContext);

await homePage.goToFo(page);

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage).to.eq(true);
});

it('should go to the category Clothes', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkClothesLink', baseContext);

await homePage.goToCategory(page, Categories.clothes.id);

const pageTitle = await categoryPage.getPageTitle(page);
expect(pageTitle).to.equal(Categories.clothes.name);
});

it('should check breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkBreadcrumb1', baseContext);

const breadcrumbText = await categoryPage.getBreadcrumbText(page);
expect(breadcrumbText).to.eq('Home Clothes');
});

it('should go to the subcategory Men', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkMenLink', baseContext);

await homePage.goToSubCategory(page, Categories.clothes.id, Categories.men.id);

const pageTitle = await homePage.getPageTitle(page);
expect(pageTitle).to.equal(Categories.men.name);
});

it('should check breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkBreadcrumb2', baseContext);

const breadcrumbText = await categoryPage.getBreadcrumbText(page);
expect(breadcrumbText).to.eq('Home Clothes Men');
});

it('should click on clothes link from the breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnClothesLink', baseContext);

await categoryPage.clickOnBreadCrumbLink(page, 'clothes');

const pageTitle = await categoryPage.getPageTitle(page);
expect(pageTitle).to.equal(Categories.clothes.name);
});

it('should check breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkBreadcrumb3', baseContext);

const breadcrumbText = await categoryPage.getBreadcrumbText(page);
expect(breadcrumbText).to.eq('Home Clothes');
});

it('should click on Home link from the breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnHomeLink', baseContext);

await categoryPage.clickOnBreadCrumbLink(page, 'en');

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage).to.eq(true);
});

it('should go to the subcategory stationery', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkStationeryLink', baseContext);

await homePage.goToSubCategory(page, Categories.accessories.id, Categories.stationery.id);

const pageTitle = await categoryPage.getPageTitle(page);
expect(pageTitle).to.equal(Categories.stationery.name);
});

it('should check breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkBreadcrumb4', baseContext);

const breadcrumbText = await categoryPage.getBreadcrumbText(page);
expect(breadcrumbText).to.eq('Home Accessories Stationery');
});

it('should click on accessories link from the breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnAccessoriesLink', baseContext);

await categoryPage.clickOnBreadCrumbLink(page, 'accessories');

const pageTitle = await categoryPage.getPageTitle(page);
expect(pageTitle).to.equal(Categories.accessories.name);
});

it('should check breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkBreadcrumb5', baseContext);

const breadcrumbText = await categoryPage.getBreadcrumbText(page);
expect(breadcrumbText).to.eq('Home Accessories');
});

it('should click on Home link from the breadcrumb', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnHomeLink2', baseContext);

await categoryPage.clickOnBreadCrumbLink(page, 'en');

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage).to.eq(true);
});
});
25 changes: 20 additions & 5 deletions tests/UI/pages/FO/FObasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default class FOBasePage extends CommonPage {

private readonly desktopLogoLink: string;

private readonly breadCrumb: string;

private readonly breadCrumbLink: (link: string) => string;

private readonly cartProductsCount: string;
Expand Down Expand Up @@ -111,7 +113,7 @@ export default class FOBasePage extends CommonPage {

private readonly wrapperDiv: (position: number) => string;

private readonly wrapperTitle: (position:number) => string;
private readonly wrapperTitle: (position: number) => string;

private readonly wrapperSubmenu: (position: number) => string;

Expand Down Expand Up @@ -153,7 +155,8 @@ export default class FOBasePage extends CommonPage {
this.content = '#content';
this.desktopLogo = '#_desktop_logo';
this.desktopLogoLink = `${this.desktopLogo} a`;
this.breadCrumbLink = (link) => `#wrapper nav.breadcrumb a[href*=${link}]`;
this.breadCrumb = '#wrapper div nav.breadcrumb';
this.breadCrumbLink = (link) => `${this.breadCrumb} a[href*=${link}]`;
this.cartProductsCount = '#_desktop_cart .cart-products-count';
this.cartLink = '#_desktop_cart a';
this.userInfoLink = '#_desktop_user_info';
Expand Down Expand Up @@ -270,14 +273,26 @@ export default class FOBasePage extends CommonPage {
return this.clickAndWaitForLoadState(page, selector);
}

/**
* Get breadcrumb text
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async getBreadcrumbText(page: Page): Promise<string> {
return this.getTextContent(page, this.breadCrumb);
}

/**
* Click on bread crumb link
* @param page {Page} Browser tab
* @param link {string} Link to click on
* @returns {Promise<void>}
*/
async clickOnBreadCrumbLink(page: Page, link: string): Promise<void> {
await this.clickAndWaitForURL(page, this.breadCrumbLink(link));
const currentUrl: string = page.url();

await page.locator(this.breadCrumbLink(link)).first().click();
await page.waitForURL((url: URL): boolean => url.toString() !== currentUrl, {waitUntil: 'networkidle'});
}

/**
Expand Down Expand Up @@ -561,7 +576,7 @@ export default class FOBasePage extends CommonPage {
* @param productName {string} Product name to search
* @returns {Promise<boolean>}
*/
async hasAutocompleteSearchResult(page: Page, productName:string): Promise<boolean> {
async hasAutocompleteSearchResult(page: Page, productName: string): Promise<boolean> {
await this.setValue(page, this.searchInput, productName);
return this.isAutocompleteSearchResultVisible(page);
}
Expand Down Expand Up @@ -596,7 +611,7 @@ export default class FOBasePage extends CommonPage {
* @param productName {string} Product name to search
* @returns {Promise<void>}
*/
async searchProduct(page: Page, productName: string): Promise<void > {
async searchProduct(page: Page, productName: string): Promise<void> {
const currentUrl: string = page.url();

await this.setValue(page, this.theme === 'hummingbird' ? this.hSearchInput : this.searchInput, productName);
Expand Down