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

查看:46
本文介绍了Robot Framework - 将 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.

Robot Framework 的 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.

我尝试通过以下方式将 Open Application 设置为变量:

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,所以我无法给出明确的答案.但是,有人问了一个关于 selenium 的类似问题,其中有人需要实际的 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.

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

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