Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exports.config = {
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',

updateJob: false,
specs: ['./tests/specs/test.js'],
specs: ['./tests/m*/**'],
exclude: [],

logLevel: 'warn',
Expand Down
68 changes: 68 additions & 0 deletions tests/moduleA/specs/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
describe("BStackDemo Tests Module A", () => {
before(async () => {
await browser.url("https://bstackdemo.com/");
await browser.waitUntil(
async () => (await browser.getTitle()).match(/StackDemo/i),
5000,
"Title didn't match with BrowserStack"
);
});

it("flaky test - random product selection", async () => {
const randomProductIndex = Math.random() > 0.5 ? "1" : "2000";
const productOnScreen = await $(`//*[@id="${randomProductIndex}"]/p`);
const productOnScreenText = await productOnScreen.getText();

const addToCart = await $(`//*[@id="${randomProductIndex}"]/div[4]`);
await addToCart.click();

const productInCart = await $('//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]');
await browser.waitUntil(async () => (
await productInCart.getText()).match(productOnScreenText),
{ timeout: 5000 }
);
});

it("always failing test - missing element 1", async () => {
const nonExistentElement = await $('//*[@id="non-existent-1"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - missing element 2", async () => {
const nonExistentElement = await $('//*[@id="non-existent-2"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 1", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 2", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 3", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("passing test - verify page title", async () => {
const title = await browser.getTitle();
expect(title).to.match(/StackDemo/i); // Use 'match' instead of 'toMatch'
});

it("Test with framework-level retry - 2 retries configured", function () {
this.retries(2); // Framework-level retry
const randomOutcome = Math.random() > 0.7; // 30% chance of passing
if (!randomOutcome) {
throw new Error("Test failed, retrying...");
}
});

it("always passing test - example A", async () => {
const url = await browser.getUrl();
expect(url).to.include("bstackdemo");
});
});
85 changes: 85 additions & 0 deletions tests/moduleB/specs/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
describe("BStackDemo Tests Module B", () => {
before(async () => {
await browser.url("https://bstackdemo.com/");
await browser.waitUntil(
async () => (await browser.getTitle()).match(/StackDemo/i),
5000,
"Title didn't match with BrowserStack"
);
});

it("Flaky test - random product selection", async () => {
const randomProductIndex = Math.random() > 0.7 ? "1" : "2000";
const productOnScreen = await $(`//*[@id="${randomProductIndex}"]/p`);
const productOnScreenText = await productOnScreen.getText();

const addToCart = await $(`//*[@id="${randomProductIndex}"]/div[4]`);
await addToCart.click();

const productInCart = await $('//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]');
await browser.waitUntil(async () => (
await productInCart.getText()).match(productOnScreenText),
{ timeout: 5000 }
);
});

it("Failing test - clicking on a non-existent element", async () => {
const nonExistentElement = await $('//*[@id="non-existent-1"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("Failing test - same stacktrace", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("Failing test - same stacktrace 2", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("Failing test - same stacktrace 3", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("Passing test - verify page title", async () => {
const title = await browser.getTitle();
expect(title).to.match(/StackDemo/i); // Use 'match' instead of 'toMatch'
});

it("Always passing test", async () => {
const result = 6 + 3;
expect(result).to.equal(9);
});

it("Always passing test - example B", async () => {
const result = 1000 * 2;
expect(result).to.equal(2000);
});

it("Always passing test - example C", async () => {
const result = 1000 * 2;
expect(result).to.equal(2000);
});

it("Always passing test - example D", async () => {
const str1 = "BrowserStack is better than LambdaTest";
const str2 = str1.substring(3, 10);
expect(str2).to.equal("wserSta");
});

it("Always passing test - example E", async () => {
const str1 = "BrowserStack is better than LambdaTest";
const str2 = str1.substring(3, 11);
expect(str2).to.equal("wserStac");
});

it("Test with framework-level retry - 2 retries configured", function () {
this.retries(2); // Framework-level retry
const randomOutcome = Math.random() > 0.7; // 30% chance of passing
if (!randomOutcome) {
throw new Error("Test failed, retrying...");
}
});
});
63 changes: 63 additions & 0 deletions tests/moduleC/specs/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
describe("BStackDemo Tests Module C", () => {
before(async () => {
await browser.url("https://bstackdemo.com/");
await browser.waitUntil(
async () => (await browser.getTitle()).match(/StackDemo/i),
5000,
"Title didn't match with BrowserStack"
);
});

it("flaky test - random product selection", async () => {
const randomProductIndex = Math.random() > 0.5 ? "1" : "2000";
const productOnScreen = await $(`//*[@id="${randomProductIndex}"]/p`);
const productOnScreenText = await productOnScreen.getText();

const addToCart = await $(`//*[@id="${randomProductIndex}"]/div[4]`);
await addToCart.click();

const productInCart = await $('//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]');
await browser.waitUntil(async () => (
await productInCart.getText()).match(productOnScreenText),
{ timeout: 5000 }
);
});

it("always failing test - missing element 1", async () => {
const nonExistentElement = await $('//*[@id="non-existent-1"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - missing element 2", async () => {
const nonExistentElement = await $('//*[@id="non-existent-2"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 1", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 2", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("always failing test - same stacktrace 3", async () => {
const nonExistentElement = await $('//*[@id="common-error"]/p');
await nonExistentElement.click(); // This will throw an error
});

it("passing test - verify page title", async () => {
const title = await browser.getTitle();
expect(title).to.match(/StackDemo/i); // Use 'match' instead of 'toMatch'
});

it("Test with framework-level retry - 2 retries configured", function () {
this.retries(2); // Framework-level retry
const randomOutcome = Math.random() > 0.7; // 30% chance of passing
if (!randomOutcome) {
throw new Error("Test failed, retrying...");
}
});
});