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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests - Refacto 'BO > International > Translations' tests #34502

Merged
merged 4 commits into from Nov 10, 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

Large diffs are not rendered by default.

Expand Up @@ -55,8 +55,15 @@ describe('BO - International - Translation : Add update a language', async () =>
expect(pageTitle).to.contains(translationsPage.pageTitle);
});

it(`should choose the '${Languages.deutsch.name}' language to add or update`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseLanguage', baseContext);
it(`should select from update language the '${Languages.english.name}' language`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseLanguage1', baseContext);

const textResult = await translationsPage.addUpdateLanguage(page, Languages.english.name);
expect(textResult).to.equal(translationsPage.successAlertMessage);
});

it(`should select from add language the '${Languages.deutsch.name}' language`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'chooseLanguage2', baseContext);

const textResult = await translationsPage.addUpdateLanguage(page, Languages.deutsch.name);
expect(textResult).to.equal(translationsPage.successAlertMessage);
Expand All @@ -82,56 +89,66 @@ describe('BO - International - Translation : Add update a language', async () =>
expect(pageTitle).to.contains(translationsPage.pageTitle);
});

it('should go to localization page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToLocalizationPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.internationalParentLink,
dashboardPage.localizationLink,
);
it(`should check that the language '${Languages.deutsch.name}' is visible in update a language list`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkLanguage', baseContext);

const pageTitle = await localizationPage.getPageTitle(page);
expect(pageTitle).to.contains(localizationPage.pageTitle);
const languagesInUpdateSection = await translationsPage.getLanguagesFromUpdateResult(page);
expect(languagesInUpdateSection).to.contains(Languages.deutsch.name);
});

it('should go to languages page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToLanguagesPage', baseContext);
// Post-condition : Delete language
describe('POST-TEST: Delete language', async () => {
it('should go to localization page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToLocalizationPage', baseContext);

await localizationPage.goToSubTabLanguages(page);
await dashboardPage.goToSubMenu(
page,
dashboardPage.internationalParentLink,
dashboardPage.localizationLink,
);

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

it('should reset all filters and get number of languages in BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilterFirst', baseContext);
it('should go to languages page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToLanguagesPage', baseContext);

numberOfLanguages = await languagesPage.resetAndGetNumberOfLines(page);
expect(numberOfLanguages).to.be.above(0);
});
await localizationPage.goToSubTabLanguages(page);

it(`should filter language by name '${Languages.deutsch.name}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterToUpdate', baseContext);
const pageTitle = await languagesPage.getPageTitle(page);
expect(pageTitle).to.contains(languagesPage.pageTitle);
});

// Filter
await languagesPage.filterTable(page, 'input', 'name', Languages.deutsch.name);
it('should reset all filters and get number of languages in BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilterFirst', baseContext);

const textColumn = await languagesPage.getTextColumnFromTable(page, 1, 'name');
expect(textColumn).to.contains(Languages.deutsch.name);
});
numberOfLanguages = await languagesPage.resetAndGetNumberOfLines(page);
expect(numberOfLanguages).to.be.above(0);
});

it('should delete language', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteLanguage', baseContext);
it(`should filter language by name '${Languages.deutsch.name}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterToUpdate', baseContext);

const textResult = await languagesPage.deleteLanguage(page, 1);
expect(textResult).to.to.contains(languagesPage.successfulDeleteMessage);
});
// Filter
await languagesPage.filterTable(page, 'input', 'name', Languages.deutsch.name);

const textColumn = await languagesPage.getTextColumnFromTable(page, 1, 'name');
expect(textColumn).to.contains(Languages.deutsch.name);
});

it('should delete language', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteLanguage', baseContext);

const textResult = await languagesPage.deleteLanguage(page, 1);
expect(textResult).to.to.contains(languagesPage.successfulDeleteMessage);
});

it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetAfterDelete', baseContext);
it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetAfterDelete', baseContext);

const numberOfLanguagesAfterReset = await languagesPage.resetAndGetNumberOfLines(page);
expect(numberOfLanguagesAfterReset).to.be.equal(numberOfLanguages - 1);
const numberOfLanguagesAfterReset = await languagesPage.resetAndGetNumberOfLines(page);
expect(numberOfLanguagesAfterReset).to.be.equal(numberOfLanguages - 1);
});
});
});
Expand Up @@ -12,6 +12,7 @@ import translationsPage from '@pages/BO/international/translations';

// Import data
import Languages from '@data/demo/languages';
import Modules from '@data/demo/modules';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';
Expand Down Expand Up @@ -53,35 +54,51 @@ describe('BO - International - Translation : Export languages', async () => {
{
args:
{
language: Languages.english,
types: ['Front office'],
language: Languages.english.name,
types: ['Back office'],
},
},
{
args:
{
language: Languages.french,
types: ['Front office'],
language: Languages.french.name,
types: ['Front office', 'Other'],
},
},
{
args:
{
language: Languages.english.name,
module: Modules.psFacetedSearch.name,
},
},
];

tests.forEach((test) => {
it(`Export language '${test.args.language.name}'`, async function () {
await testContext.addContextItem(
this,
'testIdentifier',
`exportLanguage${test.args.language.name}Theme`,
baseContext,
);

const filePath = await translationsPage.exportPrestashopTranslations(
page,
test.args.language.name,
test.args.types,
);
const doesFileExist = await files.doesFileExist(filePath);
expect(doesFileExist, `File '${filePath}' was not downloaded`).to.eq(true);
});
tests.forEach((test, index) => {
if (index !== 2) {
it(`should export language '${test.args.language}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `exportLanguage${index}`, baseContext);

const filePath = await translationsPage.exportPrestashopTranslations(page, test.args.language, test.args.types);

const doesFileExist = await files.doesFileExist(filePath);
expect(doesFileExist, `File '${filePath}' was not downloaded`).to.eq(true);
});

it('should uncheck options in PrestaShop translations section', async function () {
await testContext.addContextItem(this, 'testIdentifier', `uncheckOptions${index}`, baseContext);

await translationsPage.uncheckSelectedOptions(page, test.args.types);
});
} else {
it(`should export language '${test.args.language}' with installed module '${Modules.psFacetedSearch}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `exportLanguage${index}`, baseContext);

const filePath = await translationsPage.exportInstalledModuleTranslations(page, test.args.language, test.args.module!);

const doesFileExist = await files.doesFileExist(filePath);
expect(doesFileExist, `File '${filePath}' was not downloaded`).to.eq(true);
});
}
});
});
47 changes: 35 additions & 12 deletions tests/UI/pages/BO/catalog/discounts/add.ts
Expand Up @@ -114,6 +114,8 @@ class AddCartRule extends BOBasePage {

private readonly actionsTabLink: string;

private readonly titleOfExcludeDiscountedProduct: string;

private readonly freeShippingToggle: (toggle: string) => string;

private readonly applyDiscountRadioButton: (toggle: string) => string;
Expand Down Expand Up @@ -245,6 +247,7 @@ class AddCartRule extends BOBasePage {

// Actions tab
this.actionsTabLink = '#cart_rule_link_actions';
this.titleOfExcludeDiscountedProduct = '#apply_discount_to_product_special label span[data-original-title]';
this.freeShippingToggle = (toggle: string) => `${this.cartRuleForm} #free_shipping_${toggle}`;

// Discount percent selectors
Expand Down Expand Up @@ -280,6 +283,15 @@ class AddCartRule extends BOBasePage {
}

/* Methods */
/**
* Get generate button name
* @param page {Frame|Page} Browser tab
* @return {Promise<string>}
*/
async getGenerateButtonName(page: Page): Promise<string> {
return this.getTextContent(page, this.generateButton);
}

/**
* Fill form in information tab
* @param page {Frame|Page} Browser tab
Expand All @@ -288,15 +300,15 @@ class AddCartRule extends BOBasePage {
*/
async fillInformationForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to tab conditions
await page.click(this.infomationsTabLink);
await page.locator(this.infomationsTabLink).click();

// Fill information form
await this.setValue(page, this.nameInput(1), cartRuleData.name);
await this.setValue(page, this.descriptionTextArea, cartRuleData.description);

// Generate a discount code
if (cartRuleData.generateCode) {
await page.click(this.generateButton);
await page.locator(this.generateButton).click();
} else if (cartRuleData.code === null) {
await this.clearInput(page, this.codeInput);
} else {
Expand All @@ -322,14 +334,14 @@ class AddCartRule extends BOBasePage {
*/
async fillConditionsForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to tab conditions
await page.click(this.conditionsTabLink);
await page.locator(this.conditionsTabLink).click();

// Set Customer
// Customer will not be set if we want to use the cart rule for any customer
if (cartRuleData.customer) {
await this.setValue(page, this.singleCustomerInput, cartRuleData.customer.email);
await this.waitForVisibleSelector(page, `${this.singleCustomerResultBlock}:not([style*='display: none;'])`);
await page.click(this.singleCustomerResultItem);
await page.locator(this.singleCustomerResultItem).click();
}

// Fill date from if its changed
Expand All @@ -347,22 +359,22 @@ class AddCartRule extends BOBasePage {
// Set carrier discount
if (cartRuleData.carrierRestriction) {
await this.setChecked(page, this.carrierRestriction);
await page.click(this.carrierRestrictionPickUpInStore);
await page.click(this.carrierRestrictionRemoveButton);
await page.locator(this.carrierRestrictionPickUpInStore).click();
await page.locator(this.carrierRestrictionRemoveButton).click();
}

// Choose the country selection
if (cartRuleData.countrySelection) {
await this.setChecked(page, this.countryRestriction);
await this.selectByValue(page, this.countrySelection, cartRuleData.countryIDToRemove);
await page.click(this.countryGroupRemoveButton);
await page.locator(this.countryGroupRemoveButton).click();
}

// Set Customer Group Selection
if (cartRuleData.customerGroupSelection) {
await this.setChecked(page, this.customerGroupRestriction);
await page.click(this.customerGroupCustomer);
await page.click(this.customerGroupRemoveButton);
await page.locator(this.customerGroupCustomer).click();
await page.locator(this.customerGroupRemoveButton).click();
}

// Set product selection
Expand Down Expand Up @@ -409,7 +421,7 @@ class AddCartRule extends BOBasePage {
*/
async fillActionsForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to actions tab
await page.click(this.actionsTabLink);
await page.locator(this.actionsTabLink).click();

// Set free shipping toggle
await this.setChecked(page, this.freeShippingToggle(cartRuleData.freeShipping ? 'on' : 'off'));
Expand Down Expand Up @@ -477,6 +489,17 @@ class AddCartRule extends BOBasePage {
}
}

/**
* Get title of exclude discounted product
* @param page
*/
async getTitleOfExcludeDiscountedProduct(page: Page): Promise<string> {
// Go to actions tab
await page.locator(this.actionsTabLink).click();

return this.getAttributeContent(page, this.titleOfExcludeDiscountedProduct, 'data-original-title');
}

/**
* Create/edit cart rule
* @param page {Frame|Page} Browser tab
Expand Down Expand Up @@ -529,7 +552,7 @@ class AddCartRule extends BOBasePage {
*/
async getLimitSingleCustomer(page: Page): Promise<string | null> {
// Go to tab conditions
await page.click(this.conditionsTabLink);
await page.locator(this.conditionsTabLink).click();

return this.getAttributeContent(page, this.singleCustomerInput, 'value');
}
Expand All @@ -541,7 +564,7 @@ class AddCartRule extends BOBasePage {
*/
async getAmountValue(page: Page): Promise<string | null> {
// Go to actions tab
await page.click(this.actionsTabLink);
await page.locator(this.actionsTabLink).click();

return this.getAttributeContent(page, this.discountAmountInput, 'value');
}
Expand Down