Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Aug 05, 2020 10:04

Emulators simulate the hardware and software of Android devices on your computer. They are great for lightweight and early testing, when you need to get started and receive quick feedback. Emulators create an operating environment that looks and functions much like the mobile device model, providing almost all of the capabilities of a real Android device. This includes the simulation of incoming phone calls and text messages, location services, various network speeds, device orientation/rotation, and different hardware sensors.

Testing your app on emulators may be faster and easier than doing so on a physical device, for example because it is faster to transfer data to the emulator than to a device connected over USB. However, as your app matures and you proceed in the development and testing cycle, you will also want to test on real devices under real-world user conditions, with real gestures, and for the most accurate performance load results.

If you are already familiar with Perfecto and want to switch from a real device to an emulator, take a look at the supported capabilities.
If you are new to Perfecto, watch the video and see the detailed steps under 1 | Configure and run your test and 2 | View execution results.


On this page:

Supported Appium and Selenium versions

As a best practice, we recommend that you select only the version of the Appium client to use and let the natural dependency and compatibility between Appium server and Selenium client versions take care of the rest. If you need to select a specific Selenium client, you must make sure that the client version is compatible with the selected version of the Appium client.

Perfecto supports Appium server 1.12.0 or later. See also Supported platforms.

Supported devices and OS versions

Perfecto supports emulators for Android versions 8.0 and later on the following devices.

Samsung

Galaxy S6, Galaxy S7, Galaxy S7 Edge, Galaxy S8, Galaxy S9, Galaxy S9 Plus, Galaxy S10, Galaxy S10 Plus, Galaxy S10e, Galaxy Note 1, Galaxy Note 9, Galaxy Z Flip, Galaxy S20, Galaxy S20 Plus, Galaxy S20 Ultra

Google

Pixel, Pixel 2, Pixel 2 XL, Pixel 3, Pixel 3 XL, Pixel 3a, Pixel 3a XL, Pixel 4, Pixel 4 XL, Pixel C

Demo video

Watch the video to see how to work with emulators in Perfecto.

For your convenience, following is the script used in the video. You can run it in your environment with the following changes:

  • <your_token>: The Perfecto security token for your user. For information about obtaining a token, see Generate security tokens.
  • <your_cloud_URL>: The URL for your Perfecto cloud.
Emulator sample script
package io.appium.java_client.ios;
import com.perfecto.reportium.client.ReportiumClient;
import com.perfecto.reportium.client.ReportiumClientFactory;
import com.perfecto.reportium.model.Job;
import com.perfecto.reportium.model.PerfectoExecutionContext;
import com.perfecto.reportium.model.Project;
import com.perfecto.reportium.test.TestContext;
import com.perfecto.reportium.test.result.TestResultFactory;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
public class EmulatorsWebDemoTest {
    public static ReportiumClient reportiumClient;
    protected static AndroidDriver<AndroidElement> driver;
    String expectedPageTitle = "My Store";
    private static By ADD_TO_CART = By.xpath("//*[@id=\"homefeatured\"]//*[@class=\"ajax_block_product col-xs-12 col-sm-4 col-md-3 first-in-line first-item-of-tablet-line first-item-of-mobile-line\"]/div[1]/div[2]/div[2]/a[1]/span[1]");
    private static By CHECKOUT = By.xpath("//*[@class=\"btn btn-default button button-medium\"]");
    private static By CART = By.xpath("//*[text()=\"Cart\"]");
    private static By CHECK_OUT = By.xpath("//*[@id=\"button_order_cart\"]");
    @BeforeClass
    public static void beforeClass() throws UnknownHostException, MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        String host = "<your_cloud_URL>";
        capabilities.setCapability("securityToken", "<your_token>");
        capabilities.setCapability("deviceName", "Pixel 3");
        capabilities.setCapability("useVirtualDevice", true);
        capabilities.setCapability("automationName", "Appium");
        capabilities.setCapability("browserName", "safari");
        driver = new Android(new URL("https://" + host + "/nexperience/perfectomobile/wd/hub"), capabilities);
        PerfectoExecutionContext perfectoExecutionContext = new PerfectoExecutionContext.PerfectoExecutionContextBuilder()
                .withProject(new Project("Emulators", "1.0"))
                .withJob(new Job("Android tests emulators", 45).withBranch("branch-name"))
                .withContextTags("Sanity")
                .withWebDriver(driver)
                .build();
        reportiumClient = new ReportiumClientFactory().createPerfectoReportiumClient(perfectoExecutionContext);
    }
    @Test
    public void EmulatorWebDemoTest() throws InterruptedException {
            reportiumClient.testStart("Android Web 'Demo' test", new TestContext("androidWeb"));
            System.out.println("************** START TEST *********************");
            reportiumClient.stepStart("Open 'http://automationpractice.com/' url");
            driver.get("http://automationpractice.com/");
            reportiumClient.stepEnd();
            Thread.sleep(2000);
            reportiumClient.stepStart("Get url Title");
            String actualPageTitle = driver.getTitle();
            System.out.println("Page Title: " + actualPageTitle);
            Assert.assertEquals(expectedPageTitle, actualPageTitle);
            reportiumClient.stepEnd();
            reportiumClient.stepStart("Clicking on 'Add to cart' button");
            System.out.println("Clicking on 'Add to cart' button");
            driver.findElement(ADD_TO_CART).click();
            reportiumClient.stepEnd();
            reportiumClient.stepStart("Get Screenshot");
            System.out.println("Get Screenshot");
            driver.getScreenshotAs(OutputType.BYTES);
            reportiumClient.stepEnd();
            Thread.sleep(2000);
            reportiumClient.stepStart("Clicking on 'Proceed to checkout' button");
            System.out.println("Clicking on 'Proceed to checkout' button");
            driver.findElement(CHECKOUT).click();
            reportiumClient.stepEnd();
            Thread.sleep(2000);
            reportiumClient.stepStart("Clicking on 'Cart' button");
            System.out.println("Clicking on 'Cart' button");
            driver.findElement(CART).click();
            reportiumClient.stepEnd();
            Thread.sleep(2000);
            reportiumClient.stepStart("Clicking on 'Check Out' button");
            System.out.println("Clicking on 'Check Out' button");
            driver.findElement(CHECK_OUT).click();
            reportiumClient.stepEnd();
            System.out.println("************** END TEST *********************");
            reportiumClient.testStop(TestResultFactory.createSuccess());
    }
        @AfterClass
        public static void afterClass () {
           String reportURL = reportiumClient.getReportUrl();
           System.out.println("Report URL - " + reportURL);
            if (driver != null) {
                driver.quit();
            }
        }
    }

1 | Configure and run your tests

This step walks you through adding the required capabilities to your existing Appium test scripts against a virtual mobile device. For comprehensive information on how to make Appium test scripts work with Perfecto, including adding dependencies and integrating with Perfecto Smart Reporting, see Appium.

Note: Before running your script, it is good practice to use the Get Licensee Information by Type | Simulators API to check if a free emulator license is available. This step prevents script failures.

To configure and run your tests:

  1. Open an existing test script in the IDE of your choice. 
    The following sample code snippet is not yet configured to run in Perfecto. It opens an app (Safari) on a mobile platform (iOS) of a specific version (13.3). The device name is specific (iPhone X).

    Pure Appium script not running on Perfecto
    <add script content>
  2. Configure the script to run in Perfecto by following the steps in the Appium section. In particular, you need to add dependencies, provide the security token and URL required to connect to the Perfecto cloud, and create an instance of the reporting client to integrate with Perfecto Smart Reporting.

  3. To run the test on a virtual device, add the capability useVirtualDevice and set it to true. The script should now look similar to the following. For more information on the individual capabilities, see Supported capabilities for virtual mobile devices and Supported Appium capabilities.

    Appium script running on Perfecto against a virtual device
    <add script content>

    Note: To install the application to be tested on the simulator, use the app capability. The application specified by this capability is installed and launched automatically at the beginning of the script. If you need to install more than one app, use the app capability for the main application and the otherApps capability for additional apps. For more information, see Supported Appium capabilities and the Appium information on General Capabilities.

  4. If you want to run your test on an emulator other than GoogleAPI, add the capability emulatorType and set it to Android or Playstore

    Note: Playstore provides more options and capabilities, but it it slower than the default emulator. Android provides less functions than the default but is slightly faster.

  5. Save your test.
  6. To avoid script failure, check if a simulator license is available via the Get License Information by Type API. 
  7. If a license is available, run your script.

2 | View execution results

This section describes how to view and analyze the results of your test executions in Perfecto.

To view execution results:

  1. When your test execution has finished, go to your Perfecto cloud instance and click Analyze Reports to open the Test Analysis view.
  2. In the Report Library, in the right pane, under Filter, select Platform type > Mobile simulator.

    If the right pane is not visible, click Configure View to open it.

    The report list refreshes to show only tests run on a simulator, as indicated by the simulator icon  in the Platform column.
    For more information on filtering, see Focus on what's important to you.

  3. Click the relevant test report.
  4. In the test view, do any of the following:
    • In the left pane, under Test Flow, review the test steps.
    • In the right pane, play the video.
    • At the top right, click the download button  to download the full report or the video.