setValue and sendKeys throw error to set a text in EditText with Appium and Android

97 views
Skip to first unread message

Ana

unread,
Feb 23, 2017, 2:38:24 PM2/23/17
to appium-developers

What I try to do in order to test my LoginActivity is to set a text in the email Edittext using Appium and Android Studio.

My 1st version of the test included a WebDriver and a Webelementfor the EditText, so i used sendKeys() to set the text.

This is the code:

    
WebDriver driver;
   
   @Before
   public void testApp() throws MalformedURLException, InterruptedException {
       String apkpath = "C:\\Users\\0013498\\Desktop\\qa-XXX-2-2-4-2.apk";
       File app = new File(apkpath);
       DesiredCapabilities capabilities= new DesiredCapabilities();
       capabilities.setCapability(CapabilityType.BROWSER_NAME,"Android");
       capabilities.setCapability("deviceName","Emulator");
       capabilities.setCapability("platformName","Android");
       capabilities.setCapability("app",app.getAbsolutePath());
       capabilities.setCapability("appPackage", "com.XXX.XXX");
       capabilities.setCapability("appActivity", "com.XXX.XXX.SplashScreenActivity");
       driver = new AppiumDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);
       driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    }

   
   @Test
   public void appiumExampleTest() throws Exception {
   String path="//android.widget.EditText[contains(@resource-id,\"email\")]";
       click(path);
       elementSendText(path, "@");
   }
   public void click(String element) {
       WebElement webElement = driver.findElement(By.xpath(element));
       webElement.click();
       System.out.println("Click element: "+element+" index = "+0);

    }


    public void elementSendText(String element,  String text) {
       WebElement webElement = driver.findElement(By.xpath(element));
       webElement.sendKeys(text);

    }



this is the screenshot from UI Automator Viewer for the LoginActivity where the email EditText is :




BUT sendKeys() throws the following error:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.




So, after some digging, i changed my code to start using AndroidDriver and AndroidElement like this:

   
 AndroidDriver driver;
   @Before
   public void testApp() throws MalformedURLException, InterruptedException {
       String apkpath = "C:\\Users\\0013498\\Desktop\\qa-XXX-2-2-4-2.apk";
       File app = new File(apkpath);
       DesiredCapabilities capabilities= new DesiredCapabilities();
       capabilities.setCapability(CapabilityType.BROWSER_NAME,"Android");
       capabilities.setCapability("deviceName","Emulator");
       capabilities.setCapability("platformName","Android");
       capabilities.setCapability("app",app.getAbsolutePath());
       capabilities.setCapability("appPackage", "com.XXX.XXX");
       capabilities.setCapability("appActivity", "com.XXX.XXX.SplashScreenActivity");      
        driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),capabilities);//<----
       driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    }
   @Test
   public void appiumExampleTest() throws Exception {
   AndroidElement emailET= (AndroidElement)driver.findElementById("com.XXX.XXX:id/email");//<----
       emailET.click();//<----
       emailET.setValue("@");
   }


and now, setValue() throws the following error:

    
org.openqa.selenium.WebDriverException: Not yet implemented.


And honestly, I don't know how to move forward, i'm so stuck here. This can't be that difficult, what am i missing?

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages