diff --git a/.features-gen/homepage.feature.spec.js-snapshots/cartpage-darwin.png b/.features-gen/homepage.feature.spec.js-snapshots/cartpage-darwin.png new file mode 100644 index 0000000..82f0d6b Binary files /dev/null and b/.features-gen/homepage.feature.spec.js-snapshots/cartpage-darwin.png differ diff --git a/features/homepage.feature b/features/homepage.feature index a8c2a11..2a56593 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -1,7 +1,7 @@ -Feature: Playwright Home Page +Feature: Visual Testing of Cart Page - Scenario: Check title - Given I am on Playwright home page - When I click link "Get started" - Then I see in title "Installation" + Scenario: Create a base screenshot + Given I open url "https://flipkart.com" + When I click on cart link + Then Screenshot should get captured \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts index a9e80bf..ad37650 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,22 +2,42 @@ import { defineConfig, devices } from '@playwright/test'; import { defineBddConfig, cucumberReporter } from 'playwright-bdd'; const testDir = defineBddConfig({ - paths: ['features/*.feature'], - require: ['steps/*.ts'], - importTestFrom: 'steps/fixtures.ts', +// importTestFrom: 'steps/fixtures.ts', + paths: ['./features'], + require: ['steps/*.js'], + quotes: 'backtick', + featuresRoot: './features', }); export default defineConfig({ + repeatEach: 10, + /* Maximum time one test can run for. */ + timeout: 3000 * 3000, + expect: { + timeout: 7000 + }, testDir, - reporter: [cucumberReporter('html', { outputFile: 'cucumber-report/report.html' })], - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + reporter: [ + ['html'], + cucumberReporter('html', { outputFile: 'cucumber-report/report.html' }), + cucumberReporter('json', { outputFile: 'cucumber-report/report.json' }), + cucumberReporter('junit', { outputFile: 'cucumber-report/report.xml' }), + cucumberReporter('message', { outputFile: 'cucumber-report/report.ndjson' }), + ], + use: { + actionTimeout: 0, + browserName: 'chromium', + trace: 'retain-on-failure', + screenshot: 'only-on-failure', + video: { + mode: 'on-first-retry', + size: { width: 640, height: 480 } }, - // { - // name: 'firefox', - // use: { ...devices['Desktop Firefox'] }, - // }, - ] -}); + ignoreHTTPSErrors: true, + permissions: ['geolocation'], + launchOptions: { + args: ["--window-size=1920,1080", "--disable-web-security"], + }, + viewport: null + } +}); \ No newline at end of file diff --git a/steps/fixtures.ts b/steps/fixtures.ts deleted file mode 100644 index c0cab11..0000000 --- a/steps/fixtures.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { test as base } from 'playwright-bdd'; - -export const test = base.extend({ - // add your fixtures here -}); diff --git a/steps/index.js b/steps/index.js new file mode 100644 index 0000000..b987efd --- /dev/null +++ b/steps/index.js @@ -0,0 +1,16 @@ +import { expect } from '@playwright/test'; +import { createBdd} from 'playwright-bdd'; + +const { Given, When, Then } = createBdd(); + +Given('I open url {string}' , async ({ page }, url) => { + await page.goto(url); +}); + +When('I click on cart link', async ({ page }) => { + await page.getByText('Cart').click(); +}); + +Then('Screenshot should get captured', async ({ page }) => { + await expect(page).toHaveScreenshot('cartpage.png', { fullPage: true }); +}); \ No newline at end of file diff --git a/steps/index.ts b/steps/index.ts deleted file mode 100644 index 344cc64..0000000 --- a/steps/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { expect } from '@playwright/test'; -import { createBdd } from 'playwright-bdd'; -import { test } from './fixtures'; - -const { Given, When, Then } = createBdd(test); - -Given('I am on Playwright home page', async ({ page }) => { - await page.goto('https://playwright.dev'); -}); - -When('I click link {string}', async ({ page }, name: string) => { - await page.getByRole('link', { name }).click(); -}); - -Then('I see in title {string}', async ({ page }, text: string) => { - await expect(page).toHaveTitle(new RegExp(text)); -});