Creating Scripts

In this guide we will be using the following test scenario to demonstrate how to develop a simple test script:

  1. Launch Calculator application.
  2. Enter 2x2.
  3. Validate that the result is 4.

Basic Script

Oxygen provides a number of built-in objects (modules) for automation purposes. Because in our sample scenario we want to automate only mobile application interactions, we will use the mob module. Refer to API Reference for a complete list of provided modules and methods.

  1. Launch Calculator application.

    var caps = {
    platformName: "Android",
    platformVersion: "4.2",
    deviceName: "934a9e01",
    appPackage: "com.sec.android.app.popupcalculator",
    appActivity: "com.sec.android.app.popupcalculator.Calculator"
    };
    mob.init(caps);

    init command expects to receive capabilties object defining the application we would like to launch as well as the device specification.

  2. Type 2x2

    mob.click('desc=2');
    mob.click('desc=multiplication');
    mob.click('desc=2');

    click performs tap on an element defined by a locator which will. See API Reference for a list of supported locators.

  3. Validate result is 4.
    mob.assertText('class=android.widget.EditText', '4');



Entire script:

var caps = {
    platformName: "Android",
    platformVersion: "4.2",
    deviceName: "934a9e01",
    appPackage: "com.sec.android.app.popupcalculator",
    appActivity: "com.sec.android.app.popupcalculator.Calculator"
};
mob.init(caps);
mob.click('desc=2');
mob.click('desc=multiplication');
mob.click('desc=2');
mob.assertText('class=android.widget.EditText', '4');

Now open a new script in the IDE and paste the above snippet into it. Save the file as calculator.js. Switch to the mobile mode by clicking phone icon, select the device on which to run the test from the dropdown menu, and click Run.