-
Notifications
You must be signed in to change notification settings - Fork 31
Add diverse tests for TRA #66
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
Open
rahul-b-stack
wants to merge
3
commits into
browserstack:tra
Choose a base branch
from
rahul-b-stack:sample-repo-task
base: tra
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| module.exports = { | ||
| coverageProvider: "v8", | ||
| maxConcurrency: 5, | ||
| maxWorkers: 5, | ||
| roots: ["src"], | ||
| testMatch: ["**/*.test.js"], | ||
| testMatch: ["**/test*.js"], | ||
| testPathIgnorePatterns: ["/node_modules/"], | ||
| testTimeout: 60 * 1000, | ||
| testTimeout: 30 * 1000, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver"); | ||
| const assert = require("assert"); | ||
|
|
||
| describe("BStack demo test Module A", () => { | ||
| let driver; | ||
| jest.retryTimes(2, {retryImmediately: true}); | ||
|
|
||
| beforeAll(async () => { | ||
| driver = new Builder() | ||
| .usingServer(`http://localhost:4444/wd/hub`) | ||
| .withCapabilities(Capabilities.chrome()) | ||
| .build(); | ||
|
|
||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await driver.quit(); | ||
| }) | ||
|
|
||
| test("Test with framework-level retry - 2 retries configured", async () => { | ||
| const randomOutcome = Math.random() > 0.7; // 30% chance of passing | ||
| assert(randomOutcome); | ||
| }); | ||
|
|
||
| test("Another Test with framework-level retry - 2 retries configured", async () => { | ||
| const randomOutcome = Math.random() > 0.7; // 30% chance of passing | ||
| assert(randomOutcome); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver"); | ||
| const assert = require("assert"); | ||
|
|
||
| describe("BStack demo test Module A", () => { | ||
| let driver; | ||
|
|
||
| beforeAll(async () => { | ||
| driver = new Builder() | ||
| .usingServer(`http://localhost:4444/wd/hub`) | ||
| .withCapabilities(Capabilities.chrome()) | ||
| .build(); | ||
|
|
||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await driver.quit(); | ||
| }) | ||
|
|
||
| test( | ||
| "flaky test - add products to cart", | ||
| async () => { | ||
| let elementLocator = Math.random() < 0.5 ? '//*[@id="1"]/p' : '//*[@id="random"]/p'; | ||
|
|
||
| // locating product on webpage and getting name of the product | ||
| await driver.wait(until.elementLocated(By.xpath(elementLocator))); | ||
| let productText = await driver | ||
| .findElement(By.xpath('//*[@id="1"]/p')) | ||
| .getText(); | ||
| // clicking the 'Add to cart' button | ||
| await driver.findElement(By.xpath('//*[@id="1"]/div[4]')).click(); | ||
| // waiting until the Cart pane has been displayed on the webpage | ||
| await driver.wait(until.elementLocated(By.className("float-cart__content"))); | ||
| await driver.findElement(By.className("float-cart__content")); | ||
| // locating product in cart and getting name of the product in cart | ||
| let productCartText = await driver | ||
| .findElement( | ||
| By.xpath( | ||
| '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]' | ||
| ) | ||
| ) | ||
| .getText(); | ||
| // checking whether product has been added to cart by comparing product name | ||
| expect(productText).toBe(productCartText); | ||
| }, | ||
| 10000 | ||
| ); | ||
|
|
||
| test("always failing test - missing element 1", async () => { | ||
| await driver.wait(until.elementLocated(By.xpath('//*[@id="non-existent-1"]/p'))); | ||
| }, 2000); | ||
|
|
||
| test("always failing test - same stacktrace 1", async () => { | ||
| await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p'))); | ||
| }, 2000); | ||
|
|
||
| test("always failing test - same stacktrace 2", async () => { | ||
| await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p'))); | ||
| }, 2000); | ||
|
|
||
| test("always passing test - example F", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example G", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example H", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example I", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example A", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - verify page title", async () => { | ||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }, 10000); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver"); | ||
| const assert = require("assert"); | ||
|
|
||
| describe("BStack demo test Module B", () => { | ||
| let driver; | ||
| jest.retryTimes(2, {retryImmediately: true}); | ||
|
|
||
| beforeAll(async () => { | ||
| driver = new Builder() | ||
| .usingServer(`http://localhost:4444/wd/hub`) | ||
| .withCapabilities(Capabilities.chrome()) | ||
| .build(); | ||
|
|
||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await driver.quit(); | ||
| }) | ||
|
|
||
| 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("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..."); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver"); | ||
| const assert = require("assert"); | ||
|
|
||
| describe("BStack demo test Module B", () => { | ||
| let driver; | ||
|
|
||
| beforeAll(async () => { | ||
| driver = new Builder() | ||
| .usingServer(`http://localhost:4444/wd/hub`) | ||
| .withCapabilities(Capabilities.chrome()) | ||
| .build(); | ||
|
|
||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await driver.quit(); | ||
| }) | ||
|
|
||
| test( | ||
| "flaky test - add products to cart", | ||
| async () => { | ||
| let elementLocator = Math.random() < 0.5 ? '//*[@id="1"]/p' : '//*[@id="random"]/p'; | ||
|
|
||
| // locating product on webpage and getting name of the product | ||
| await driver.wait(until.elementLocated(By.xpath(elementLocator))); | ||
| let productText = await driver | ||
| .findElement(By.xpath('//*[@id="1"]/p')) | ||
| .getText(); | ||
| // clicking the 'Add to cart' button | ||
| await driver.findElement(By.xpath('//*[@id="1"]/div[4]')).click(); | ||
| // waiting until the Cart pane has been displayed on the webpage | ||
| await driver.wait(until.elementLocated(By.className("float-cart__content"))); | ||
| await driver.findElement(By.className("float-cart__content")); | ||
| // locating product in cart and getting name of the product in cart | ||
| let productCartText = await driver | ||
| .findElement( | ||
| By.xpath( | ||
| '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]' | ||
| ) | ||
| ) | ||
| .getText(); | ||
| // checking whether product has been added to cart by comparing product name | ||
| expect(productText).toBe(productCartText); | ||
| }, | ||
| 10000 | ||
| ); | ||
|
|
||
| test("always failing test - same stacktrace 1", async () => { | ||
| await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p'))); | ||
| }, 2000); | ||
|
|
||
| test("always failing test - same stacktrace 2", async () => { | ||
| await driver.wait(until.elementLocated(By.xpath('//*[@id="common-error"]/p'))); | ||
| }, 2000); | ||
|
|
||
| test("always passing test - example F", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example G", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example H", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example I", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example A", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example B", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example C", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example D", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - example E", async () => { | ||
| assert(true); | ||
| }, 10000); | ||
|
|
||
| test("always passing test - verify page title", async () => { | ||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }, 10000); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| const { Builder, By, Key, until, Capabilities } = require("selenium-webdriver"); | ||
| const assert = require("assert"); | ||
|
|
||
| describe("BStack demo test Module C", () => { | ||
| let driver; | ||
| jest.retryTimes(2, {retryImmediately: true}); | ||
|
|
||
| beforeAll(async () => { | ||
| driver = new Builder() | ||
| .usingServer(`http://localhost:4444/wd/hub`) | ||
| .withCapabilities(Capabilities.chrome()) | ||
| .build(); | ||
|
|
||
| await driver.get("https://bstackdemo.com"); | ||
| await driver.wait(until.titleMatches(/StackDemo/i), 10000); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await driver.quit(); | ||
| }) | ||
|
|
||
| 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("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..."); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.