Mobile Action Documentation

    Mobile Action Documentation


    Article summary

    Mobile actions are exposed in the Mobile Automation framework in Quality Modeller. The corresponding Git repository is available https://github.com/CuriositySoftwareIreland/TestModeller-JavaAppiumFramework . This uses Appium with Java as the underlying automation technology. 

    When the framework is imported into Quality Modeller, the actions below are available in the 'MobileGeneralActions' module. This provides an accelerator for automating common actions on mobile devices. This class can be extended to incorporate your own keywords and actions as necessary.


    MobileGeneralActions Module.

    QuickStart Mobile Test Automation

    To learn how you can quickly get started with Mobile Automation in Quality Modeller, check out our QuickStart guide: QuickStart Mobile Automation


    Location Strategy

    All keywords in the Quality Modeller MobileGeneralActions library that need to find an element on the page take a locator argument. Locator is a string that describes how to locate an element using a syntax specifying different location strategies. 

    By default, when a locator is provided, it is matched against the key attributes of the particular element type. For iOS and Android, the XPath is used as default. 

    Appium inspector is a great utility for finding the appropriate locator https://github.com/appium/appium-inspector.

    Strategy

    Example

    XPath

    xpath://input[id="username"]

    Id

    id:usernameId

    Class

    class:username

    Css

    css:#usernameId

    AccesibilityId

    accessibilityId:usernameObj


    Library Usage

    In order to use the library actions, you need to have an Appium server setup; with appropriate virtual or physical devices setup. This can also be a cloud environment provider (e.g., SauceLabs / Browserstack / Perfecto / …).

    Once you have a connection to an Appium instance, the first thing you need to do is specify the desired capabilities of the device you wish to test.

    This can be achieved using the 'Add Capability' function. E.g. below, we set up the capability to test on an Android device. Read more about desired capabilities.

    Text
    addCapability("platformName","Android"); addCapability("app","C:\\APKS\\tinder.apk");
    addCapability("platformName","Android"); addCapability("app","C:\\APKS\\tinder.apk");

    Next, we need to connect to the Appium instance. This can be achieved using the 'Connect Appium' function, with the URL of the Appium host. E.g. below, we connect to an Appium server hosted locally. For cloud providers, this is the Appium URL provided (typically with the API key / username embedded). 

    connectAppium("http://192.168.0.125:4723/wd/hub");

    Mobile Actions

    Move App to Background (int seconds)


    Arguments

    seconds - The number of seconds to put the device in the background for.

    Documentation

    Puts the application in the background on the device for a certain duration.

    Capture Page Screenshot


    Documentation

    Takes a screenshot of the current page and embeds it into the log.

    Clear Text (string locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Clears the text field identified by locator.

    Click a point (int x, int y)


    Arguments

     x - x coordinate on the screen to click.

    y - y coordinate on the screen to click.

    Documentation

    Click on a specified point on the screen.

    Click Element (string locator)


    Arguments

    locator - The object identifier. See locator strategy above.


    Documentation

    Click element identified by locator.

    Click Element At Coordinates (int x, int y)


    Arguments

     x - x coordinate on the screen to click.

    y - y coordinate on the screen to click.

    Documentation

    Click element at a certain coordinate

    Close Application


    Documentation

    Closes the current application.

    Element Attribute Should Match (String locator, String attr_name, String value)


    Arguments

    locator - The object identifier. See locator strategy above.

    attr_name - attirbute name to retrieve.

    value - value of the attribute to assert the value against

    Documentation

    Verify that an attribute of an element matches the expected criteria.

    Element Should Be Disabled (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Verifies that element identified with locator is disabled.

    Element Should Be Enabled (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Verifies that element identified with locator is enabled.

    Element Should Be Visible (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Verifies that element identified with locator is visible.

    Element Should Contain Text (String locator, String text)


    Arguments

    locator - The object identifier. See locator strategy above.

    text - The text to assert the element contains.

    Documentation

    Verifies element identified by locator contains text expected.

    Element Should Not Contain Text (String locator, String text)


    Arguments

    locator - The object identifier. See locator strategy above.

    text - The text to assert the element does not contain.

    Documentation

    Verifies element identified by locator does not contain text expected.

    Element Text Should Be (String locator, String text)


    Arguments

    locator - The object identifier. See locator strategy above.

    text - The text to assert the element text is equal to.

    Documentation

    Verifies element identified by locator exactly contains text expected.

    Execute Adb Shell (String command)


    Arguments

    command - the Adb shell command to execute.

    Documentation

    Execute ADB shell commands

    Execute Async Script (String script)


    Arguments

    script - the script to execute.

    Documentation

    Inject a snippet of Async-JavaScript into the page for execution in the context of the currently selected frame (Web context only).

    Execute Script (String script)


    Arguments

    script - the script to execute.

    Documentation

    Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame (Web context only).

    Get Appium SessionId


    Documentation

    Returns the current session ID as a reference

    Get Capability (String capability)


    Arguments

    capability - The Appium capability to retrieve the value.

    Documentation

    Return the desired capability value by desired capability name

    Add Capability (String capabilityName, String value)


    Arguments

    capability - The Appium capability to set the value.

    value - The value to set for the capability.

    Documentation

    Add a desired capability value by desired capability name

    Get Element Attribute (String locator, String attribute)


    Arguments

    locator - The object identifier. See locator strategy above.

    attribute - The element attribute to retrieve.

    Documentation

    Get element attribute using given attribute: name, value,...

    Get Element Location (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Get element location

    Get Element Size (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Get element size

    Get Matching Xpath Count (String xpath)


    Arguments

    xpath - The xpath to execute and get the number of matching elements for.

    Documentation

    Returns number of elements matching xpath

    Get Source


    Documentation

    Returns the entire source of the current page.

    Get Text (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Get element text (for hybrid and mobile browser use xpath locator, others might cause problem)

    Get Window Height


    Documentation

    Get current device height.

    Get Window Width


    Documentation

    Get current device width.

    Hide Keyboard


    Documentation

    Hides the software keyboard on the device.

    Input Text (String locator, String text)


    Arguments

    locator - The object identifier. See locator strategy above.

    text - The text to enter into the input element.

    Documentation

    Types the given text into text field identified by locator.

    Input Value (String locator, String value)


    Arguments

    locator - The object identifier. See locator strategy above.

    value - The value to set in the input element.

    Documentation

    Sets the given value into text field identified by locator. This is an IOS only keyword, input value makes use of set_value

    Start Activity (String applicationPackage, String applicationActivity)


    Arguments

    applicationPackage - The package containing the activity to start. 

    applicationActivity - The activity to start.

    Documentation

    Start Activity App via Appium

    Install App (String applicationPath)


    Arguments

    applicationPath - Path to the APK file of the application to install.

    Documentation

    Install App via Appium

    Landscape


    Documentation

    Set the device orientation to LANDSCAPE

    Lock


    Documentation

    Lock the device for a certain period of time. iOS only.

    Long Press (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Long press the element with optional duration

    Connect Appium (String remote_url)


    Arguments

    remote_url - The URL of the appium server to use for execution. 

    Documentation

    Opens a new application to given Appium server. Capabilities of appium server,

    Page Should Contain Element (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Verifies that current page contains locator element.

    Page Should Not Contain Element (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Verifies that current page not contains locator element.

    Portrait


    Documentation

    Set the device orientation to PORTRAIT

    Quit Application


    Documentation

    Quit application. Application can be quit while Appium session is kept alive. This keyword can be used to close application during test case or between test cases.

    Reset Application


    Documentation

    Reset application. Open Application can be reset while Appium session is kept alive.

    Scroll to Element (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Scrolls to element

    Swipe (int start_x, int start_y, int offset_x, int offset_y, int duration)


    Arguments

    start_x - The start x location of the swipe.

    start_y - The start y location of the swipe.

    offset_x - The x offset to swipe

    offset_y - The y offset to swipe.

    duration - The duration of the swip in seconds.

    Documentation

    Swipe from one point to another point, for an optional duration.

    Tap (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Tap element identified by locator.

    Wait Until Element Is Visible (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Waits until element specified with locator is visible.

    Wait Until Page Contains Element (String locator)


    Arguments

    locator - The object identifier. See locator strategy above.

    Documentation

    Waits until element specified with locator appears on current page.