Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

eThis section provides instructions on how to run a Appium/Selenium test with Java in Perfecto. It assumes that you are:

  • Familiar with Appium/Selenium
  • Do not have any existing tests to work with
  • A novice user of Perfecto

To run tests in Perfecto, they need to include:

  • What driver you want to use
  • Where your Perfecto instance is located 
  • Who you are
  • What devices you want to work on

Our sample project is available on GitHub: https://github.com/PerfectoMobileSA/PerfectoSampleProject


Panel

On this page:

Table of Contents
maxLevel2
stylesquare

Prerequisites

Before you get started, make sure you have installed the following:

1 | Get started

Our sample project includes the following simple scripts: PerfectoAppium.java and PerfectoSelenium.java. The scripts accesses the Perfecto website and verify the title. They only serves the purpose of showing you how to connect to Perfecto.

Info
iconfalse
Note: For information on running the final scripts, see the README.md file included with the sample project.

To get started: 

  1. Access the sample project in GitHub and copy the clone URL: https://github.com/PerfectoMobileSA/PerfectoSampleProject
  2. Open your IDE and check out the project from GitHub.

2 | Configure the script for Perfecto

In this step, you configure security information and the Perfecto cloud name. If needed, you can also modify the device details.

Info
iconfalse
Note: The project's pom.xml file is institutional because it holds all configurations and dependencies. In its initial state, when you first create a project, the file is very simple. The pom.xml file in our sample project has been updated with the required Perfecto dependencies.

Expand a step to view its content.


UI Expand
titleA | Supply the security token

Generate your security token through the Perfecto UI. Search for the following line in PerfectoAppium.java and replace <<security token>> with your Perfecto security token. 

Code Block
String securityToken = "<<security token>>";

Alternatively, you can pass the token as a Maven property, as follows:

Code Block
-DsecurityToken=<<SECURITY TOKEN>>

Anchor
addToken
addToken
Excerpt Include
PD:Generate security tokens
PD:Generate security tokens
nopaneltrue

UI Expand
titleB | Select a device

Use capabilities to select a device from the Perfecto lab. You can be as generic or specific as needed. Our Appium script includes the following capabilities:

  • model: The device model
  • openDeviceTimeout: The timeout, in minutes, to wait for a specific device in case it is not available at the start of the script (use with caution)
  • appPackage: The Java package of the Android app you want to run
Code Block
titleAppium
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
...	
capabilities.setCapability("model", "Galaxy.*");
capabilities.setCapability("openDeviceTimeout", 2);
capabilities.setCapability("appPackage", "com.sec.android.app.popupcalculator");

Our Selenium script only includes the platformName capability (which specifies the device operating system), as shown in the following code snippet. For more information, see Define capabilitiesUse capabilities to select a device, and Supported Appium capabilities. 

Code Block
titleSelenium
DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY);
...
capabilities.setCapability("platformName", "Android");

You can use the Manual Testing view in the Perfecto UI to generate a code snippet with device-specific capabilities that you can then copy-paste into your script. 

To generate capabilities (for mobile or web devices) through the Perfecto UI:

  1. On the Perfecto landing page, under Manual Testing, click Open Device.
  2. In the Manual Testing view, do the following to generate capabilities:
    Excerpt Include
    PD:Select a device for manual testing
    PD:Select a device for manual testing
    nopaneltrue
UI Expand
titleC | Provide the URL to connect to the Perfecto cloud

As part of creating an instance of the RemoteWebDriver, you need to supply the URL of your Perfecto cloud. Search for the following line in PerfectoAppium.java and replace <<cloud name>> with the name of your Perfecto cloud (for example: demo).

Code Block
String cloudName = "<<cloud name>>";

Alternatively, you can pass the TestNG file name as a Maven property to execute specific TestNG files, as follows:

Code Block
-DtestngXmlFile=<<testng file name>>.xml
Info
iconfalse

Note: testng_perfecto.xml is configured by default. You can override it by passing the preferred TestNG name as a Maven property, such as -DtestingXmlFile=testng.xml, to execute all 4 tests in parallel. 

The general structure of the URL string is as follows:

"https://" + Utils.fetchCloudName(cloudName) + ".perfectomobile.com/nexperience/perfectomobile/wd/hub

Here is the respective line from our sample script:

Code Block
WebDriver driver = new RemoteWebDriver(new URL("https://" + Utils.fetchCloudName(cloudName) + ".perfectomobile.com/nexperience/perfectomobile/wd/hub"), capabilities);
UI Expand
titleD | Execute the test

Include Page
PD:_automation-execute-test
PD:_automation-execute-test