Skip to content

Commit

Permalink
Merge pull request PrestaShop#36673 from jolelievre/debug-classic
Browse files Browse the repository at this point in the history
Screenshot on each steps in UI tests
  • Loading branch information
jolelievre authored Aug 29, 2024
2 parents 8aa72a0 + adc8314 commit c719b30
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .github/actions/ui-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inputs:
required: false
description: Database Server (mysql/mariadb)
default: 'mysql'
TAKE_SCREENSHOT_AFTER_EACH_STEP:
required: false
description: Take screenshot after each step
default: 'false'

runs:
using: 'composite'
Expand All @@ -42,7 +46,9 @@ runs:
- name: Use .env.ci
working-directory: ${{ inputs.TESTS_DIR }}
shell: bash
run: cp .env.ci .env
run: |
cp .env.ci .env
sed -i -e "s/TAKE_SCREENSHOT_AFTER_EACH_STEP.*/TAKE_SCREENSHOT_AFTER_EACH_STEP=${{ inputs.TAKE_SCREENSHOT_AFTER_EACH_STEP == 'false' && 'false' || 'true' }}/g" .env
- name: Install dependencies
working-directory: ${{ inputs.TESTS_DIR }}
Expand Down
1 change: 1 addition & 0 deletions tests/UI/.env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ INTERCEPT_ERRORS=false

# Screenshots
TAKE_SCREENSHOT_AFTER_FAIL=true
TAKE_SCREENSHOT_AFTER_EACH_STEP=false

# Mocha
GENERATE_FAILED_STEPS=false
Expand Down
1 change: 1 addition & 0 deletions tests/UI/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ INTERCEPT_ERRORS=false

# Screenshots
TAKE_SCREENSHOT_AFTER_FAIL=true
TAKE_SCREENSHOT_AFTER_EACH_STEP=false

# Mocha
GENERATE_FAILED_STEPS=false
Expand Down
4 changes: 2 additions & 2 deletions tests/UI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/UI/pages/FO/classic/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ class CheckoutPage extends FOBasePage {
* @returns {Promise<void>}
*/
async fillAddressForm(page: Page, address: FakerAddress): Promise<void> {
if (await this.elementVisible(page, this.addressStepAliasInput)) {
if (await this.elementVisible(page, this.addressStepAliasInput, 500)) {
await this.setValue(page, this.addressStepAliasInput, address.alias);
}
await this.setValue(page, this.addressStepPhoneInput, address.phone);
Expand Down
3 changes: 2 additions & 1 deletion tests/UI/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ type GlobalBrowserErrors = {

type GlobalScreenshot = {
FOLDER: string
AFTER_FAIL: any
AFTER_FAIL: boolean
EACH_STEP: boolean
}

type GlobalMaildevConfig = {
Expand Down
1 change: 1 addition & 0 deletions tests/UI/utils/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ global.GENERATE_FAILED_STEPS = process.env.GENERATE_FAILED_STEPS ? JSON.parse(pr
global.SCREENSHOT = {
FOLDER: process.env.SCREENSHOT_FOLDER || './screenshots',
AFTER_FAIL: process.env.TAKE_SCREENSHOT_AFTER_FAIL ? JSON.parse(process.env.TAKE_SCREENSHOT_AFTER_FAIL) : false,
EACH_STEP: process.env.TAKE_SCREENSHOT_AFTER_EACH_STEP ? JSON.parse(process.env.TAKE_SCREENSHOT_AFTER_EACH_STEP) : false,
};

global.maildevConfig = {
Expand Down
38 changes: 29 additions & 9 deletions tests/UI/utils/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
utilsCore,
utilsFile,
utilsPlaywright,
} from '@prestashop-core/ui-testing';
Expand Down Expand Up @@ -47,25 +48,44 @@ after(async function () {
}
});

const takeScreenShotAfterStep = async (browser: any, screenshotPath: string) => {
const currentTab = await utilsPlaywright.getLastOpenedTab(browser);

// Take a screenshot
if (currentTab !== null) {
await currentTab.screenshot(
{
path: screenshotPath,
fullPage: true,
},
);
}
};

/**
* @function afterEach
* @description Take a screenshot if a step is failed
*/
afterEach(async function () {
// Take screenshot if demanded after failed step
if (global.SCREENSHOT.AFTER_FAIL && this.currentTest?.state === 'failed') {
const currentTab = await utilsPlaywright.getLastOpenedTab(this.browser);
await takeScreenShotAfterStep(this.browser, `${global.SCREENSHOT.FOLDER}/fail_test_${screenshotNumber}.png`);
screenshotNumber += 1;
}
if (global.SCREENSHOT.EACH_STEP) {
const testPath = this.currentTest?.file;
// eslint-disable-next-line no-unsafe-optional-chaining
const folderPath = testPath?.slice(testPath?.indexOf('tests/UI') + 8).slice(0, -3);
let stepId: string = `screenshot-${screenshotNumber}`;

// Take a screenshot
if (currentTab !== null) {
await currentTab.screenshot(
{
path: `${global.SCREENSHOT.FOLDER}/fail_test_${screenshotNumber}.png`,
fullPage: true,
},
);
if (this.currentTest?.title) {
stepId = `${screenshotNumber}-${this.currentTest?.title}`;
}

const screenshotPath = `${global.SCREENSHOT.FOLDER}${folderPath}/${utilsCore.slugify(stepId)}.png`;
await takeScreenShotAfterStep(this.browser, screenshotPath).catch((err) => {
console.log(`screenshot for ${this.currentTest?.title} failed`, err);
});
screenshotNumber += 1;
}
});

0 comments on commit c719b30

Please sign in to comment.