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/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) # ======================================= diff --git a/moduleA/test.js b/moduleA/test.js new file mode 100644 index 0000000..2b13c75 --- /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', { 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(); + 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', { tag: ['@must_pass'] }, 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', { tag: ['@p1'] }, 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..38df9ec --- /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', { tag: ['@must_pass', '@p1'] }, 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', { tag: ['@regression'] }, 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..af57ee9 --- /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', { tag: ['@regression'] }, 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', { tag: ['@p1'] }, 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..245bd3e 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: 10 * 1000, expect: { /** * Maximum time expect() should wait for the condition to be met.