当前Amazon Device Farm不支持Appium的机器人框架。是否有工作或可以让我在Amazon Device Farm上运行机器人脚本的工具?
使用自定义环境,可以使用RobotFramework。例如,这是我用来在设备农场运行RobotFramework测试的步骤。
git clone https://github.com/serhatbolsu/robotframework-appiumlibrary.git
cd robotframework-appiumlibrary
接下来,我通过引用环境变量对设备农场执行的资源文件进行了修改。
./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
然后,我创建了测试包,使用以下步骤上传到设备农场:
# 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文件中的以下命令来执行设备农场中的测试。
bin/robot --outputdir $DEVICEFARM_LOG_DIR/robotresults tests/test_android_contacts.txt
aws设备农场支持具有记录和播放脚本工具的机器人等框架。如果您想使用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)));
}
这是报告的重要功能。您可以将此方法放在抽象的基础上或抽象测试库上。