I'm working on integrating Robot Framework with Appium, using Python. However I can't figure out how to pass the Appium driver created in the Robot Framework to a custom python script.
My Environment:
- Mac OS - Mavericks
- Appium 1.2 (installed via home brew)
- Latest Robot Framework (installed via pip)
- Latest Appium Library for Robot Framework (installed via pip)
I have a working Appium script in Python, but I want to start using Robot Framework for handling the actual tests.
partial code for working python script:
wd = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
wd.find_element_by_name("Start").click()
wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]").click()
wd.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"Test Text\");")
wd.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.buttons()['Return'].tap();")
As you can see, because of how the application is working, I ned to use execute_script as part of the script.
The Appium Library for Robot Framework does not expose execute_script, so I need to write my own in a python library.
Here's my start of the robot testing script, which does work up until the point where I need to execute_script:
TestStart
Open Application ${REMOTE_URL} ${PLATFORM_NAME} ${PLATFORM_VERSION} ${DEVICE_NAME} ${APP}
Click Element name=Start
Click Element xpath=//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]
My question is how do I get the driver instance created in the Open Application and pass it to a Python script?
I have a python script that has the following:
def KeyboardType(driver):
driver.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"hi there\");")
However, I can't seem to be able to pass the driver from the Robot Framework script to this python script.
I tried setting the Open Application to a variable via:
${Driver} Open Application ${REMOTE_URL} ${PLATFORM_NAME} ${PLATFORM_VERSION} ${DEVICE_NAME} ${APP}
KeyboardType ${Driver}
but I received the error:
AttributeError: 'str' object has no attribute 'execute_script'
I also tried passing the result of Get Current Context into the python script, but then I get:
AttributeError: 'unicode' object has no attribute 'execute_script'
How can I pass the driver created by the Robot Framework into the python script?