【问题标题】:Robot Framework - How to connect to Amazon Device Farm机器人框架 - 如何连接到 Amazon Device Farm
【发布时间】:2017-11-02 21:49:11
【问题描述】:

目前亚马逊设备场不支持带有 Appium 的机器人框架。是否有解决方法或工具可以让我在亚马逊设备场上运行我的机器人脚本?

【问题讨论】:

    标签: mobile appium robotframework aws-device-farm


    【解决方案1】:

    使用custom environment 可以使用机器人框架。例如,以下是我在 Device Farm 中运行机器人框架测试的步骤。

    git clone https://github.com/serhatbolsu/robotframework-appiumlibrary.git
    cd robotframework-appiumlibrary
    

    接下来,我通过引用 environment variables 修改了 Device Farm 执行的资源文件。

    ./demo/test_android_contact_resource.txt

    *** Settings ***
    Library           AppiumLibrary
    
    *** Variables ***
    ${REMOTE_URL}     http://localhost:4723/wd/hub
    ${PLATFORM_NAME}    %{DEVICEFARM_DEVICE_PLATFORM_NAME}
    ${DEVICE_NAME}    %{DEVICEFARM_DEVICE_NAME}
    ${APP}            %{DEVICEFARM_APP_PATH}
    
    *** Keywords ***
    add new contact
        [Arguments]    ${contact_name}    ${contact_phone}    ${contact_email}
        Open Application  ${REMOTE_URL}  platformName=${PLATFORM_NAME}  deviceName=${DEVICE_NAME}  app=${APP}  automationName=UIAutomator2
        Click Element    accessibility_id=Add Contact
        Input Text    id=com.example.android.contactmanager:id/contactNameEditText    ${contact_name}
        Input Text    id=com.example.android.contactmanager:id/contactPhoneEditText    ${contact_phone}
        Input Text    id=com.example.android.contactmanager:id/contactEmailEditText    ${contact_email}
        Click Element    accessibility_id=Save
    
    

    然后,我使用以下步骤创建了要上传到 Device Farm 的测试包:

    
    # assumes we're still in the same directory as local execution
    # create a virtual directory
    /usr/local/bin/python2 /Users/$(whoami)/Library/Python/2.7/lib/python/site-packages/virtualenv.py workspace
    cd workspace/
    source bin/activate
    pip install pytest
    pip install Appium-Python-Client
    pip install robotframework
    pip install robotframework-appiumlibrary
    mkdir tests
    cp ../demo/*.txt ./tests/
    pip freeze > requirements.txt
    pip wheel --wheel-dir wheelhouse -r requirements.txt
    echo "# This is a dummy file to appease the parser in Device Farm" > ./tests/dummy_test.py
    # mv command might be required on mac to appease the Device Farm parser
    mv wheelhouse/scandir-1.10.0-cp27-cp27m-macosx_10_12_x86_64.whl wheelhouse/scandir-1.10.0-py2.py3-none-any.whl
    # changed ./bin/robot to use #!/bin/python instead of absolute path to workspace
    zip -r test_bundle.zip tests/ wheelhouse/ requirements.txt
    

    接下来我在 testspec.yml 文件中使用以下命令在 Device Farm 中执行测试。

    bin/robot --outputdir $DEVICEFARM_LOG_DIR/robotresults tests/test_android_contacts.txt

    【讨论】:

    • 您好,我正在尝试您的指导,但无法遵循。您能否解释一下我可以遵循的正确步骤,因为从这里“我然后使用以下步骤创建了要上传到 Device Farm 的测试包:”我不知道您是在 AWS 设备场还是在您的本地计算机上执行此操作的.
    • 我在我的本地机器上创建了测试包,这是一台 Mac。如果我们使用 Ubuntu ec2 实例会更好,因为那是主机设备场使用的操作系统。获得测试包后,我使用 Web 控制台和自定义环境将其上传到设备场,如本视频中所示 youtu.be/PRA1WlR0nvU
    • 感谢您的回复。我想你写的那个是为 Android 写的,你能帮我为 iOS 机器人框架自动化执行同样的操作吗?因为当我运行上述命令时,它给了我一个错误“java.io.IOException:无法运行程序“bin/robot”:error=2,没有这样的文件或目录”
    • 嗯,我认为构建测试包的命令是相同的。你的 testspec.yml 文件中有什么?听起来可能工作目录已更改或机器人框架未包含在测试包中
    • 我只在 testspec.yml 文件中添加了您的 4 行代码,然后就大功告成了……它就像一个魅力。其他执行是从我的 java 代码触发的。感谢这篇文章,它真的很有帮助。
    【解决方案2】:

    AWS Device Farm 支持像 Robotium 这样具有记录和回放脚本工具的框架。如果您希望使用 TestNG 或 JUnit,您可以将语言插入到捕获屏幕截图的脚本中:

    public boolean takeScreenshot(final String name) {
    String screenshotDirectory = System.getProperty("appium.screenshots.dir", System.getProperty("java.io.tmpdir", ""));
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    return screenshot.renameTo(new File(screenshotDirectory, String.format("%s.png", name)));
    }
    

    这是报告的一项重要功能。您可以将此方法放在您的 Abstract BasePage 或 Abstract TestBase 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 2020-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多