如何使用Robot Framework和Appium在模拟器上打开浏览器

时间:2018-01-07 16:20:03

标签: selenium-webdriver appium robotframework

我正在尝试配置Robot Framework以在Android模拟器中打开Chrome浏览器。我有这个代码来做到这一点:

*** Settings ***
Suite Setup       Set Library Search Order    SeleniumLibrary
Test Setup        Open page
Test Teardown     Close Page
Library           SeleniumLibrary
Library           Collections
Library           requests
Library           AppiumLibrary

*** Test Cases ***
Test_case_sample
    Go To    https://www.google.com
    Sleep    10s

*** Keywords ***
Open Page
    ${desired_capabilities}=    Create Dictionary
    Set to Dictionary    ${desired_capabilities}    deviceName    Demo_6_Inch
    # Set to Dictionary    ${desired_capabilities}    build    test_run
    Set to Dictionary    ${desired_capabilities}    platformName    Android
    Set to Dictionary    ${desired_capabilities}    name    test_case_Sample
    Set to Dictionary    ${desired_capabilities}    platformVersion    8.0
    Set to Dictionary    ${desired_capabilities}    deviceOrientation    portrait
    Set to Dictionary    ${desired_capabilities}    browserName    Chrome
    Set to Dictionary    ${desired_capabilities}    appiumVersion    1.7.1
    Set to Dictionary    ${desired_capabilities}    deviceType    phone
    Create Webdriver    Remote    desired_capabilities=${desired_capabilities}

Close Page
    Close All Applications

运行脚本时,出现以下错误:

  

11:10:3​​9.547 INFO创建Remote WebDriver的实例   11:10:40.548 INFO无法连接到主机127.0.0.1上的端口4444   11:10:40.548 INFO无法获取主机的IP地址:127.0.0.1
  11:10:41.561 FAIL URLError:urlopen错误[Errno 10061]无连接   可以制作,因为目标机器主动拒绝它

我在localhost:4444启动了selenium webdriver的实例。但这一次我收到了这个错误:

  

WebDriverException:消息:转发新会话时出错   用于设置功能的VM池{appiumVersion:1.7.1,browserName:   Chrome,deviceName:Demo_6_Inch,deviceOrientation:portrait,   deviceType:phone,name:test_case_Sample,platformName:android,   platformVersion:8.0} Stacktrace:       在org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:117)       在org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:84)       在org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:68)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)       在org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:841)       在org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)       在org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)       在org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(Sessio ......       [超出限制的邮件内容已被删除。 ]       在org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)       在org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)       在org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)       在org.seleniumhq.jetty9.server.Server.handle(Server.java:561)       在org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:334)       在org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251)       在org.seleniumhq.jetty9.io.AbstractConnection $ ReadCallback.succeeded   (AbstractConnection.java:279)       在org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:104)       在org.seleniumhq.jetty9.io.ChannelEndPoint $ 2.run(ChannelEndPoint.java:124)       在org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)       在org.seleniumhq.jetty9.util.thread.QueuedThreadPool $ 2.run(QueuedThreadPool.java:597)

     

at java.lang.Thread.run(: - 1)

我如何克服这个并运行模拟器?

感谢您提出解决此问题的建议

1 个答案:

答案 0 :(得分:2)

终于找到了简单的解决方案:

*** Settings ***
Library           SeleniumLibrary
Library           Collections

*** Variables ***

*** Test Cases ***
AndroidConnection
    ${Options}    Create Dictionary    androidPackage    com.android.chrome
    ${caps}    Create Dictionary    chromeOptions    ${Options}
    Set to Dictionary    ${caps}    platformName    Android
    Set to Dictionary    ${caps}    platformVersion    8.0
    Set To Dictionary    ${caps}    deviceName    emulator-5554
    Set To Dictionary    ${caps}    browserName    Chrome
    Create Webdriver    Remote    command_executor=http://localhost:4723/wd/hub    desired_capabilities=${caps}
    go to    http://www.google.com
    Close Browser