Javascript 承诺:WebdriverIO用户界面测试只在Chrome上运行,不在Firefox和Safari上运行
我已经创建了test.page.js,在这里我在页面上设置了元素。我想找到“添加”按钮。这是我的代码:Javascript 承诺:WebdriverIO用户界面测试只在Chrome上运行,不在Firefox和Safari上运行,javascript,selenium-webdriver,automated-tests,es6-promise,webdriver-io,Javascript,Selenium Webdriver,Automated Tests,Es6 Promise,Webdriver Io,我已经创建了test.page.js,在这里我在页面上设置了元素。我想找到“添加”按钮。这是我的代码: import Page from './page'; class TestPage extends Page { get addButton() { return browser.element('#add-button > a'); } getAddButton() { return this.addButton.getText(); } 根据文档,
import Page from './page';
class TestPage extends Page {
get addButton() {
return browser.element('#add-button > a');
}
getAddButton() {
return this.addButton.getText();
}
根据文档,下面的示例应该可以工作,但实际上不行。它返回待定的承诺:
在我的test.spec.js文件中,我使用chai作为chai库的承诺扩展来断言此元素:
import testPage from '../pageobjects/test.page';
it('should validate if Add button exists', (done) => {
testPage.getAddButton().should.eventually.be.equal('Create a new thing').notify(done);
});
它在Chrome上运行,但在Firefox或Safari上失败。我认为我在定位元素时出错了,我的版本与文档版本不同。有人能帮忙吗?问题不在于你的元素选择器,据我所知,它们写得都正确,而在于你如何使用Chai WebdriverIO为您不需要使用“最终”关键字的地方带来了一些特殊的魔力。尝试此断言:
testPage.getAddButton().should.equal('createanewthing')
我使用类似的想法创建了一个测试示例,供您尝试运行:
就是这样,我只是在使用Chai时遇到了问题,问题不在于WebdriverIO本身。谢谢@klamping很高兴它修好了!
import testPage from '../pageobjects/test.page';
it('should validate if Add button exists', (done) => {
testPage.getAddButton().should.eventually.be.equal('Create a new thing').notify(done);
});