Wednesday, November 26, 2014

Running selenium scripts on android mobile web browser

Pre requisites:
On your mobile device navigate to Settings -> Applications, and check "Unknown Sources".
Android SDK should install and add to environment variables.
Server Computer and the mobile device should be in the same Wi-Fi network
This will help to run selenium scripts inside an android mobile web browser

Step-by-step guide

Set-up Android device
  1. Download the latest android webdriver apk file from HERE (im playing with C#).
  2. Install downloaded apk file on the android device.(adb install <file name.apk>).
  3. From the android device locate the the Webdriver application with the selenium logo.
  4. Tap on the icon to start the selenium server.
  5. From the host computer/ server open a command prompt and run type adb forward tcp:8080 tcp:8080 .
  6. Tap on enter key.
If you get any error on above command try to kill all the processors / task listening and started using port 8080.Re run the command.
We use above command to forward the ports and create a link between android device and the host computer/ server 
     7.  To check whether the server woks fine , navigate to web browser and go to below URL.(Using host computer/ server )
If the server works fine (newly created link between android device and the host computer are working file) ,User should see something like below image on the web browser.
     8.  Click on "Create Session" button and select android as on the below image.

     9.  Click on OK button.
   10.  Session should create successfully as on the bellow image.


Set-up Host computer / Server
  1. Download the latest selenium .net drivers from  HERE.
  2. Open Visual studio and create a new CodedUI project.
  3. Add all the dll files which are inside the downloaded selenium .net driver archive to the reference folder of newly created CodedUI project as on the below image.


  4. You may need add OpenQA.Selenium.Android namespace to test class file.
  5. On the test class create new AndroidDriver instance to initialise the webDriver and start writing test scripts according to the standard way.
  eg:
[TestMethod]
        public void CodedUITestMethod1()
        {
            IWebDriver driver = new AndroidDriver();
            driver.Navigate().GoToUrl("https:www.google.com");
            Assert.AreEqual(driver.Title.ToString(),"Google");
        }

No comments:

Post a Comment