Documentation - MaxGolden/MobileApp_MySprint_iOS GitHub Wiki

Sprint Mobile App Automation Test Documentation

1. Tools

    1. Appium
    1. TestNG
    1. Device / Device Simulator
    1. ALLURE
    1. MAVEN
    1. IntelliJ IDEA
    1. GITHUB
    1. Jenkins

2. MAVEN Dependencies

testng 6.14.3        (TestNG)
java-client 7.0.0    (Appium)
extentreports 2.41.2 (Extent)
allure-testng 2.12.0 (ALLURE)
log4j 1.2.17
slf4j-api 1.7.25
slf4j-simple 1.7.25
freemarker 2.3.28
zip4j 1.3.2

3. Test case scripts folder structure

Project
      - allure-results
      - testng
      - src – main – java
	  - Android_Base
	  - app
	  - Data
	  - Listeners
	  - Util
	  - SPRCOM_XXXXX

4. Common setting

4.1 Simulator settings

(1) Android

Android device simulator could be created by ANDROID STUDIO. (Video Attachment only support 28+ version of the android device system)

(2) iOS

Download and install Xcode which includes the iOS device and versions of iOS.

4.2 LISTENERS - TestNG

Use Listeners can print info of test start, finish, pass and skip to let the tester know the status of the whole testing progress.

Examples

    1. onStart
    public void onStart(ITestContext iTestContext) {
        System.out.println("LISTENER: onStart Test - " + iTestContext.getName());
    }

When the test begin, the listener will print information.

    1. onTestFailure
    public void onTestFailure(ITestResult iTestResult)
    {
        ITestContext context = iTestResult.getTestContext();
        System.out.println("LISTENER: Test failed ... " + iTestResult.getName() + " --- " + context) ;
    }

Listener will print information when test failed.

4.3 ALLURE Add Attachment

The attachments can be shown in the result page

    1. Text attachment adding
    @Attachment(value = "IMPORTANT Message", type = "text/plain")
    public static String saveTextLog_Allure(String message) {
        return message;
    }
    1. Screenshot attachment adding
    @Attachment(value = "Auto Screenshot", type = "image/png")
    public static byte[] saveScreenshotPNG_Allure(IOSDriver driver) {
        return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
    }
    1. Video attachment adding
    @Attachment(value = "Video Attachment", type = "video/mp4")
    public static byte[] saveH264_Allure_Video(String videoClip) {
        return Base64.decodeBase64(videoClip);
    }

4.4 APP file using

Put the files under the app folder for using

5. Script class methods

Project - src - main - java - Util - iOS_Driver_Methods

5.1 ELEMENT FIND - iOS

Almost all the testing cases relate to the element finding and then do the tap, scroll, typing, etc.

findElementByAccessibilityId & findElementsByAccessibilityId APPIUM iOS Driver

Find element by using the element "accessibility ID" if it has.

  • 1. Method - findByAccessibilityID_Click
    Click the element

Example:

findByAccessibilityID_Click(30, "Make a payment");

The code means it will take 30 seconds to find element with accessibility id of "Make a payment".

    1. Method - findByAccessibilityID_SendKey
      Type in the element, usually the element is text box or field

Example:

findByAccessibilityID_SendKey(30, "ZIP", "66100");

The code means it will take 30 seconds to find element with accessibility id of "ZIP" and type in "66100".

    1. Method - findByAccessibilityID_Clear
      Clear the element

Example:

findByAccessibilityID_Clear(10, "ZIP");

The code means it will take 10 seconds to find element with accessibility id of "ZIP" and empty the text field.

    1. Method - findByAccessibilityID_GetText
      Get text of the element

Example:

findByAccessibilityID_GetText(10, "ZIP");

The code means it will take 10 seconds to find element with accessibility id of "ZIP" and get the content of the element.

    1. Method - findByAccessibilityID_Enable
      Check the status of element is enable(true) or disable(false)

Example:

findByAccessibilityID_Enable(10, "Cancel");

The code means it will take 10 seconds to find element with accessibility id of "Cancel" and check the element status.

    1. Method - findByAccessibilityID_Counts
      Check how many elements with same accessibility id

Example:

findByAccessibilityID_Counts(10, "Submit");

The code means it will take 10 seconds to find elements with accessibility id of "Cancel" and check the element amount.

    1. Method - findByAccessibilityID_Exist
      Check the element existence.

Example:

findByAccessibilityID_Exist(10, "Submit");

The code means it will take 10 seconds to find element with accessibility id of "Cancel" and check the element existence.

findElementByClassName APPIUM iOS Driver

Find element by using the element "type"

    1. Method - findByClassType_Click
      Click the element

Example:

findByClassType_Click(10, "XCUIElementTypeButton");

The code means it will take 10 seconds to find and click element with type of "XCUIElementTypeButton".

    1. Method - findByClassType_SendKey
      Type in the element, usually the element is text box or field

Example:

findByClassType_SendKey(10, "XCUIElementTypeOther", "113");

The code means it will take 10 seconds to find the element with type of "XCUIElementTypeButton" and type in "113".

    1. Method - findByClassType_Clear
      Clear the element

Example:

findByClassType_Clear(10, "XCUIElementTypeOther");

The code means it will take 10 seconds to find the element with type of "XCUIElementTypeButton" and empty the text field

    1. Method - findByClassType_Exist
      Check the element existence.

Example:

findByClassType_Exist(10, "XCUIElementTypeOther");

The code means it will take 10 seconds to find the element with type of "XCUIElementTypeButton" and check the element existence.

findElementByName APPIUM iOS Driver

Find element by using the element "name"

    1. Method - findByName_Click
      Click the element

Example:

findByName_Click(10, "make a payment");

The code means it will take 10 seconds to find and click the element with name of "make a payment".

    1. Method - findByName_SendKey
      Type in the element, usually the element is text box or field

Example:

findByName_SendKey(10, "ZIP", "66100");

The code means it will take 10 seconds to find the element with name of "ZIP" and type in "66100".

    1. Method - findByName_Clear
      Clear the element

Example:

findByName_Clear(10, "ZIP");

The code means it will take 10 seconds to find the element with name of "ZIP" and empty the text field.

    1. Method - findByName_Exist
      Check the element existence.

Example:

findByName_Exist(10, "ZIP");

The code means it will take 10 seconds to find the element with name of "ZIP" and check the element existence

findElementById APPIUM iOS Driver

Find element by using the element "id"

    1. Method - findByID_Click
      Click the element

Example:

findByID_Click(10, "OK");

The code means it will take 10 seconds to find and click the element with id of "OK".

    1. Method - findByID_SendKeys
      Type in the element, usually the element is text box or field

Example:

findByID_SendKeys(10, "ZIP", "66100");

The code means it will take 10 seconds to find the element with id of "ZIP" and type in "66100".

    1. Method - findByID_Exist
      Check the element existence.

Example:

findByID_Exist(10, "ZIP");

The code means it will take 10 seconds to find the element with id of "ZIP" and check the element existence.

findElementByXPath APPIUM iOS Driver

Find element by using the element "Xpath"

    1. Method - findByValueXpath_Click
      Click the element

Example:

findByValueXpath_Click(10, "//XCUIElementTypeButton[@text=\"Make a payment\"]");

The code means it will take 10 seconds to find and click the element with Xpath of "//XCUIElementTypeButton[@text="Make a payment"]".

    1. Method - findByValueXpath_Exist
      Check the element existence.

Example:

findByValueXpath_Click(10, "//XCUIElementTypeButton[@text=\"Make a payment\"]");

The code means it will take 10 seconds to find the element with Xpath of "//XCUIElementTypeButton[@text="Make a payment"]" and check the element existence.

TouchAction APPIUM iOS Driver

Find element by using the element "Coord"

    1. Method - findByCoord_Click
      Click the element

Example:

findByCoord_Click("200", "400");

The code means it clicks point of (200, 400).

TouchAction APPIUM iOS Driver Scroll Down

    1. Method - findByPoint_ScrollDown
      Find elements by using the accessibility id and touch action or use point X, Y to scroll down and up

5.2 ELEMENT FIND - Android


List<AndroidElement> APPIUM Android Driver

Find element by using the element list based on text

  • 1. Method - findByList_IndexClick
    Click the element based on the text

Example:

findByList_IndexClick(30, "com.sprint.care.beta:id/action_btn", "add a new device");

The code means it will take 30 seconds to find elements with resource id of "com.sprint.care.beta:id/action_btn". Then match the text (lower case) "add a new device" and tap the element.

  • 2. Method - findByList_IndexClickMT3
    Click the element based on the different text posibilities

Example:

findByList_IndexClick(10, "com.sprint.care.beta:id/action_btn", "upgrade your service", "upgrade now", "early upgrade");

The code means it will take 10 seconds to find elements with resource id of "com.sprint.care.beta:id/action_btn". Then match the text (lower case) "upgrade your service" or "upgrade now" or "early upgrade". And tap the element of matching


findElementById & findElementsById APPIUM Android Driver

Find element by using the element "resource id" if it has.

  • 1. Method - findByResourceID_Click
    Click the element

Example1:

findByResourceID_Click(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find and tap the element with resource id of "com.sprint.care.beta:id/action_btn".

Example2:

findByResourceID_Click(10, "com.sprint.care.beta:id/action_btn", true, "Back server error");

The code means it will take 10 seconds to find and tap the element with resource id of "com.sprint.care.beta:id/action_btn". If element not found, the error dialog check will issue and take screenshot if there is any of them. Then let the case fail and back to the main page for next test case.

  • 2. Method - findByResourceID_SendKey
    Type in the element, usually the element is text box or field

Example:

findByResourceID_SendKey(10, "com.sprint.care.beta:id/action_btn", "Max");

The code means it will take 10 seconds to find the element with resource id of "com.sprint.care.beta:id/action_btn" and send key " Max" to it.

  • 3. Method - findByResourceID_Clear
    Clear the element

Example:

findByResourceID_Clear(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find the element with resource id of "com.sprint.care.beta:id/action_btn" and clear its field value.

  • 4. Method - findByResourceID_GetText
    Get text of the element

Example:

findByResourceID_GetText(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find the element with resource id of "com.sprint.care.beta:id/action_btn" and get the text/value

  • 5. Method - findByResourceID_Enable
    Check the status of element is enable(true) or disable(false)

Example:

findByResourceID_Enable(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find the element with resource id of "com.sprint.care.beta:id/action_btn" and check the status.

  • 6. Method - findByResourceID_Counts
    Check how many elements with same accessibility id

Example:

findByResourceID_Counts(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find the elements with resource id of "com.sprint.care.beta:id/action_btn" and check the elements amount.

  • 7. Method - findByResourceID_Exist
    Check the element existence.

Example:

findByResourceID_Exist(10, "com.sprint.care.beta:id/action_btn");

The code means it will take 10 seconds to find the element with resource id of "com.sprint.care.beta:id/action_btn" and check it exist or not.


findElementsByClassName APPIUM Android Driver

Find element by using the element "name"

  • 1. Method - findByClassType_Click
    Click the element

Example:

findByClassType_Click(10, "Make a payment");

The code means it will take 10 seconds to find and tap the element with the name of "Make a payment".


findElementByAndroidUIAutomator APPIUM iOS Driver

Find element by using the element "text"

  • 1. Method - findByAndroidUIAutomator_Click
    Click the element

Example:

findByAndroidUIAutomator_Click(10, "text(\"Settings\")");

The code means it will take 10 seconds to find and tap the element with the text of "text("Settings")" by using Android UI Automator

  • 2. Method - findByAndroidUIAutomator_Exist
    Check the element existence.

Example:

findByAndroidUIAutomator_Exist(10, "text(\"Settings\")");

The code means it will take 10 seconds to find the element with the text of "text("Settings")" by using Android UI Automator and check the existence.

  • 3. Method - findByAndroidUIAutomator_Counts
    Check how many elements with same text

Example:

findByAndroidUIAutomator_Counts(10, "text(\"Settings\")");

The code means it will take 10 seconds to find the elements with the text of "text("Settings")" by using Android UI Automator and check the elements amount.

findElementByXPath APPIUM Android Driver

Find element by using the element "Xpath"

  • 1. Method - findByValueXpath_Click
    Click the element

Example:

findByValueXpath_Click(10, "text(\"Settings\")");

The code means it will take 10 seconds to find and tap the element with the text of "text("Settings")" by using Xpath.


TouchAction APPIUM Android Driver

Find element by using the element "Coord"

  • 1. Method - findByCoord_Click
    Click the element

Example:

findByCoord_Click("200", "400");

The code means it will find and tap the spot by using coordinate of x "200" and y "400".


5.3 Assert Fail

Assert fail and back to the main for preparing the next test.

5.4 Fail Message

Show the fail message to the allure result page.

⚠️ **GitHub.com Fallback** ⚠️