目前亚马逊设备农场不支持带有 Appium 的机器人框架。是否有解决方法或工具可以让我在亚马逊设备场上运行我的机器人脚本?
问问题
2293 次
2 回答
3
使用自定义环境可以使用机器人框架。例如,以下是我在 Device Farm 中运行机器人框架测试的步骤。
git clone https://github.com/serhatbolsu/robotframework-appiumlibrary.git
cd robotframework-appiumlibrary
接下来,我通过引用环境变量对 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
于 2019-10-20T20:01:18.000 回答
-1
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 上。
于 2017-06-01T23:31:23.183 回答