Integrating Custom Appium Code & Scriptless

You are here:
< All Topics

Appium Custom Scripts

  • Click on Add Custom Script
  • Below the Popup box will appear on the screen.

 

 

  • Add a Test Case Name and Description.
  • Add your scripts on Custom Script.
  • Click on Save.

 

Actions

Call Custom Script

 

  • This action is for Android, iOS, and Web.
  • This action is used to call the custom script that you created in a custom script section.

 

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
WebElement ele1 =(WebElement)driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(2);
WebElement ele2 =(WebElement)driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(5);
TouchAction action = new TouchAction((MobileDriver) driver);
action.longPress(ele1).moveTo(ele2).release().perform();
System.out.println("It Is dragging element.");

 

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
MobileElement signInButton = driver.findElement(By.xpath("//XCUIElementTypeButton[@name=’Start updating’]"));
signInButton.click();
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.");

 

As simple as that! Happy Testing 😇

Table of Contents