Skip to content

Commit

Permalink
Merge pull request PrestaShop#34105 from nesrineabdmouleh/functionalS…
Browse files Browse the repository at this point in the history
…eoTab

Functional tests - Add new test 'BO > Product V2 > Check seo tab'
  • Loading branch information
boubkerbribri authored Oct 6, 2023
2 parents c14d081 + 660d1f6 commit 26d4275
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 2 deletions.
273 changes: 273 additions & 0 deletions tests/UI/campaigns/productV2/functional/18_seoTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import common tests
import loginCommon from '@commonTests/BO/loginBO';

// Import BO pages
import dashboardPage from '@pages/BO/dashboard';
import createProductPage from '@pages/BO/catalog/productsV2/add';
import seoTab from '@pages/BO/catalog/productsV2/add/seoTab';
import productsPage from '@pages/BO/catalog/productsV2';

// Import FO pages
import foProductPage from '@pages/FO/product';
import {searchResultsPage} from '@pages/FO/searchResults';
import categoryPageFO from '@pages/FO/category';

// Import data
import Products from '@data/demo/products';
import ProductData from '@data/faker/product';

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

const baseContext: string = 'productV2_functional_seoTab';

describe('BO - Catalog - Products : Seo tab', async () => {
let browserContext: BrowserContext;
let page: Page;

// Data to create standard product
const newProductData: ProductData = new ProductData({
name: 'Oriental fresh chair',
type: 'standard',
quantity: 100,
minimumQuantity: 1,
status: true,
});
// Data to edit standard product
const editProductData: ProductData = new ProductData({
metaTitle: 'lorem ipsum',
metaDescription: 'lorem ipsum',
friendlyUrl: 'lorem ipsum',
});

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

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

// 1 - Create product
describe('Create product', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Catalog > Products\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToProductsPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.catalogParentLink,
dashboardPage.productsLink,
);
await productsPage.closeSfToolBar(page);

const pageTitle = await productsPage.getPageTitle(page);
await expect(pageTitle).to.contains(productsPage.pageTitle);
});

it('should click on \'New product\' button and check new product modal', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnNewProductButton', baseContext);

const isModalVisible = await productsPage.clickOnNewProductButton(page);
await expect(isModalVisible).to.be.true;
});

it('should choose \'Standard product\' and go to new product page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseStandardProduct', baseContext);

await productsPage.selectProductType(page, newProductData.type);
await productsPage.clickOnAddNewProduct(page);

const pageTitle = await createProductPage.getPageTitle(page);
await expect(pageTitle).to.contains(createProductPage.pageTitle);
});

it('should create standard product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'createStandardProduct', baseContext);

const createProductMessage = await createProductPage.setProduct(page, newProductData);
await expect(createProductMessage).to.equal(createProductPage.successfulUpdateMessage);
});
});

// 2 - Check all options in SEO tab
describe('Check all options in SEO tab', async () => {
it('should fill all fields on SEO Tab and check the error message', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkErrorMessage', baseContext);

await createProductPage.goToTab(page, 'seo');
await seoTab.setMetaTitle(page, editProductData.metaTitle!);
await seoTab.setMetaDescription(page, editProductData.metaDescription!);
await seoTab.setFriendlyUrl(page, editProductData.friendlyUrl!);
await createProductPage.clickOnSaveProductButton(page);

const errorMessage = await seoTab.getErrorMessageOfFriendlyUrl(page);
expect(errorMessage).to.eq('"lorem ipsum" is invalid - Language: English (English)');
});

it('should edit friendly URL', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'editFriendlyURL', baseContext);

await seoTab.setFriendlyUrl(page, 'lorem-ipsum');

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it('should reset URL', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetURL', baseContext);

await seoTab.clickOnGenerateUrlFromNameButton(page);

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);

const friendlyUrl = await seoTab.getValue(page, 'link_rewrite', '1');
expect(friendlyUrl).to.eq('oriental-fresh-chair');
});

it('should switch the product status to off', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'switchProductStatusToOff', baseContext);

await createProductPage.setProductStatus(page, false);

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it(`'should choose redirectionPage 'Products : ${Products.demo_1.name}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseRedirectionPage2', baseContext);

await seoTab.selectRedirectionPage(page, 'Permanent redirection to a product (301)');
await seoTab.searchOptionTarget(page, Products.demo_1.name);

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it(`should preview product and check '${Products.demo_1.name}' page`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'previewProduct2', baseContext);

// Click on preview button
page = await createProductPage.previewProduct(page);
await foProductPage.changeLanguage(page, 'en');

const pageTitle = await foProductPage.getPageTitle(page);
expect(pageTitle).to.contains(Products.demo_1.name);
});

it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO2', baseContext);

// Go back to BO
page = await foProductPage.closePage(browserContext, page, 0);

const pageTitle = await createProductPage.getPageTitle(page);
expect(pageTitle).to.contains(createProductPage.pageTitle);
});

it('should choose redirectionPage \'Category : Home accessories\'', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseRedirectionPage', baseContext);

await seoTab.selectRedirectionPage(page, 'Permanent redirection to a category (301)');
await seoTab.searchOptionTarget(page, 'Home accessories');

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it('should preview product and check \'Home Accessories\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'previewProduct', baseContext);

// Click on preview button
page = await createProductPage.previewProduct(page);
const currentUrl = await foProductPage.getCurrentURL(page);
const newUrl = currentUrl.split('token');
await foProductPage.goTo(page, newUrl[0]);
await foProductPage.changeLanguage(page, 'en');

const pageTitle = await foProductPage.getPageTitle(page);
expect(pageTitle).to.contains('Home Accessories');
});

it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO', baseContext);

// Go back to BO
page = await foProductPage.closePage(browserContext, page, 0);

const pageTitle = await createProductPage.getPageTitle(page);
expect(pageTitle).to.contains(createProductPage.pageTitle);
});

it('should add tag', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'addTag', baseContext);

await seoTab.setTag(page, 'welcome');

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it('should switch the product status to on', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'switchProductStatusToOn', baseContext);

await createProductPage.setProductStatus(page, true);

const message = await createProductPage.saveProduct(page);
expect(message).to.eq(createProductPage.successfulUpdateMessage);
});

it('should preview product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'previewProduct3', baseContext);

// Click on preview button
page = await createProductPage.previewProduct(page);
await foProductPage.changeLanguage(page, 'en');

const pageTitle = await foProductPage.getPageTitle(page);
expect(pageTitle).to.contains(Products.demo_1.name);
});

it('should search the new tag \'welcome\' from the search bar', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'searchTag', baseContext);

await foProductPage.searchProduct(page, 'welcome');

const pageTitle = await searchResultsPage.getPageTitle(page);
await expect(pageTitle).to.equal(searchResultsPage.pageTitle);

const numberOfProducts = await categoryPageFO.getNumberOfProducts(page);
expect(numberOfProducts).to.eql(1);
});

it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goBackToBO3', baseContext);

// Go back to BO
page = await foProductPage.closePage(browserContext, page, 0);

const pageTitle = await createProductPage.getPageTitle(page);
expect(pageTitle).to.contains(createProductPage.pageTitle);
});
});

// 3 - Delete product
describe('POST-TEST: Delete product', async () => {
it('should delete product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteProduct', baseContext);

const createProductMessage = await createProductPage.deleteProduct(page);
expect(createProductMessage).to.equal(productsPage.successfulDeleteMessage);
});
});
});
15 changes: 15 additions & 0 deletions tests/UI/data/faker/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export default class ProductData {

public numberOfDays: number | null;

public metaTitle: string | null;

public metaDescription: string | null;

public friendlyUrl: string | null;

public combinations: ProductCombination[];

public packageDimensionWidth: number;
Expand Down Expand Up @@ -323,6 +329,15 @@ export default class ProductData {
/** @type {number} Number of days limit */
this.numberOfDays = productToCreate.numberOfDays || null;

/** @type {string} Meta title */
this.metaTitle = productToCreate.metaTitle || null;

/** @type {string} Meta description */
this.metaDescription = productToCreate.metaDescription || null;

/** @type {string} Friendly URL */
this.friendlyUrl = productToCreate.friendlyUrl || null;

/** @type {number} Weight of the package */
this.packageDimensionWeight = productToCreate.packageDimensionWeight || faker.number.int({min: 1, max: 20});

Expand Down
3 changes: 3 additions & 0 deletions tests/UI/data/types/product.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type ProductCreator = {
packageDimensionWidth?: number
deliveryTime?: string
combinations?: ProductCombination[]
metaTitle?: string | null
metaDescription?: string | null
friendlyUrl?: string | null
};

type ProductCombination = {
Expand Down
11 changes: 10 additions & 1 deletion tests/UI/pages/BO/catalog/productsV2/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CreateProduct extends BOBasePage {
// Modal : Switch Product Type
this.modalSwitchType = '#switch-product-type-modal';
this.modalSwitchTypeBtnChoice = (productType: string) => `${this.modalSwitchType} button.product-type-choice`
+ `[data-value="${productType}"]`;
+ `[data-value="${productType}"]`;
this.modalSwitchTypeBtnSubmit = `${this.modalSwitchType} .modal-footer button.btn-confirm-submit`;
this.modalConfirmType = '#modal-confirm-product-type';
this.modalConfirmTypeBtnSubmit = `${this.modalConfirmType} .modal-footer button.btn-confirm-submit`;
Expand Down Expand Up @@ -341,6 +341,15 @@ class CreateProduct extends BOBasePage {
await this.setValue(page, this.productNameInput(locale), name);
}

/**
* Click on save product button
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async clickOnSaveProductButton(page: Page): Promise<void> {
await this.clickAndWaitForLoadState(page, this.saveProductButton);
}

/**
* Save product
* @param page {Page} Browser tab
Expand Down
Loading

0 comments on commit 26d4275

Please sign in to comment.