How to run automation on Android emulator
1. Setup Android emulator
a. Download the Android SDK
http://developer.android.com/sdk/index.html
Note that there is an emulator bug on Gingerbread((2.3.x) that might cause WebDriver to crash. My testing is on Ice Cream Sandwich (4.0.x)
b. Install Android SDK:
http://developer.android.com/sdk/installing.html
c. Start Android SDK Manager (SDK Manager.exe)
d. Select and install Package online
e. Start AVD Manager.exe
f. Create an emulator
2. Install the AndroidDriver APK by using platform-tools
a. list divce name:
adb devices
b. download AndroidDriver APK:
http://code.google.com/p/selenium/downloads/list
c. install AndroidDriver APK:
adb -s emulator-5554 -e install -r c:\android-server-2.21.0.apk
d. start the Android WebDriver application
adb -s emulator-5554 shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
e. setup the port forwarding in order to forward traffic from the host machine to the emulator
adb -s emulator-5554 forward tcp:8080 tcp:8080
3. Create test case and running:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import 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(); } } |
声明: 本文由( 乐测网 )原创编译,转载请保留链接: 如何用Selenium的AndroidDriver在Andrioid模拟器上进行Web自动化测试
-----==== 本站公告 ====-----
1.本站是目前唯一能支持智能手机平板电脑访问的软件测试技术网站.
2.具体访问方法请参考本站的手机访问说明,或直接点击以下链接:
→点击这里打开手机平板访问说明←