机器人框架-将Appium驱动程序传递给python脚本 [英] Robot Framework - passing Appium driver to python script

查看:79
本文介绍了机器人框架-将Appium驱动程序传递给python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python将Robot Framework与Appium集成.但是我不知道如何将在Robot Framework中创建的Appium驱动程序传递给自定义python脚本.

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.

我的环境:

  • Mac OS-小牛
  • Appium 1.2(通过家庭酿造安装)
  • 最新的机器人框架(通过pip安装)
  • 用于机器人框架的最新Appium库(通过pip安装)

我在Python中有一个有效的Appium脚本,但是我想开始使用Robot Framework来处理实际测试.

I have a working Appium script in Python, but I want to start using Robot Framework for handling the actual tests.

适用于python脚本的部分代码:

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();")

如您所见,由于应用程序的工作方式,我决定将execute_script用作脚本的一部分.

As you can see, because of how the application is working, I ned to use execute_script as part of the script.

机器人框架的Appium库未公开execute_script,因此我需要在python库中编写自己的库.

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]

我的问题是如何获取在Open Application中创建的驱动程序实例并将其传递给Python脚本?

My question is how do I get the driver instance created in the Open Application and pass it to a Python script?

我有一个包含以下内容的python脚本:

I have a python script that has the following:

def KeyboardType(driver):
    driver.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"hi there\");")

但是,我似乎无法将驱动程序从Robot Framework脚本传递到此python脚本.

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}

但是我收到错误:

AttributeError:"str"对象没有属性"execute_script"

AttributeError: 'str' object has no attribute 'execute_script'

我还尝试将获取当前上下文"的结果传递到python脚本中,但随后得到:

I also tried passing the result of Get Current Context into the python script, but then I get:

AttributeError:"unicode"对象没有属性"execute_script"

AttributeError: 'unicode' object has no attribute 'execute_script'

如何将Robot Framework创建的驱动程序传递到python脚本中?

How can I pass the driver created by the Robot Framework into the python script?

推荐答案

我目前不使用appium,因此无法给出明确的答案.但是,有人对硒提出了类似的问题,其中有人需要实际的webdriver对象.请参阅问题将现有的Webdriver对象传递给用于Robot Framework的自定义Python库

I don't currently use appium so I can't give a definitive answer. However, a similar question was asked about selenium, where someone needed the actual webdriver object. See the question Pass existing Webdriver object to custom Python library for Robot Framework

简短的答案是,您可以尝试对appium库进行子类化,以便您的关键字可以访问所有appium内部构件,或者可以通过调用BuiltIn().get_library_instance('Selenium2Library来获取库的句柄.

The short answer is that you can try to subclass the appium library so that your keywords have access to all of the appium internals, or you can get a handle to the library by calling BuiltIn().get_library_instance('Selenium2Library.

有关后一种技术的更多信息,请参见《机器人框架用户指南》 .

For more information on the latter technique see see Getting active library instance from Robot Framework in the Robot Framework User's Guide.

这篇关于机器人框架-将Appium驱动程序传递给python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆