There are several steps required to prepare the android device or emulator, the environment and the computer. These include: · Installing android-server.apk (the actual filename may differ e.g. if you use a prebuilt version it will include the release name). If you want to use an emulator, we currently recommend using one with Android 2.2 installed. The server doesn’t support earlier versions any more (it used to but limitations with the platform e.g. lack of support for XPath meant the project team have chosen to target a minimum of 2.2). There’s currently an issue with the Java-to-JavaScript bridge in version 2.3 of the emulator, so again we don’t recommend using it currently.) · Configuring port forwarding so your tests can communicate with the device or running instance of the emulator. · Starting the WebDriver Server on the Android emulator (or on a device). Configuring your eclipse project You will need to include the various jar files from the selenium project in order for your tests to use ‘RemoteWebdriver’. The AndroidDriver implements the RemoteWebdriver protocol. You can download a zip file from the selenium project site http://code.google.com/p/selenium/downloads/list e.g. selenium-java-2.0b1.zip currently. This file needs to be unzipped, which will unpack to 2 selenium jar files (the code and the javadoc documentation) and a series of 27 other jar files. All these files need to be added to the build path in your eclipse project. I suggest copying all the files into a common libs folder for your project. First, let's create an Android Virtual Device (AVD): $cd ~/android_sdk/tools/ $./android create avd -n my_android -t 12 -c 100M -n: specifies the name of the AVD. -t: specifies the platform target. For an exhaustive list of targets, run: ./android list targets Make sure the target level you selected corresponds to a supported SDK platform. -c: specifies the SD card storage space. When prompted "Do you wish to create a custom hardware profile [no]" enter "no". Now, start the emulator. This can take a while, but take a look at the FAQ below for tips on how to improve performance of the emulator. $./emulator -avd my_android & Install the WebDriver APKEvery device or emulator has a serial ID. Run this command to get the serial ID of the device or emulator you want to use: $~/android_sdk/platform-tools/adb devices Download the Android server from selenium download page To install the application do: $./adb -s <serialId> -e install -r android-server.apk Make sure you are allowing installation of application not coming from Android Market. Go to Settings -> Applications, and check "Unknown Sources". Start the Android WebDriver application through the UI of the device or by running this command: $./adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity You can start the application in debug mode, which has more verbose logs by doing: $./adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity -e debug true Sample Code: just put that inside a class and check the magic, Run the Testsimport junit.framework.TestCase; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.android.AndroidDriver; public class OneTest extends TestCase { public void testGoogle() throws Exception { WebDriver driver = new AndroidDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } }
still confused ??? haha. Really no problem. Check my video tutorial on android webdriver. You will have your all questions answer.
40 Comments
Mark
8/24/2011 04:12:25 pm
very useful. thank you man !!
Reply
9/11/2012 04:30:49 pm
I enjoyed reading you post. I am sharing it with my other friends as the information is really very useful. Keep sharing your excellent work.
Reply
lita
8/24/2011 04:32:09 pm
Your video is cool!
Reply
Tuan
8/24/2011 04:58:22 pm
thank you !!!
Reply
8/25/2011 05:47:13 pm
I want to learn but i dont know anything about Android's application. But Dev in my Company is doing that.
Reply
Masud
8/25/2011 06:36:39 pm
@hung: to learn / do this testing you don't need to be an android developer. if you have a basic knowledge on OOP and any IDE knowledge then u can learn it.
Reply
Mark
8/25/2011 06:38:48 pm
hay dude i got a problem. i don't have any error in my coding and i did all you said here. But i am always having error message in console. why this is happening?
Reply
Anh
8/25/2011 06:39:26 pm
This is interesting. I will try to do it.
Reply
Masud
8/25/2011 06:58:30 pm
@Mark: i think you forgot to forward the port to 8080
Reply
Khan
8/27/2011 08:55:32 pm
Hi, I'm using latest selenium version (2.3.1) and I encountered an issue when attempting to click on something (both using selenium or webdriver). As a device I'm using Android SDK with emulator of Android 2.3.1 (API level 9). Below is the stack trace: com.thoughtworks.selenium.SeleniumException?: java.net.SocketException?: Connection reset Build info: version: '2.3.1', revision: 'unknown', time: '2011-08-04 07:30:11' System info: os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24' Driver info: driver.version: RemoteWebDriver
Reply
Nguyen
8/27/2011 08:56:36 pm
This is just awesome man. But i can not install the webdriver in my emulator. how can i do it?
Reply
Matt
8/27/2011 09:03:55 pm
Using Selenium 2.0 and the last version of android driver I am not able to select options from select control. I've tried both: WebElement? select = driver.findElement(By.id("....."));
Reply
Masud
8/28/2011 04:34:10 pm
@Khan: from your trace i think, you did not put the selenium server in the build path. plz but that in the whole project's build path. make sure you are using the latest version too. Some old versions have some issue on this operation.
Reply
Masud
8/28/2011 04:42:32 pm
@Nguyen: just make sure you have added your android home in environment variables and then move to tools found and run
Reply
Masud
8/28/2011 05:16:21 pm
@Matt: install the webdriver.apk properly in device and then forward the port to 8080.
Reply
harish
8/28/2011 07:38:09 pm
Its Really Interesting!!! :)
Reply
Masud
8/28/2011 07:39:34 pm
@Harish: Thank you Harish !
Reply
Jimy
8/29/2011 07:48:23 pm
xpath , name or id? which one is more helpful?
Reply
Masud
10/13/2011 04:25:04 pm
@Jimy: ofcourse id. when there is no way then try with xpath. surely xpath have some issue with android.
Reply
Lorry
10/16/2011 05:44:34 pm
Do I have to modify any other permission issue?
Reply
An
10/16/2011 07:27:03 pm
is there any way to make the emulator faster?
Reply
Masud
10/17/2011 01:09:51 pm
@Lorry: that is enough my friend
Reply
anh
11/9/2011 03:28:35 pm
Masud would you please share me your updated slides which you presented on MDC 2011?
Reply
Masud
11/16/2011 12:33:47 pm
@Anh: soon I will add that slide. keep in touch !
Reply
adrian
3/11/2012 06:54:34 am
Hi,
Reply
Masud
3/11/2012 12:18:54 pm
Check the following things
Reply
adrian
3/13/2012 04:35:57 am
Thanks. But I'm trying to test it on my device with Android 2.3 not on an emulator. Do you know if it works on the device ?
Masud
3/13/2012 11:43:06 am
Sure it works well in device too.
ram
5/28/2012 03:34:03 pm
I have 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.
Reply
Masud
5/28/2012 08:01:33 pm
Tell me about your set up and configuration. did you forward the port ?
Reply
ram
5/28/2012 09:55:50 pm
I am running the code in eclipse ide as a junit test, and I have forwarded the port also, It is working well until the google.com page load. After the page load after that the error shows.
Masud
6/20/2012 06:34:08 pm
Try with the latest version. with some old version I also faced the same problem . plus try with the 2.2 emulator as well.
Ashrafunissa
6/20/2012 05:59:43 pm
hello sir: will u please send ur testcase application so that i will import it and run it. the one in which u tested google home page
Reply
Masud
6/20/2012 06:36:56 pm
well. This is not going to work for your until you set up the complete set up. just importing will not help you. follow the steps as I told in the tutorial. for test case u can use this code as well:
Reply
Ashrafunissa
6/20/2012 07:24:33 pm
sir i have followed your all steps then when i run the program . first sentence it was showing on console is
Reply
Ashrafunissa
6/20/2012 07:28:10 pm
Then after 5 sec it was showing an alert box which was showing error "Java heap space " error.
Reply
Masud
6/20/2012 08:22:10 pm
Sounds you are in a conic problem. This is fine. In the beginning if you face so many problems then u will know a lot of cases as well.
Reply
Hey i installed webdriver in emulator nd what my doubt exactly is we have to create new android project or java project to paste that sample code???
Reply
masud
11/24/2012 11:18:57 pm
Thanks for your question. Just make a java project. that will work fine for you. :)
Reply
lakshman
8/14/2013 11:07:30 pm
Hi mausd,
Reply
Leave a Reply. |
AuthorI am Masud Parvez. Working as IT Senior Project Manager for RMIT University. Previously I built and run a distributed Test Center. My success was to turn that in to one of the most successful business units of the company. Categories
All
|