如何用Selenium的AndroidDriver在Andrioid模拟器上进行自动化试
发布网友
发布时间:2022-05-15 23:05
我来回答
共1个回答
热心网友
时间:2024-02-28 21:09
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(); } }