如何用Selenium的AndroidDriver在Andrioid模拟器上进行自动化试
发布网友
发布时间:2022-05-13 17:19
我来回答
共2个回答
懂视网
时间:2022-05-13 21:41
利用Selenium自动化测试android wap页面:http://blogs.360.cn/360qtest/2014/04/01/%E5%88%A9%E7%94%A8selenium%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95android-wap%E9%A1%B5/
热心网友
时间:2022-05-13 18:49
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: 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(); } }