Skip to main content
Transform your testing process with: Company-wide Licences, Test Observability & App Percy
No Result Found

Integrate your Selenium JavaScript tests with Percy

A guide to integrating your Selenium JavaScript automated tests with BrowserStack Percy. Catch visual differences in your web application on time.

Percy integrates with your tests using both Percy and BrowserStack SDK. To establish this integration, choose the appropriate SDK and refer to the following section accordingly:

You can integrate your tests using the BrowserStack SDK and manage browsers through Percy. Percy supports the latest versions of modern browsers, including Chrome, Firefox, Edge, and Safari.

Create Project

Create a Percy Web project using the Percy dashboard. For more information, see Create a project.

Update your BrowserStack config file

  1. In the browserstack.yml file, set percy: true.

  2. Set a projectName.
    Use the same projectName specified when creating the Percy Web Project.

  3. Set browserstackAutomation: true if it is currently set to false.

  4. Set percyCaptureMode: manual.

Currently, we do not support percyCaptureMode: auto on Percy web project and using BrowserStack SDK.

Below sample browserstack.yml file shows how to set the percy, the projectName, percyCaptureMode and the browserstackAutomation parameters.

Copy icon Copy
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
platforms:
  - os: Windows
    osVersion: 11
    browserName: Chrome
    browserVersion: 103.0
  - os: Windows
    osVersion: 10
    browserName: Firefox
    browserVersion: 102.0
  - os: OS X
    osVersion: Big Sur
    browserName: Safari
    browserVersion: 14.1
parallelsPerPlatform: 1
browserstackLocal: true
buildName: browserstack-build-1
projectName: Percy Web Prj
debug: false
percy: true
percyCaptureMode: manual
browserstackAutomation: true

Update your test script

To manually capture snapshot alongside the auto mode, implement the following steps in your test script:

  1. Import the BrowserStack Percy SDK in your test script.
  2. Add the percy.snapshot(driver, name) method at required points in your test script to get the snapshot you want.

Here’s an example:

Javascript
Copy icon Copy
const { percy } = require('browserstack-node-sdk');
describe("Mocha Test", () => {
  var driver;
  var caps = require("../" + conf_file).capabilities;
  beforeAll(() => {
    driver = new Builder()
      .usingServer(`http://example-servername/hub`)
      .withCapabilities(caps)
      .build();
  });
  
  afterAll(async () => {
    await driver.quit();
  })
  
  test("my test", async () => {
    // ....
    await percy.snapshot(driver, "My Snapshot")
    // ....
  });
})

Run your test script

Your script is ready to execute visual tests, and Percy is prepared to receive the build. After the tests runs, the snapshots are added to the same Percy project.

A build with the same project name and platform configuration mentioned in the BrowserStack config file appears on the Automate dashboard.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle