From 3e562d9807ce0a2e17f7dc08c883295a768c5467 Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Fri, 19 Dec 2025 10:56:44 +0530 Subject: [PATCH 1/4] add diverse tests --- .gitignore | 2 +- moduleA/test.js | 112 +++++++++++++++++++++++++++++++++++++++++ moduleB/test.js | 116 +++++++++++++++++++++++++++++++++++++++++++ moduleC/test.js | 108 ++++++++++++++++++++++++++++++++++++++++ playwright.config.js | 6 +-- 5 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 moduleA/test.js create mode 100644 moduleB/test.js create mode 100644 moduleC/test.js diff --git a/.gitignore b/.gitignore index 706a798..97dcb2e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ node_modules playwright-report test-results log/ -package-lock.json +./package-lock.json local.log diff --git a/moduleA/test.js b/moduleA/test.js new file mode 100644 index 0000000..894293c --- /dev/null +++ b/moduleA/test.js @@ -0,0 +1,112 @@ +const { expect, test } = require('@playwright/test'); + +let page; +const baseUrl = 'https://the-internet.herokuapp.com/'; + +test.beforeAll(async ({ browser }) => { + page = await browser.newPage(); + + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); + + // await page.getByRole('link', { name: 'Checkboxes' }).click(); + + // const checkbox1 = page.getByRole('checkbox').first(); + // const checkbox2 = page.getByRole('checkbox').last(); + + // expect(await checkbox1.isChecked()).toBe(false); + // await checkbox1.check(); + // expect(await checkbox1.isChecked()).toBe(true); + + // expect(await checkbox2.isChecked()).toBe(true); + // await checkbox2.uncheck(); + // expect(await checkbox2.isChecked()).toBe(false); + + // await page.goto(baseUrl); + // await page.getByRole('link', { name: 'Dropdown' }).click(); + + // const dropdown = page.locator('#dropdown'); + // await dropdown.selectOption({ label: 'Option 1' }); + + // await page.goBack(); +}); + +test('flaky test - intermittently passes and fails', async () => { + const headingName = Math.random() > 0.7 ? 'Available Examples' : 'Some Other Heading'; + const availableExamples = page.getByRole('heading', { name: headingName }); + const headingText = await availableExamples.textContent(); + expect(headingText).toContain('Available Examples'); +}); + +// test('always failing test - incorrect page title', async () => { +// await page.goto(baseUrl); + +// await page.waitForTimeout(3000); + +// await expect(page).toHaveTitle('Wrong title'); +// }); + +test('always failing test - same stacktrace 1', async () => { + throw new Error("NullPointerError: Cannot read property 'foo' of null"); +}); + +// test('always failing test - same stacktrace 2', async () => { +// throw new Error("NullPointerError: Cannot read property 'foo' of null"); +// }); + +test('always pasing test - example F', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example G', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example H', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example I', async () => { + expect(true).toBe(true); +}); + +test('always passing test - verify page title', async () => { + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); +}) + +test.describe(() => { + test.describe.configure({ retries: 2 }); + + test('Test with framework-level retry - 2 retries configured', async () => { + const randomOutcome = Math.random() > 0.7; // 30% chance of passing + if (!randomOutcome) { + throw new Error("Test failed, retrying..."); + } + }); +}); + +// test.describe(() => { +// test.describe.configure({ retries: 2 }); + +// test('Another Test with framework-level retry - 2 retries configured', async () => { +// const randomOutcome = Math.random() > 0.7; // 30% chance of passing +// if (!randomOutcome) { +// throw new Error("Test failed, retrying..."); +// } +// }); +// }); + +test('always pasing test - example A', async () => { + expect(true).toBe(true); +}); + +test.afterAll(async () => { + await page.close(); +}); diff --git a/moduleB/test.js b/moduleB/test.js new file mode 100644 index 0000000..c872cf5 --- /dev/null +++ b/moduleB/test.js @@ -0,0 +1,116 @@ +const { expect, test } = require('@playwright/test'); + +let page; +const baseUrl = 'https://the-internet.herokuapp.com/'; + +test.beforeAll(async ({ browser }) => { + page = await browser.newPage(); + + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); + + // await page.getByRole('link', { name: 'Checkboxes' }).click(); + + // const checkbox1 = page.getByRole('checkbox').first(); + // const checkbox2 = page.getByRole('checkbox').last(); + + // expect(await checkbox1.isChecked()).toBe(false); + // await checkbox1.check(); + // expect(await checkbox1.isChecked()).toBe(true); + + // expect(await checkbox2.isChecked()).toBe(true); + // await checkbox2.uncheck(); + // expect(await checkbox2.isChecked()).toBe(false); + + // await page.goto(baseUrl); + // await page.getByRole('link', { name: 'Dropdown' }).click(); + + // const dropdown = page.locator('#dropdown'); + // await dropdown.selectOption({ label: 'Option 1' }); + + // await page.goBack(); +}); + +test('flaky test - intermittently passes and fails', async () => { + const headingName = Math.random() > 0.7 ? 'Available Examples' : 'Some Other Heading'; + const availableExamples = page.getByRole('heading', { name: headingName }); + const headingText = await availableExamples.textContent(); + expect(headingText).toContain('Available Examples'); +}); + +// test('always failing test - same stacktrace 1', async () => { +// throw new Error("NullPointerError: Cannot read property 'foo' of null"); +// }); + +test('always failing test - same stacktrace 2', async () => { + throw new Error("NullPointerError: Cannot read property 'foo' of null"); +}); + +test('always pasing test - example F', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example G', async () => { + expect(true).toBe(true); +}); + +// test('always pasing test - example H', async () => { +// expect(true).toBe(true); +// }); + +test('always pasing test - example I', async () => { + expect(true).toBe(true); +}); + +test('always passing test - verify page title', async () => { + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); +}) + +test('always pasing test - example B', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example C', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example D', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example E', async () => { + expect(true).toBe(true); +}); + +test.describe(() => { + test.describe.configure({ retries: 2 }); + + test('Test with framework-level retry - 2 retries configured', async () => { + const randomOutcome = Math.random() > 0.7; // 30% chance of passing + if (!randomOutcome) { + throw new Error("Test failed, retrying..."); + } + }); +}); + +// test.describe(() => { +// test.describe.configure({ retries: 2 }); + +// test('Another Test with framework-level retry - 2 retries configured', async () => { +// const randomOutcome = Math.random() > 0.7; // 30% chance of passing +// if (!randomOutcome) { +// throw new Error("Test failed, retrying..."); +// } +// }); +// }); + +test.afterAll(async () => { + await page.close(); +}); diff --git a/moduleC/test.js b/moduleC/test.js new file mode 100644 index 0000000..6314f24 --- /dev/null +++ b/moduleC/test.js @@ -0,0 +1,108 @@ +const { expect, test } = require('@playwright/test'); + +let page; +const baseUrl = 'https://the-internet.herokuapp.com/'; + +test.beforeAll(async ({ browser }) => { + page = await browser.newPage(); + + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); + + // await page.getByRole('link', { name: 'Checkboxes' }).click(); + + // const checkbox1 = page.getByRole('checkbox').first(); + // const checkbox2 = page.getByRole('checkbox').last(); + + // expect(await checkbox1.isChecked()).toBe(false); + // await checkbox1.check(); + // expect(await checkbox1.isChecked()).toBe(true); + + // expect(await checkbox2.isChecked()).toBe(true); + // await checkbox2.uncheck(); + // expect(await checkbox2.isChecked()).toBe(false); + + // await page.goto(baseUrl); + // await page.getByRole('link', { name: 'Dropdown' }).click(); + + // const dropdown = page.locator('#dropdown'); + // await dropdown.selectOption({ label: 'Option 1' }); + + // await page.goBack(); +}); + +test('flaky test - intermittently passes and fails', async () => { + const headingName = Math.random() > 0.7 ? 'Available Examples' : 'Some Other Heading'; + const availableExamples = page.getByRole('heading', { name: headingName }); + const headingText = await availableExamples.textContent(); + expect(headingText).toContain('Available Examples'); +}); + +test('always failing test - incorrect page title', async () => { + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('Wrong title'); +}); + +test('always failing test - same stacktrace 1', async () => { + throw new Error("NullPointerError: Cannot read property 'foo' of null"); +}); + +// test('always failing test - same stacktrace 2', async () => { +// throw new Error("NullPointerError: Cannot read property 'foo' of null"); +// }); + +test('always pasing test - example F', async () => { + expect(true).toBe(true); +}); + +test('always pasing test - example G', async () => { + expect(true).toBe(true); +}); + +// test('always pasing test - example H', async () => { +// expect(true).toBe(true); +// }); + +test('always pasing test - example I', async () => { + expect(true).toBe(true); +}); + +test('always passing test - verify page title', async () => { + await page.goto(baseUrl); + + await page.waitForTimeout(3000); + + await expect(page).toHaveTitle('The Internet'); +}) + +test.describe(() => { + test.describe.configure({ retries: 2 }); + + test('Test with framework-level retry - 2 retries configured', async () => { + const randomOutcome = Math.random() > 0.7; // 30% chance of passing + if (!randomOutcome) { + throw new Error("Test failed, retrying..."); + } + }); +}); + +// test.describe(() => { +// test.describe.configure({ retries: 2 }); + +// test('Another Test with framework-level retry - 2 retries configured', async () => { +// const randomOutcome = Math.random() > 0.7; // 30% chance of passing +// if (!randomOutcome) { +// throw new Error("Test failed, retrying..."); +// } +// }); +// }); + +test.afterAll(async () => { + await page.close(); +}); diff --git a/playwright.config.js b/playwright.config.js index 0f3a2f4..612207d 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,10 +1,10 @@ // This is a sample config for what users might be running locally const config = { - testDir: './tests', - testMatch: '**/bstack_test*.js', + testDir: './', + testMatch: 'module*/**/*.js', /* Maximum time one test can run for. */ - timeout: 90 * 1000, + timeout: 20 * 1000, expect: { /** * Maximum time expect() should wait for the condition to be met. From 3aa01e5e95b6c612a4f6aaf0eb8b745142a7cb5a Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Fri, 19 Dec 2025 11:04:16 +0530 Subject: [PATCH 2/4] increase timeout to 10s --- playwright.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright.config.js b/playwright.config.js index 612207d..245bd3e 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -4,7 +4,7 @@ const config = { testMatch: 'module*/**/*.js', /* Maximum time one test can run for. */ - timeout: 20 * 1000, + timeout: 10 * 1000, expect: { /** * Maximum time expect() should wait for the condition to be met. From aa34cb56a11762a79e90344a6cf9f58cde01bf40 Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Fri, 19 Dec 2025 11:41:53 +0530 Subject: [PATCH 3/4] add build tag --- browserstack.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/browserstack.yml b/browserstack.yml index 931609d..16db2d8 100644 --- a/browserstack.yml +++ b/browserstack.yml @@ -21,6 +21,8 @@ buildName: browserstack build # Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} +CUSTOM_TAG_1: bstack_sample + # ======================================= # Platforms (Browsers / Devices to test) # ======================================= From ef08680fd6829170e53f48ce8d51ebe23ceb7924 Mon Sep 17 00:00:00 2001 From: Rahul Singh Date: Fri, 19 Dec 2025 12:36:42 +0530 Subject: [PATCH 4/4] add test tags --- moduleA/test.js | 6 +++--- moduleB/test.js | 4 ++-- moduleC/test.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/moduleA/test.js b/moduleA/test.js index 894293c..2b13c75 100644 --- a/moduleA/test.js +++ b/moduleA/test.js @@ -34,7 +34,7 @@ test.beforeAll(async ({ browser }) => { // await page.goBack(); }); -test('flaky test - intermittently passes and fails', async () => { +test('flaky test - intermittently passes and fails', { tag: ['@regression'] }, async () => { const headingName = Math.random() > 0.7 ? 'Available Examples' : 'Some Other Heading'; const availableExamples = page.getByRole('heading', { name: headingName }); const headingText = await availableExamples.textContent(); @@ -57,7 +57,7 @@ test('always failing test - same stacktrace 1', async () => { // throw new Error("NullPointerError: Cannot read property 'foo' of null"); // }); -test('always pasing test - example F', async () => { +test('always pasing test - example F', { tag: ['@must_pass'] }, async () => { expect(true).toBe(true); }); @@ -73,7 +73,7 @@ test('always pasing test - example I', async () => { expect(true).toBe(true); }); -test('always passing test - verify page title', async () => { +test('always passing test - verify page title', { tag: ['@p1'] }, async () => { await page.goto(baseUrl); await page.waitForTimeout(3000); diff --git a/moduleB/test.js b/moduleB/test.js index c872cf5..38df9ec 100644 --- a/moduleB/test.js +++ b/moduleB/test.js @@ -53,7 +53,7 @@ test('always pasing test - example F', async () => { expect(true).toBe(true); }); -test('always pasing test - example G', async () => { +test('always pasing test - example G', { tag: ['@must_pass', '@p1'] }, async () => { expect(true).toBe(true); }); @@ -92,7 +92,7 @@ test('always pasing test - example E', async () => { test.describe(() => { test.describe.configure({ retries: 2 }); - test('Test with framework-level retry - 2 retries configured', async () => { + test('Test with framework-level retry - 2 retries configured', { tag: ['@regression'] }, async () => { const randomOutcome = Math.random() > 0.7; // 30% chance of passing if (!randomOutcome) { throw new Error("Test failed, retrying..."); diff --git a/moduleC/test.js b/moduleC/test.js index 6314f24..af57ee9 100644 --- a/moduleC/test.js +++ b/moduleC/test.js @@ -41,7 +41,7 @@ test('flaky test - intermittently passes and fails', async () => { expect(headingText).toContain('Available Examples'); }); -test('always failing test - incorrect page title', async () => { +test('always failing test - incorrect page title', { tag: ['@regression'] }, async () => { await page.goto(baseUrl); await page.waitForTimeout(3000); @@ -69,7 +69,7 @@ test('always pasing test - example G', async () => { // expect(true).toBe(true); // }); -test('always pasing test - example I', async () => { +test('always pasing test - example I', { tag: ['@p1'] }, async () => { expect(true).toBe(true); });