需要帮助在webdriver.io上创建期望条件



我正在测试一个web应用程序,它使用进度条来反映一些冗长过程的状态。

我需要创建一个测试,单击Start按钮,然后等待进度条达到75%。然后点击停止,5%是通过测试的可接受公差限制。

但是我不确定如何创建一个断言来检查这个,我已经创建了测试,它停在75%,但是我怎么能(使用Mocha和预期的wdio库)可以验证它是否在5%可接受的公差限制?

这是我现在正在工作的内容:

describe('Progress bar challenge', () => {
before(() => {
ProgressPage.open();
});
it('Should click [start] wait for the bar to reach 75% and click [stop]', async () => {
await ProgressPage.startBtn.click(); 
await ProgressPage.progressBar.waitUntil(async function () {
return (await this.getAttribute('aria-valuenow')) >= '75'
}, {
timeout: 50000,
});
await ProgressPage.stopBtn.click();
console.log(await ProgressPage.progressBar.getAttribute('aria-valuenow'));        
});

});

日志通常返回75或76,但我不知道我可以创建哪个断言来通过测试。

试试下面的代码,这将有5%的公差

it('Progress bar start wait stop and tollerence', async () => {
await ProgressPage.open()
await ProgressPage.startButton.click()
await ProgressPage.progressBar.waitUntil(async function() {
const tolerance = (await this.getAttribute('aria-valuenow'))
return ( tolerance >= '75' && tolerance <= '80' )
},
{
timeout: 50000,
timeoutmsg:"Failed while waiting for progressBar to reach 75%"
})
await ProgressPage.stopButton.click()
});

不确定我的理解是否正确,但是如果你导入chai

const { assert } = require('chai')
const progressValue = await this.getAttribute('aria-valuenow')

,然后做

assert(progressValue >= '75' && progressValue <= '80')

最新更新