【问题标题】:How to implement automated scroll in Appium with Webdriverio + Mocha?如何使用 Webdriverio + Mocha 在 Appium 中实现自动滚动?
【发布时间】:2018-08-23 22:56:06
【问题描述】:

我正在为使用 react 构建的移动应用程序自动化测试用例。我正在使用 Appium 框架,我正在使用的客户端是 Webdriver.io,以及用于断言的 Mocha 和 Chai。

到目前为止,我的脚本运行良好,但我遇到了滚动问题。我查看了用于滚动的 Webdriver.io 文档并实现了 touchAction()、touchPerform()、execute()、scrollTo(),但在这种情况下没有任何方法有效。谁能帮我解决这个问题?

这是我正在使用的示例代码

var webdriverio = require("webdriverio");
var expect = require("chai").expect;
var config = require("./helpers/desiredCapabilities").options;
var client = webdriverio.remote(config);

describe("Sample Test", function() {
  beforeEach(function() {
  this.timeout(90000);
});

describe("Scroll Test", function() {
  before(function() {
    return client.init();
  });

  it("should scroll successfully", function() {
    return client
      .element("~mobile")
      .setValue("1000000000")
      .element("~continue")
      .click()
      .element("~passwordTextField")
      .setValue("12345")
      .element("~continue")
      .click()
      .element("~home")
      .touchPerform([{
          action: 'press', 
          options: {x: 60, y: 200}
       },
       {
          action:'moveTo', 
          options: {x: 700, y: 200}
       },
       {
          action: 'release'
       }
    ])
    .element("~article")
    .click()
  });
 });
});

这段代码模拟了一个简单的登录操作,在 touchPerform() 之前它运行良好,它不执行任何滚动。

这是 Appium 所需的功能。

exports.options = {
  desiredCapabilities: {
    platformName: "android",
    platformVersion: "5.1",
    appPackage: "com.sample.app",
    appActivity: "com.sample.app.MainActivity",
    automationName: "uiautomator2",
    avdReadyTimeout: "2000",
    deviceName: "AVY9K17424903794",
    app: "C:/Users/MdArifuzzaman/Arif/Appium Test/app-universal- 
          release.apk",
    newCommandTimeout: 90
  },
  host: "127.0.0.1",
  port: 4723
}; 

这是我的 package.json 文件。

{
  "name": "sampletest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "mocha scrollTest"
  },
  "author": "Md. Arifuzzaman",
  "license": "ISC",
  "dependencies": {
    "appium": "^1.7.2",
    "appium-uiautomator2-driver": "^1.1.1",
    "chai": "^4.1.2",
    "chai-as-promised": "^7.1.1",
    "mocha": "^5.0.0",
    "wd": "^1.5.0"
  },
  "devDependencies": {
    "randomstring": "^1.1.5",
    "wdio-appium-service": "^0.2.3",
    "wdio-mocha-framework": "^0.5.12",
    "webdriverio": "^4.10.2"
  }
}

【问题讨论】:

    标签: javascript node.js mocha.js appium


    【解决方案1】:

    我不确定这个遮阳篷是否也能在移动设备上为您提供帮助。但我认为应该这样做。

    向下滚动:

    client
    .url('https://www.yourwebsite.com')
    .leftClick('#yourtable') // <-- should also work with .click()
    .scroll(0, 500) // the higher the more we scroll
    

    要使用键,请确保在模拟鼠标位于您要向下滚动的项目之前单击列表 div 框。然后你可以按向下键向下:

     /*
      \uE014    "ArrowRight"
      \uE015    "ArrowDown"
     */
    
    client
    .leftClick('#yourtable') // <-- should also work with .click()
    .keys('ArrowDown')
    .keys('ArrowDown')
    .keys('ArrowDown')
    // or
    .keys('\uE015')
    .keys('\uE015')
    .keys('\uE015')
    

    来源:api/protocol/keys.html

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 2017-06-19
      • 2021-11-27
      • 2022-07-09
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多