Skip to main content
No Result Found

Integrate App Percy with Appium and Java

Learn how to integrate Appium with Java automated tests and Percy to catch visual differences in your application.

App 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:

To integrate your Java based test suite with App Percy using the BrowserStack SDK, follow these steps:

Prerequisites

Before you start, ensure that you have the following:

Set BrowserStack credentials

Save your BrowserStack credentials as environment variables. It simplifies running your test suite from your local or CI environment. You can export the environment variables for the Username and Access Key of your BrowserStack account or you can set it in the config file.

Copy icon Copy
Copy icon Copy

Install BrowserStack SDK using Maven Archetype

Maven Archetype provides a template to quickly configure your project. Copy & run the following command on your terminal/command prompt to add browserstack-java-sdk dependency in your pom.xml and browserstack.yml file in your project.

Copy icon Copy
Copy icon Copy

Update your BrowserStack config file

In the browserstack.yml file:

  1. Set percy: true.

  2. Set a projectName.
    After you run a test, an App Automate project and an App Percy project are created with the project name you set here.
    If a App Percy project by the name you set in the browserstack.yml file already exists, your screenshots are added to the same project. However, if the name matches a Percy project, your visual tests will continue to run, but an error message will appear in your logs. Your functional tests still run as expected.

  3. Set percyCaptureMode: manual.

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

Copy icon Copy

Manually add Percy screenshot method to update test script

To manually capture screenshots, implement the following steps in your test script:

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

Here’s an example:

Java
Copy icon Copy

Run your test script

Congratulations!

You have successfully integrated App Percy with BrowserStack SDK and created your first build. 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, App Percy takes new screenshots. You can then see the comparisons between the two runs on the new build. You can access the App Percy dashboard directly from the App Automate dashboard.

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

We highly recommend using our BrowserStack SDK for Percy integration.

Prerequisites

In order to conduct Percy visual testing for Java Appium, you must possess the following dependencies:

  • Appium version < 2.0.1
  • Node 12+ with npm

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

Run the given command to set PERCY_TOKEN as an environment variable:

Copy icon Copy

Install Percy packages

Install Percy CLI by running the following command:

Copy icon Copy

Install dependencies

Add percy-appium-app to your project dependencies. If you’re using Maven:

Copy icon Copy

Update test script

Make sure to import AppPercy in your code.

Below is an example test using the percy.screenshot function. Use this function wherever you have to take a screenshot.

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):
  • fullScreen - (optional) It indicates if the app is a full screen
  • options - (optional) screenshot params: Use ScreenshotOptions to set following params to override
  • deviceName - Device name on which screenshot is taken
  • statusBarHeight - int; Height of status bar for the device
  • navBarHeight - int; Height of navigation bar for the device
  • orientation - Orientation of the application
  • FullPage: boolean; [alpha] only supported on App Automate driver sessions [ needs @percy/cli 1.20.2+ ]
  • In case scrollview is overlapping with other app elements. Offsets can be provided to reduce the area which needs to be considered for scrolling:
    • topScrollviewOffset :(optional) [alpha] offset from top of scrollview [ needs @percy/cli 1.20.2+ ]; int
    • bottomScrollviewOffset: (optional) - [alpha] offset from bottom of scrollview [ needs @percy/cli 1.20.2+ ]; int
  • ScreenLengths: int; [alpha] max screen lengths for fullPage [ needs @percy/cli 1.20.2+ ]
  • ScrollableXpath (optional) - [alpha] scrollable element xpath for fullpage [ needs @percy/cli 1.20.2+ ]; string
  • ScrollableId (optional) - [alpha] scrollable element accessibility id for fullpage [ needs @percy/cli 1.20.2+ ]; string
  • IgnoreRegionXpaths (optional) - elements xpaths that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
  • IgnoreRegionAccessibilityIds (optional) - elements accessibility_ids that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
  • IgnoreRegionAppiumElements (optional) - appium elements that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of appium element object
  • CustomIgnoreRegions (optional) - Custom locations that users want to ignore in visual diffs, with (0, 0) starting at the top left (requires @percy/cli 1.23.0+); list of ignore_region objects.
  • IgnoreRegion:-
    • Description: This class represents a rectangular area on a screen that needs to be ignored for visual diff.
    • constructor:-
Copy icon Copy
  • Parameters:
    • top (int): Top coordinate of the ignore region.
    • bottom (int): Bottom coordinate of the ignore region.
    • left (int): Left coordinate of the ignore region.
    • right (int): Right coordinate of the ignore region.
  • Raises IllegalArgumentException:If top, bottom, left, or right is less than 0, or top is greater than or equal to bottom, or left is greater than or equal to right.
  • valid: Ignore region should be within the boundaries of the screen.


Run your test script

Run your tests using percy app:exec.

If you are unable to use the percy app:exec command or prefer to run your tests using IDE run options, you can use the percy app:exec:start and percy app:exec:stop commands. To learn more, visit Run Percy.

Copy icon Copy
Copy icon Copy

This command starts Percy, create a new Percy build, takes snapshots and uploads them to your project, and stops Percy:

Copy icon Copy

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