Skip to content

Add Jest sample for Selenium load testing#6

Open
anushree-bstack wants to merge 1 commit into
mainfrom
add-jest-sample
Open

Add Jest sample for Selenium load testing#6
anushree-bstack wants to merge 1 commit into
mainfrom
add-jest-sample

Conversation

@anushree-bstack
Copy link
Copy Markdown
Collaborator

Adds a jest/ folder mirroring the per-framework layout used by java/, junit-4/, junit-5/, and testng/. Tests use selenium-webdriver against the BrowserStack pod's hub at localhost:4444/wd/hub and target bstackdemo.com for add-to-cart and full checkout flows, parity with the WebdriverIO public sample.

  • jest/browserstack-load.yml — Selenium + framework: jest, vus: 1, duration: 1m, us-east-1, references jest.config.js
  • jest/package.json — jest + selenium-webdriver
  • jest/jest.config.js — node env, runInBand-friendly
  • jest/tests/add-to-cart.test.js — bstackdemo add-to-cart
  • jest/tests/checkout.test.js — bstackdemo full checkout flow
  • jest/README.md — 5-step setup (clone, npm install, CLI, run, dashboard)
  • .gitignore — Node artifacts (node_modules, lockfiles)

Adds a jest/ folder mirroring the per-framework layout used by
java/, junit-4/, junit-5/, and testng/. Tests use selenium-webdriver
against the BrowserStack pod's hub at localhost:4444/wd/hub and target
bstackdemo.com for add-to-cart and full checkout flows, parity with
the WebdriverIO public sample.

- jest/browserstack-load.yml — Selenium + framework: jest, vus: 1,
  duration: 1m, us-east-1, references jest.config.js
- jest/package.json — jest + selenium-webdriver
- jest/jest.config.js — node env, runInBand-friendly
- jest/tests/add-to-cart.test.js — bstackdemo add-to-cart
- jest/tests/checkout.test.js — bstackdemo full checkout flow
- jest/README.md — 5-step setup (clone, npm install, CLI, run, dashboard)
- .gitignore — Node artifacts (node_modules, lockfiles)
@anushree-bstack anushree-bstack requested a review from a team as a code owner May 11, 2026 07:27
Copy link
Copy Markdown
Collaborator

@jhawarchirag jhawarchirag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against the four existing samples (java/, junit-4/, junit-5/, testng/) to keep this consistent with what customers already see in the repo. Three changes needed before merge — all are parity gaps with the sibling samples, not new conventions:

  1. Checkout test has no expect() and a different final-step flow than siblings — see inline comment on checkout.test.js.
  2. Driver lifecycle is beforeAll/afterAll; siblings re-create per test.
  3. Implicit wait + window().maximize() missing.

Non-blocking (pre-existing repo-wide, not introduced by this PR but worth a follow-up): brittle selectors (#\\33, react-select-2-option-0-0, deep float-cart chain), hardcoded sleep(500) after login, README OS↔arch swap in Linux binary links. These appear in every sample — best handled in a separate cleanup PR across all frameworks.

await driver.findElement(By.id("postCodeInput")).sendKeys("pincode");

// checkout
await driver.findElement(By.id("checkout-shipping-continue")).click();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing assertion + wrong final-step flow

All four sibling samples (java/, junit-4/, junit-5/, testng/) end the checkout test by asserting on the order confirmation message:

String checkoutMessage = driver.findElement(By.id("confirmation-message")).getText();
assertEquals("Your Order has been successfully placed.", checkoutMessage);

This jest version clicks checkout-shipping-continue → an xpath Continue → an xpath Orders and exits with no expect(). A silent failure mid-flow is the only signal a successful run gives — passing tests prove nothing.

Suggested change:

await driver.findElement(By.id("checkout-shipping-continue")).click();
const checkoutMessage = await driver
  .findElement(By.id("confirmation-message"))
  .getText();
expect(checkoutMessage).toBe("Your Order has been successfully placed.");

Drop the two trailing xpath clicks — siblings do not have them.

describe("BStackDemo test add to cart", () => {
let driver;

beforeAll(async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Driver lifecycle should be per-test, not shared across the file

Sibling samples use @BeforeMethod / @BeforeEach / @Before — a fresh driver per @Test. This file uses beforeAll / afterAll, so both test() blocks share one session. State from add-to-cart leaks into checkout (cart contents, cookies, scroll position). Swap to beforeEach / afterEach for parity with the other framework samples. Same change needed in checkout.test.js.

driver = await new Builder()
.usingServer(HUB_URL)
.forBrowser("chrome")
.build();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing implicit wait + window maximize (sibling parity)

All sibling samples configure a 10-second implicit wait and maximize the window after driver build:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().window().maximize();

Without these, findElement races against page render — flakes the first run on a fresh pod. Add after .build():

await driver.manage().setTimeouts({ implicit: 10000 });
await driver.manage().window().maximize();

Same change needed in checkout.test.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants