【问题标题】:What are the `steps` mentioned while executing swipe() using Appium使用 Appium 执行 swipe() 时提到的“步骤”是什么
【发布时间】:2023-12-05 15:10:01
【问题描述】:
这只是出于好奇和对该方法的实现一无所知,我正在查看java代码的appium服务器日志:
driver.swipe()
服务器日志读取:
info: [debug] [BOOTSTRAP] [debug] 从 [x=540.0, y=1066.0] 滑动到
[x=540.0, y=710.0] 步数:22
这里的22 steps 是什么??
【问题讨论】:
标签:
selenium
appium
swipe
swipe-gesture
【解决方案1】:
“步数”表示在“滑动”动作期间将注入和发出多少个微“移动”动作。该值的计算取决于设备的实际显示尺寸和您想要从和到的滑动坐标(滑动距离)。通常,在微动作之间插入一个微小的延迟来模仿“滑动”。
这里是“Swipe”命令实现的示例source code。
【解决方案2】:
步数是内部滑动选项,根据您提供的滑动时间计算。它指示应该在多少步中完成滑动操作。在您的示例中,整个滑动操作通过 22 个小滑动步骤完成。如果您提供duration to 0,您可能会找到with steps: 0,而不是steps:22。例如,
info: [debug] [BOOTSTRAP] [debug] 从 [x=540.0, y=1066.0] 滑动到
[x=540.0, y=710.0] 步数:0
根据您为滑动指定的持续时间计算步数
Math.round(duration * swipeStepsPerSec)
每秒滑动步数定义为
const swipeStepsPerSec = 28;
因此,如果您提供 1 秒的滑动持续时间,总步数将变为 28。您可以参考 appium android driver code here。