7

Currently Amazon device farm does not have support for Robot framework with Appium. Is there a work around or a tool that can allow me to run my robot scripts on Amazon device farm?

blin92
  • 71
  • 1
  • 2

2 Answers2

3

Using the custom environment it is possible to use the robotframework. For example, here are the steps I used to run a robotframework test in Device Farm.

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

Next I made modifications to the resource file for the Device Farm execution by referencing the environment variables.

./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

I then created the test package to upload to Device Farm using the following steps:


# 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

Next I used the following command in the testspec.yml file to execute the tests in Device Farm.

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

jmp
  • 2,175
  • 2
  • 17
  • 16
  • Hi, i am trying what you have guided but not able to follow it. Can you please explain like proper steps which i can follow because from here "I then created the test package to upload to Device Farm using the following steps:" i dont know where did you do this, on AWS device farm or on your local machine. – Manish Boricha Jan 13 '20 at 09:58
  • I created the test package on my local machine which was a Mac. It would be better if we used an Ubuntu ec2 instance since thats the os the host machine device farm uses. After I had the test package I uploaded it to device farm using the web console and the custom environment like shown in this video https://youtu.be/PRA1WlR0nvU – jmp Jan 17 '20 at 02:06
  • Thanks for the reply. I think the one you have written is for Android, can you help me executing the same for iOS robot framework automation? Because when i am running the above commands, its giving me an error that "java.io.IOException: Cannot run program "bin/robot": error=2, No such file or directory" – Manish Boricha Jan 20 '20 at 05:18
  • Hmm, I think that the commands would be the same to build the test package. What was in your testspec.yml file? Sounds like maybe the working directory was changed or the robot framework wasn't included in the test package – jmp Jan 20 '20 at 12:08
  • I have added just the 4 lines of your code in testspec.yml file and boom...it worked like a charm. Other execution is triggered from my java code. Thanks for this post, it really helped a lot. – Manish Boricha Jan 23 '20 at 12:53
  • Did you created the part "I then created the test package to upload to Device Farm using the following steps:" on your local machine or AWS device farm? – Manish Boricha Jan 28 '20 at 05:19
  • Local machine, which is a Mac – jmp Jan 28 '20 at 11:41
  • @ManishBoricha I need to use AWS Device farm with Robot framework. Can you please let me know the steps. it will be really helpful – Madhu Nov 15 '21 at 10:26
  • How to use AWS Device farm with Robot framework to test a web application? – Cheng Peng Nov 15 '21 at 18:16
-1

AWS Device Farm supports frameworks like Robotium that have record and playback scripting tools. If you wish to use TestNG or JUnit You can insert language into your script that captures screen shots:

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)));
}

This is an important feature for reporting. You can put this method on your Abstract BasePage or Abstract TestBase.

Emna Ayadi
  • 2,430
  • 8
  • 37
  • 77