Road to setup Selendroid and create first test script of android application

About Selendroid:  Selendroid is an open source automation framework which drives of UI of android native, hybrid and mobile web application. It supports both emulator and real device. It uses Json Wire Protocol to run webdriver test scripts on device. It can be integrated with selenium grid for parallel execution on multiple nodes. No need any modification in application and not need source code to automate application.

Prerequisites:
  • JDK should be installed and java home path setup in your machine.
  • Android SDK should be installed on your machine and android path should be setup in your machine
  • Download Selendroid from link: Download
  • Selenium jar file from: Download
  • Eclipse.
  • Create new Emulator or attached real devices with you machine.
Run Server: open command prompt and go to downloaded Selendroid jar file and run below command
>>java -jar selendroid-standalone-0.*.0-with-dependencies.jar -aut {Application APK file}

Like below command:

>>java -jar selendroid-standalone-0.9.0-with-dependencies.jar -aut resigned-selendroid-test-app-0.9.0.apk

Where selendroid-standalone-0.9.0-with-dependencies.jar is downloaded selendroid jar file and resigned-selendroid-test-app-0.9.0.apk application apk file name, you can download this sample application from link: Download

Check server status: launch browser and open url http://localhost:4444/wd/hub/status you should see your url like below screen:


Step to create test script:
  1. Create a java project in eclipse.
  2. Add selenium and selendroid jar file in eclipse environments:
  3. Create package “com.test“ and add java file “SelendroidTest.java” with below code:
package com.test;

import io.selendroid.SelendroidCapabilities;
import io.selendroid.SelendroidConfiguration;
import io.selendroid.SelendroidDriver;
import io.selendroid.SelendroidLauncher;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class SelendroidTest {
 
 private WebDriver driver ;
 
 @BeforeSuite
 public void setUp() throws Exception
 {  
      SelendroidConfiguration config = new SelendroidConfiguration();
     config.addSupportedApp("selendroid-test-app-0.9.0.apk");
     SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
     selendroidServer.lauchSelendroid();

     SelendroidCapabilities caps = new SelendroidCapabilities("io.selendroid.testapp:0.9.0");
     driver = new SelendroidDriver(caps);
 }

 @Test
 public void selendroidTest() throws Exception
 {  
  WebElement inputField = driver.findElement(By.id("my_text_field"));
  Assert.assertEquals("true", inputField.getAttribute("enabled"));
  inputField.sendKeys("Selendroid");

  Assert.assertEquals("Selendroid", inputField.getText());
  
  //click EN butoon
  WebElement button = driver.findElement(By.id("buttonTest"));  
  button.click();
  
  //click accept button
  button = driver.findElement(By.id("button2"));  
  button.click();
  
  Thread.sleep(5000);
  //click on registration button
  button = driver.findElement(By.id("startUserRegistration"));  
  button.click();
  
  Thread.sleep(10000);
  // fill registration form data
  WebElement element = driver.findElement(By.id("label_username"));
  String text = element.getText();
  System.out.println(text);
  element = driver.findElement(By.id("inputUsername"));
  element.sendKeys("bob");
  
  element = driver.findElement(By.id("inputEmail"));
  element.sendKeys("test@gmail.com");
  
  element = driver.findElement(By.id("inputPassword"));
  element.clear();
  element.sendKeys("test1233");
  
  element = driver.findElement(By.id("inputName"));
  element.clear();
  element.sendKeys("My Name ");
  
  element = driver.findElement(By.id("input_preferedProgrammingLanguage"));
  element.click();
  
  element = driver.findElement(By.id("text1"));
  element.click();
  
  element = driver.findElement(By.id("input_adds"));
  element.click();
  
  element = driver.findElement(By.id("btnRegisterUser"));
  element.click();
  
  element = driver.findElement(By.id("buttonRegisterUser"));
  element.click();  
 }
 
 @AfterSuite
 public void tearDown(){
        driver.quit();
 }
} 
I have created a test script using TestNG for the registration scenario of android application provided by selendroid. In next post I will show you how to get android application element details.

26 comments:

  1. 1. Can we automate web apps with out having apk file?
    2. What is need of downloading selenium jar again as selendroid has apis. Please correct me if I'm wrong

    ReplyDelete
    Replies
    1. Yes you can automate webapplication without having apk file.

      Go through my post: http://roadtoautomation.blogspot.in/2013/06/road-to-setup-and-execute-webdriver.html

      Delete
  2. Hello,

    I need to run my selenium webdriver cases on android real device using selendroid.
    1. Do u need an apk file to run on browsers like chrome or native mobile browser on real device?
    2.Can you please guide me on how to start the server and execute a simple test on android real device?

    Thanks,
    Shamili

    ReplyDelete
  3. Hi All,

    I am new to Selendroid. Can you provide list of links to get download jar files
    I have downloaded Selendroid jar file(To run the Selendriod Server) and Selenium jar files(2.42). But I am not able to access methods as you mentioned as:
    SelendroidConfiguration config = new SelendroidConfiguration();
    config.addSupportedApp("selendroid-test-app-0.9.0.apk");
    SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
    selendroidServer.lauchSelendroid();

    SelendroidCapabilities caps = new SelendroidCapabilities("io.selendroid.testapp:0.9.0");
    driver = new SelendroidDriver(caps);

    Where I have gone wrong or missing something

    Regards,
    -- Panikera

    ReplyDelete
  4. I am executing the same code in TestNG, but its showing test run 0.

    ReplyDelete
    Replies
    1. I think you are not using import TesgNg annotation class, might be imported Junit Test Calss

      Delete
    2. Thanks Admin for reply. Problem has been resolved, by your suggestion.

      Delete
  5. Hi All,

    I am new in Selendroid.I am getting following error for following code.I have installed all the prerequisites but still get an error

    Code: SelendroidConfiguration config = new SelendroidConfiguration();
    config.addSupportedApp("selendroid-test-app-0.9.0.apk");
    SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
    selendroidServer.launchSelendroid();

    SelendroidCapabilities caps = new SelendroidCapabilities("io.selendroid.testapp:0.9.0");
    driver = new SelendroidDriver(caps);

    Error: The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

    If any one help me !! It's Urgent

    Thanks in advance

    Regards,
    Gunjan.

    ReplyDelete
    Replies
    1. this is not the code to start the application

      Delete
  6. Hi All,

    I am new in Selendroid. I am getting "io.selendroid.exceptions.NoSuchElementException: Element was not found." when run Test selenium If any one please help me to solve this error.


    Thanks in Advance!!!

    Regards,
    Gunjan

    ReplyDelete
    Replies
    1. I would like to suggest you to use appium instead of selendroid.
      Also NoSuchElementException error means element is not present on page.

      Delete
    2. Element ID is changed. So, re-inspect the element and run.

      Delete
    3. While u inspecting the element.you should be carefull with spelling mistakes.

      example 1. If the element ID is "True" and if u write "true" in ur scripting it will show the error Element was not found.

      Delete
    4. Element ID is changed. So, re-inspect the element and run.

      Delete
  7. Hi All,

    I am getting error 'The requested application under test is not configured in selendroid server.' Please help me to solve this.It's urgent..............

    Thanks in Advance

    ReplyDelete
    Replies
    1. can u briefly explain where your getting error.

      Delete
    2. when you get this error. can you copy what ever is there in the console. So, that i can clear your doubt. Did u get any error like java.lang.Thread.run(Thread.java:745)

      Delete
    3. did u install java development tool

      Delete
  8. hi all,
    I am new to Selendroid and trying to execute scripts on emulator. I am getting "org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
    please give the solution for the same.

    ReplyDelete
  9. hi all,
    I am new to Selendroid and trying to execute scripts on emulator. I am getting "org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
    please give the solution for the same.

    ReplyDelete
  10. I can use this example to test a native application on android?

    Can you give me an example in that is testing native app, please?

    ReplyDelete
  11. Dear Team, can some help me in understand certain basic concept of it.
    1. Do we have to app installed on phone ?
    2. Why do we add app details while starting server?
    3 Your sample code is really great, but you didn explain how did you identified the properties of each element . How did you inspect on elements? . Please explain on that.

    ReplyDelete
  12. Hi,

    I am trying to run this script:
    package Mytest;

    import io.selendroid.SelendroidDriver;
    import io.selendroid.common.SelendroidCapabilities;
    import io.selendroid.standalone.SelendroidConfiguration;
    import io.selendroid.standalone.SelendroidLauncher;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.testng.annotations.BeforeSuite;


    //@SuppressWarnings("unused")
    public class Guru99 {

    public WebDriver driver;

    @BeforeSuite
    public void setup() throws Exception{
    try{
    SelendroidConfiguration config = new SelendroidConfiguration();
    config.addSupportedApp("com.facebook.katana_18971694.apk");
    SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
    selendroidServer.launchSelendroid();

    SelendroidCapabilities caps = new SelendroidCapabilities("com.facebook.katana:58.0.0.28.70");
    driver = new SelendroidDriver(caps);
    }
    catch (Exception e)
    {
    }
    }


    //@Test
    //public void selenTest() throws Exception {
    WebElement element1 = driver.findElement(By.xpath(""));
    WebElement element2 = driver.findElement(By.xpath(""));
    WebElement element3 = driver.findElement(By.xpath(""));
    //}
    //@AfterSuite
    //public void tearDown() {
    // driver.quit();
    //}

    }

    But getting these errors:
    org.testng.TestNGException:
    Cannot find class in classpath: Mytest.Guru99
    at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
    at org.testng.xml.XmlClass.init(XmlClass.java:73)
    at org.testng.xml.XmlClass.(XmlClass.java:59)
    at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:543)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
    at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
    at org.testng.xml.Parser.parse(Parser.java:172)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:92)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:207)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:178)


    Please somebody assist me.

    ReplyDelete
  13. 04:39:53 E/DeviceMonitor: Adb connection Error:EOF
    Jul 27, 2016 4:39:53 PM io.selendroid.standalone.server.model.DeviceStore release
    INFO: Releasing device HardwareDevice [serial=c39c3626, model=GT-S7562, targetVersion=ANDROID15, apiTargetType=google]
    Jul 27, 2016 4:39:53 PM io.selendroid.standalone.server.model.DeviceStore removeAndroidDevice
    INFO: Removing: HardwareDevice [serial=c39c3626, model=GT-S7562, targetVersion=ANDROID15, apiTargetType=google]
    04:39:53 E/DeviceMonitor: Connection attempts: 1
    04:39:54 E/DeviceMonitor: Connection attempts: 2
    04:39:55 E/DeviceMonitor: Connection attempts: 3
    04:39:56 E/DeviceMonitor: Connection attempts: 4
    04:39:57 E/DeviceMonitor: Connection attempts: 5
    04:39:58 E/DeviceMonitor: Connection attempts: 6
    04:39:59 E/DeviceMonitor: Connection attempts: 7
    04:40:00 E/DeviceMonitor: Connection attempts: 8
    04:40:01 E/DeviceMonitor: Connection attempts: 9
    04:40:02 E/DeviceMonitor: Connection attempts: 10
    04:40:03 E/DeviceMonitor: Connection attempts: 11
    Jul 27, 2016 4:40:07 PM io.selendroid.standalone.io.ShellCommand exec
    INFO: Executing shell command: /home/ashwini/Android/Sdk/platform-tools/adb -s c39c3626 shell ls /system/framework/*map*
    Jul 27, 2016 4:40:07 PM io.selendroid.standalone.io.ShellCommand exec
    INFO: Shell command output
    -->

    ReplyDelete
  14. I am getting this error
    Please give me solution

    04:39:53 E/DeviceMonitor: Adb connection Error:EOF
    Jul 27, 2016 4:39:53 PM io.selendroid.standalone.server.model.DeviceStore release
    INFO: Releasing device HardwareDevice [serial=c39c3626, model=GT-S7562, targetVersion=ANDROID15, apiTargetType=google]
    Jul 27, 2016 4:39:53 PM io.selendroid.standalone.server.model.DeviceStore removeAndroidDevice
    INFO: Removing: HardwareDevice [serial=c39c3626, model=GT-S7562, targetVersion=ANDROID15, apiTargetType=google]
    04:39:53 E/DeviceMonitor: Connection attempts: 1
    04:39:54 E/DeviceMonitor: Connection attempts: 2
    04:39:55 E/DeviceMonitor: Connection attempts: 3
    04:39:56 E/DeviceMonitor: Connection attempts: 4
    04:39:57 E/DeviceMonitor: Connection attempts: 5
    04:39:58 E/DeviceMonitor: Connection attempts: 6
    04:39:59 E/DeviceMonitor: Connection attempts: 7
    04:40:00 E/DeviceMonitor: Connection attempts: 8
    04:40:01 E/DeviceMonitor: Connection attempts: 9
    04:40:02 E/DeviceMonitor: Connection attempts: 10
    04:40:03 E/DeviceMonitor: Connection attempts: 11
    Jul 27, 2016 4:40:07 PM io.selendroid.standalone.io.ShellCommand exec
    INFO: Executing shell command: /home/ashwini/Android/Sdk/platform-tools/adb -s c39c3626 shell ls /system/framework/*map*
    Jul 27, 2016 4:40:07 PM io.selendroid.standalone.io.ShellCommand exec
    INFO: Shell command output
    -->

    ReplyDelete
  15. Hey
    Have any method to find out the element id or text field of android app in selendroid if i debug the unknown app.

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution