无法在Selenium

时间:2016-08-19 00:37:07

标签: selenium selenium-webdriver android-emulator webdriver appium

我正在尝试在Selenium中运行Android驱动程序,但遇到了一个奇怪的错误,我不知道如何修复。我有一个正在运行的Appium Server和一个正在运行的Android模拟器(通过Android Studio),当我在命令行中运行“adb devices”时,它显示为“emulator-5554”。但是,当我尝试实际启动模拟器并在Android模拟器中打开“Chrome”时,我得到以下异常:

A new session could not be created. (Original error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device emulator-5554 is not online
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64))) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.32 seconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'

这是我的代码:

public void useAndroid(){
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","Android");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("app", "Chrome");

    try {
        URL url = new URL("http://127.0.0.1:4723/wd/hub");
        WebDriver driver = new AndroidDriver<WebElement>(url, capabilities);
    } catch(Exception e) {
        System.out.println(e);
    }

    open("http://www.google.com");
}

为什么会发生这种异常的任何想法?我做了很多搜索,我很茫然。

1 个答案:

答案 0 :(得分:0)

从日志中看,仿真器(emulator-5554)在测试执行期间似乎处于脱机模式。添加模拟器名称的功能,并等待模拟器在测试执行之前进入联机状态。

另外,不要打开使用get api -

driver.get("http://www.google.com")