当函数像这样定义时,一切正常,我的测试成功地点击了按钮(这里的代码被简化了,没有复制粘贴,所以如果票证描述中有任何语法错误,它不是票证的答案):
const wdio = require("webdriverio");
const options = require('./android.conf.js').config;
describe('Main',async ()=> {
it('Should click button', async ()=> {
const client = await wdio.remote(options);
const button = await client.findElement('id', 'app.debug:id/theID');
await client.isElementDisplayed(button.ELEMENT).then(async () => {
await client.elementClick(button.ELEMENT);
})
})但我是这样描述pageObject的:
function PageObjects() {
this.clickButton = async (client)=> {
const button = await client.findElement('id', 'app.debug:id/theID');
await client.isElementDisplayed(button.ELEMENT).then(async () => {
await client.elementClick(button.ELEMENT);
});
}
};
module.exports = PageObjects;我的函数如下:
const wdio = require("webdriverio");
const options = require('./android.conf.js').config;
const PageObjects = require('./po.js');
describe('Main', async ()=> {
const po = new PageObjects();
it('Should click button', async ()=> {
const client = await wdio.remote(options);
po.clickButton(client);
})
})它停止工作,我的测试不能再点击按钮了!我做错了什么?
发布于 2020-01-21 16:13:34
显然,由于这是一个异步流,po.clickButton()试图以比wdio驱动程序所描述的更快的速度执行。为了防止出现这种情况,需要添加await,以便所有测试步骤都能按正确的顺序执行:
describe('Main', async ()=> {
const po = new PageObjects();
it('Should click button', async ()=> {
const client = await wdio.remote(options);
await po.clickButton(client);
})
})https://stackoverflow.com/questions/59784330
复制相似问题