Skip to main content
No Result Found

Integrate your Espresso test suite with App Percy

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

Integrate App Percy with your test suite to run visual tests. To do that, follow these steps:

Exercise caution when integrating the Espresso SDK while using dependency verification, as it may lead to build failure issues. Resolve this by regenerating your ‘verification-metadata.xml’ file after adding the SDK. Learn more

Create new app project on percy dashboard

Sign in to Percy and create a new app type project. After you’ve created the project, you’ll be shown a PERCY_TOKEN environment variable. Percy will use the PERCY_TOKEN to know which organisation and project to upload the screenshots to. You will need this PERCY_TOKEN in next steps.

Create an App Percy project

Set the project token as an environment variable

To set the project token as an environment variable, include the PERCY_TOKEN in the curl command as shown in step 6.

Install Percy packages

Install Percy CLI by running the following command:

Copy icon Copy

Install dependencies

Add the Percy library “io.percy:espresso-java:1.0.3” to your Gradle file:

Copy icon Copy

Update the app manifest file

In order to make calls to the Percy CLI and enable HTTP requests, you need to check if the required permissions and attributes are set in the manifest file. If they are not set, you can add them using the below code:

Copy icon Copy

When using the android:networkSecurityConfig attribute in your network configuration file, there is no need to include usesCleartextTraffic attribute, as it eliminates the cleartext permissions by discarding the cleartext attribute.

In this case you can update the the network config file using the below code:

Copy icon Copy

Update test script

Import the App Percy library to use the methods and attributes required to take screenshots.

In the following code, the percy.screenshot(“name”, “options”) method is called twice. In the first instance we are passing only the required argument which is “name”. In the second instance, we are passing both the required and optional “options”.

Copy icon Copy
Copy icon Copy

We are passing the required arguments.percy.screenshot method.

The screenshot method arguments are:

Copy icon Copy
  • name\ (required) - The screenshot name; must be unique to each screenshot
  • Additional screenshot options (overrides any project options):
    • setDeviceName(String) - A custom device name assigned to override the device name fetched by the SDK.
    • setStatusBarHeight(Int) - Specifies the height of the status bar in pixels, allowing you to override the value fetched by the SDK if needed.
    • setNavBarHeight(Int) - Specifies the height of the navigation bar in pixels, allowing you to override the value fetched by the SDK if needed.
    • setFullScreen(Boolean) - Indicates whether the app is currently in fullscreen mode.
    • setOrientation(String) - Indicates the current orientation of the app to the SDK, either “portrait” or “landscape”. Note: This is solely for tagging purposes and does not modify the actual device orientation.


Run your test script

Run your tests using either BrowserStack App Automate or your local Android Studio environment.

Run with App Automate

When you run the script on App Automate, proceed to generate the application APK and the test suite APK files. For the App Automate session to work with App Percy, we need to provide App Percy parameters.

For instance, in “appPercy”: {“env”: {“PERCY_BRANCH”: “test”}, “PERCY_TOKEN”: “"}, the env parameter can contain any of the following Percy environment variables.

Execute tests using the following command post updating App Percy params:

Copy icon Copy

Run if using SCM integration

Copy icon Copy
  • Include the below environment variables when creating the Percy build in order to get the correct build status in your VCS: PERCY_BRANCH, PERCY_COMMIT, PERCY_PULL_REQUEST
  • App Percy supports sharding with App Automate, and it is advised to use the “all” deviceSelection strategy when using App Percy. Using the “any” deviceSelection strategy may lead to inconsistent builds, as a random device from the provided device list will be assigned to shards, which results in the generation of new snapshots during your build process.

Run in local Android Studio

When you run the test script within a local Android Studio environment, continue modifying the test script by adding the following code snippet, which adds the Percy Server address.

Copy icon Copy

For simulators, use IP 10.0.2.2, for real devices, get an IP address based on the device you are using.

  1. Open the terminal and set the Percy token:export PERCY_TOKEN=\<PERCY_TOKEN>
  2. Start your Percy server by running the following command:percy app:exec start.
  3. Run your Espresso tests.
  4. Stop your Percy server by running the following command:percy app:exec stop.

Congratulations!

You have successfully created your first build on App Percy. To see the build with snapshots of your application, visit your project in Percy.

When you run another build with visual changes to your application, Percy takes new snapshots. You can then see the comparisons between the two runs on the new build.

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