Skip to main content

Integrating Appium Custom Scripts with Codeless Automation

Appium Custom Scripts

  • Open an existing test case or open a new test case in the codeless generator.
  • Select custom expression and add your Java snippet code there.

Android Appium Custom Script:

  • For Android, we can write custom scripts in Java using the Appium framework.
  • We can use the “driver” object to access all methods of the WebDriver class.
  • Following are some examples:

Sample 1

MobileElement passwordEditText = driver.findElement(By.xpath("//android.widget.EditText[@text='Password']"));
passwordEditText.sendKeys("test@123");

Sample 2

MobileElement signInButton = driver.findElement(By.xpath("//android.widget.Button[@text='Sign In']"));
signInButton.click();

Sample 3

try {
      HashMap<String, Object> args = new HashMap<>();
                args.put("action", "accept");     // accept = click Allow
                args.put("buttonLabel", "Allow");
                driver.executeScript("mobile: alert", args);
                System.out.println("Clicked Allow alert button");
     } catch (Exception e) {
            throw new RuntimeException("Unable to click Allow button", e);
}

iOS Appium Custom Script

  • For iOS we can write custom scripts in Java using the Appium framework.
  • We can use the “driver” object to access all methods of the WebDriver class.
  • Following are some examples:

Sample 1

MobileElement passwordEditText = driver.findElement(By.xpath("//XCUIElementTypeTextView[@name=’LocationTextView’]"));
passwordEditText.sendKeys("test@123");

Sample 2

JavascriptExecutor js = (JavascriptExecutor) driver;
          HashMap<String, Object> swipeObject = new HashMap<>();
          swipeObject.put("direction", "up");
          js.executeScript("mobile: swipe", swipeObject);

Sample 3

WebElement ele1 = (WebElement) driver.findElementByAccessibilityId("drag_handle1"); 
WebElement ele2 = (WebElement) driver.findElementByAccessibilityId("drag_handle2");
TouchAction action = new TouchAction((MobileDriver) driver);  
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("It Is dragging element."

 

Table of Contents