Appium-Execute Driver Script(执行驱动程序脚本)


Run a WebdriverIO script against the current session, allowing execution of many commands in one Appium request. //对当前会话运行WebdriverIO脚本,允许在一个Appium请求中执行多个命令。

Example Usage
JavaString script = "const el = await driver.$('~foo');\n"
+ "await el.click();"
driver.executeDriverScript(script, new ScriptOptions().withTimeout(200));
Pythonimport textwrap
script = """
const el = await driver.$('~foo');
await el.click();
"""
response = driver.execute_driver(script=textwrap.dedent(script))
Javascript// webdriver.io example
const script = '
const el = await driver.$('~foo');
await el.click();
';
await driver.executeDriver(script);
// wd example
const script = <br/>const el = await driver.$('~foo');<br/>await el.click();<br/>;
await driver.executeDriver(script, {timeout: 200});
Ruby# ruby_lib example
script = <<-SCRIPT
const status = await driver.status();
return status;
SCRIPT
driver.execute_driver script: script
# ruby_lib_core example
@driver.screenshot_as(:base64)
C#// TODO C# sample
PHP// TODO PHP sample
Description

One downside of Appium’s client-server architecture is that each command must travel across a network with potentially high latency. This is especially the case in situations where the Appium session takes place on a service provider’s host machine rather than locally.//潜在高延迟缺点

This command enables the batching of many commands together, to be executed in one go on the Appium server. The way this is accomplished is on the model of executeScript: the client will send in a string representing code to be executed. The Appium server will execute that code in the context of the current session, and return any values specified by the script. //允许多命令批处理在一起一次执行,在executeScript模型上

There are three parameters accepted by this command (which may be collected by each client in its own way): * script: the string consisting of the script itself * timeout: a number representing the number of milliseconds to wait before killing the process running the driver script. Default is equivalent to 1 hour. * type: a string representing the script language/API. Currently only one type, webdriverio, is supported (and it is the default). //此命令接受三个参数,每个客户端都可以以自己的方式收集):脚本:由脚本本身组成的字符串超时:表示终止运行驱动程序脚本的进程之前等待的毫秒数的数字。默认值相当于1小时。*type:表示脚本语言/API的字符串。目前只支持一种类型webdriverio(这是默认的)

Not just any code can run in this context. The code must be written in Javascript, and it will have access to a context with three objects * driver: a WebdriverIO driver object. It may be assumed this driver has already connected with the Appium server and is ready to run commands. The version of WebdriverIO used is the one installed according to the specification in appium-base-driver's package.json file. * console: a custom console object, with methods log, warn, and error, so that logging may take place. * Promise: a Promise library (Bluebird), to make asynchronous work easier. //代码必须用Javascript编写并且可以访问包含三个对象*driver的上下文:WebdriverIO driver对象,一个自定义的console对象具有log、warn、error方法

The code will be placed inside an async function, as below, so you are free to use await: //代码将放置在异步函数中,如下所示,因此您可以自由使用

(async function (driver, console, Promise) {
  // --> your script here <--
})()

Any errors will result in an error response to the call to this command. Any return values will be wrapped up and sent back to your client in the following form:
任何错误都将导致对该命令调用的错误响应。任何返回值都将以以下形式打包并发送回客户端:

{result: <return value>, logs: {log: [], warn: [], error: []}}

Using this response object you can gather the return value as well as the output of any log statements you made. //使用此响应对象,可以手机返回值以及所做的任何日志语句的输出

The advantage of this approach of using WebdriverIO code is that you have access to a full programming language and Appium API, and can use any language or API features you need, including loops, conditionals, and explicit waits. The WebdriverIO API cannot be enumerated here, so visit the WebdriverIO documentation for more info. //这种使用WebdriverIO代码的方法的优点是,您可以访问完整的编程语言和appiumapi,并且可以使用您需要的任何语言或API特性,包括循环、条件和显式等待。此处无法枚举WebdriverIO API,请访问WebdriverIO文档以获取更多信息

Support
Appium Server

详见

Appium Clients
LanguageSupportDocumentation
JavaAllappium.github.io
PythonNoneappium.github.io
Javascript (WebdriverIO)All
Javascript (WD)Allgithub.com
RubyNonewww.rubydoc.info
PHPNone
C#None
HTTP API Specifications
Endpoint

POST /session/:session_id/appium/execute_driver

URL Parameters
namedescription
session_idID of the session to route the command to
JSON Parameters
nametypedescription
scriptstringThe webdriverio script to execute
typestringThe name of the script type. Currently only ‘webdriverio’ is supported
timeoutnumberThe number of ms Appium should wait for the script to finish before killing it due to timeout
Response

The script result. It will have two fields: result and logs. Result will be the return value of the script. Logs will contain the content of anything logged from the console object by the script. (any) //脚本结果。它将有两个字段:结果和日志。结果将是脚本的返回值。日志将包含脚本从控制台对象记录的任何内容。(任何)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aniona

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值