I'm using the following code to run a simple test. The same code is working sometimes and returning error sometimes. The error it will return is "Not able to find UI Element".
This is my code:
package example;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import java.net.URL;
public class CalculatorTest {
AppiumDriver<WebElement> driver;
@BeforeClass
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("app", "C:/Users/rraghunath/Downloads/Apk/Calculator_com.google.android.calculator.apk");
capabilities.setCapability("appPackage", "com.google.android.calculator");
capabilities.setCapability("appActivity", "com.android.calculator2.CalculatorGoogle");
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
/**
* Test for Calculator
*/
@Test
public void test_CalculatorTest(){
driver.findElement(By.id("digit_1")).click();
driver.findElement(By.id("digit_0")).click();
driver.findElement(By.id("digit_1")).click();
driver.findElement(By.id("del")).click();
driver.findElement(By.id("del")).click();
driver.findElement(By.id("del")).click();
driver.findElement(By.id("digit_1")).click();
driver.findElement(By.id("dec_point")).click();
driver.findElement(By.id("digit_0")).click();
driver.findElement(By.id("digit_2")).click();
driver.findElement(By.id("digit_3")).click();
driver.findElement(By.id("op_mul")).click();
driver.findElement(By.id("digit_3")).click();
driver.findElement(By.id("dec_point")).click();
driver.findElement(By.id("digit_0")).click();
driver.findElement(By.id("digit_1")).click();
driver.findElement(By.id("digit_2")).click();
driver.findElement(By.id("eq")).click();
}
}