Percy Developer Hub

Welcome to the Percy Developer Hub. You'll find comprehensive guides and documentation to help you start working with Percy as quickly as possible, as well as support if you get stuck. Let's jump right in!

Protractor

Integrating Percy with your Protractor tests

πŸ‘

Covered in this doc

Visual regression testing for Protractor
Installing @percy/protractor
Adding and calling percySnapshot(<snapshotName>, <options>)

Package StatusPackage Status CircleCICircleCI This project is using Percy.io for visual regression testing.This project is using Percy.io for visual regression testing.

Setup


If you're not ready to integrate Percy, check out our 2-minute Protractor tutorial and example app with Percy for Protractor already added.

Install @percy/protractor using npm:

npm install --save-dev @percy/protractor

Or using yarn:

yarn add --dev @percy/protractor

In order to start creating snapshots from your Protractor tests, you'll need to import the percySnapshot() function from the @percy/protractor package. You will need to do this in each file from which you want to take snapshots:

const { percySnapshot } = require('@percy/protractor')

You will then use percySnapshot(...) to generate a snapshot:

describe('Integration test with visual testing', function() {
  it('Loads the app', async function() {
    await browser.get('http://example.com')
    await percySnapshot('My snapshot')
  })
})

Finally, wrap your script or test runner command in the percy exec command. This will start a Percy agent to receive snapshots from your tests and upload them to your Percy dashboard.

Before you can successfully run Percy, the PERCY_TOKEN environment variable must be set:

# Windows
$ set PERCY_TOKEN=<your token here>

# Unix 
$ export PERCY_TOKEN=<your token here>

Your new test command becomes:

percy exec -- protractor conf.js

Note the double dash with spaces, --, between percy exec and your test run command.

That's it! Now, whenever your tests run with the Percy command, a snapshot of the app in that state will be uploaded to Percy for visual regression testing!

For an example showing how to add Percy snapshots to an existing Protractor test suite, see https://github.com/percy/example-percy-protractor/pull/4/files.

🚧

Make sure Control Flow is disabled

Our SDK is written using async / await. You will need to disable the WebDriver Control Flow for reliable results. See this issue for more information

Configuration


percySnapshot(snapshotName)
percySnapshot(snapshotName, options)

snapshotName is a required string that will be used as the snapshot name. It can be any string that makes sense to you to identify the page state. It should be unique and remain the same across builds. For more details on generating snapshot names, see Autogenerated snapshot names.

optionsΒ is an optional hash that can include:

  • widths: An array of integers representing the browser widths at which you want to take snapshots.

  • minHeight: An integer specifying the minimum height of the resulting snapshot, in pixels. Defaults to 1024px.

  • percyCSS: A string containing Percy specific CSS that will be applied to this snapshot.

  • requestHeaders: An object containing HTTP headers to be sent for each request made during asset discovery for this snapshot.

🚧

percySnapshot(...) relies on the presence of the Protractor browser instance, and so can only be called within the context of a Protractor test. An exception will be thrown if the browser instance is not present.

For example:

percySnapshot('Homepage test');
percySnapshot('Homepage responsive test', { widths: [768, 992, 1200] });

Global configuration

You can also configure Percy to use the same options over all snapshots. To see supported configuration including widths read our SDK configuration docs

Updated 6 months ago


What's next

Once you've set up Percy for Protractor, the next step is to add Percy to your CI service. That way, every time CI runs, Percy will automatically kick off visual tests as well.

CI integration overview

Protractor


Integrating Percy with your Protractor tests

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.