我正在使用 Python 将 Robot Framework 与 Appium 集成。但是我不知道如何将 Robot Framework 中创建的 Appium 驱动程序传递给自定义 python 脚本。
我的环境:
- Mac 操作系统 - 小牛队
- Appium 1.2(通过 homebrew 安装)
- 最新的机器人框架(通过pip安装)
- 最新的机器人框架 Appium 库(通过 pip 安装)
我有一个可用的 Python Appium 脚本,但我想开始使用 Robot Framework 来处理实际测试。
工作 python 脚本的部分代码:
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();")
如您所见,由于应用程序的工作方式,我需要使用执行脚本作为脚本的一部分。
机器人框架的Appium库不公开execute_script,所以我需要在python库中编写自己的脚本。
这是我的机器人测试脚本的开始,它一直工作到我需要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]
我的问题是如何获取在开放应用程序中创建的驱动程序实例并将其传递给 Python 脚本?
我有一个 python 脚本,其中包含以下内容:
def KeyboardType(driver):
driver.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"hi there\");")
但是,我似乎无法将驱动程序从 Robot Framework 脚本传递到这个 python 脚本。
我尝试通过以下方式将打开应用程序设置为变量:
${Driver} Open Application ${REMOTE_URL} ${PLATFORM_NAME} ${PLATFORM_VERSION} ${DEVICE_NAME} ${APP}
KeyboardType ${Driver}
但我收到错误:
AttributeError:“str”对象没有属性“execute_script”
我还尝试将 Get Current Context 的结果传递到 python 脚本中,但随后我得到:
AttributeError:“unicode”对象没有属性“execute_script”
如何将 Robot Framework 创建的驱动程序传递到 python 脚本中?