Search Here!

Tuesday, April 24, 2012

Selenium Android Testing : Using the remote WebDriver server in C#

Following are the steps to setup environment : ANDROID TESTING using c#
1. Install SDK and install 4.0.3 Android API's.


2. Install AVD Manager and create AVD using 4.0.3 Android API'.


3. Start AVD by clicking on Start button and launch virtual device.



4. Open command prompt and browse the path of SDK directory under platform-tools folder to run the adb commands for example I had set the path D:\android-sdk-windows\platform-tools


5. Every device or emulator has a serial ID. Run this command to get the serial ID of the device or emulator you want to use and check whether to check the active state:
> adb devices


6. Download the Android server apk file 'android-server-2.0b3-patched2.apk' from http://code.google.com/p/selenium/downloads/list. To install the application do:
> adb -s emulator-5554 -e install -r D:\android-sdk-windows\platform-tools\android-server-2.0b3-patched2.apk



7. Start the Android WebDriver application through the UI of the device, click on WebDriver link button,


or by running this command: 

> adb -s emulator-5554 shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity


 

and confirm Jetty Server started, if this confirmation fails on the emulator UI then run these commands,
> adb kill-server

> adb start-server
then re-start from step 3 again till then you would not get confirmation.



8. Now we need to setup the port forwarding in order to forward traffic from the host machine to the emulator. In a terminal type:
> adb forward tcp:8080 tcp:8080



 9. Start Selenium Server on the machine :
> java -jar selenium-server-standalone-2.0b2.jar -proxyInjectionMode -trustAllSSLCertificates -log selenium.log


10. Now, execute the C# code for this built setup:

[TestClass] 

public class AndroidApp 
{
private IWebDriver WebDriver; 


[TestInitialize] 
public void TestInitializeAttribute() 

try 

WebDriver = new AndroidDriver(); 
WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30)); WebDriver.Manage().Cookies.DeleteAllCookies(); WebDriver.Navigate().GoToUrl("http://google.co.in");
} catch (Exception) { throw; } }


Now, you have done successfully and ready to start testing:)
 

Note: Always use the correct version of Android API with *.apk file.

6 comments:

  1. This is really nice, helps a lot.

    ReplyDelete
  2. Hey, Very Helpful Post :)

    ReplyDelete
  3. Thanks for posting this artcile ..i believe it is the only one on the web which talk about android browser automation using C#..

    I have one problem , which DLL or namespace AndroidDriver is referenced? I am getting (the type or namespace AndroidDriver couldn't be found)

    ReplyDelete
  4. what was the purpose of starting the selenium-server-standalone-2.0b2.jar i do not see anything on the code using the selenium server.

    ReplyDelete
  5. Hi, thank you for the tutorial, but i have a problem with Jetty on Step 7, jetty connect on 5037 port but doesn't appears on emulator no matter how i try repeat from 3. step

    ReplyDelete