javascript - 无法使用 WebdriverIO 和 Mocha 执行页面对象模式
问题描述
我正在尝试在我的测试中使用页面对象模式。我真的遇到了很多问题,例如使用 Mocha 我不应该在做断言时“最终”使用,但是没有它我的测试会失败。难道我做错了什么?当我在做任何控制台日志时,我得到的信息是我的承诺是 {state: pending}
这是我的第一个测试:test1.spec.js:
import chai from 'chai';
import cartPage from '../pageobjects/cart.page';
import regeneratorRuntime from "regenerator-runtime";
const chaiAsPromised = require("chai-as-promised");
const { expect } = chai;
const { assert } = chai;
chai.use(chaiAsPromised);
chai.should();
describe('Test1 - All elements exist on the Cart Page', function () {
before(function () {
cartPage.open();
});
it('should validate if the Add button exists', function (done) {
expect(cartPage.addButtonText.getText()).eventually.equal('Add').notify(done);
});
it('should validate if the Remove button exists', function (done) {
expect(cartPage.removeButtonText.getText()).eventually.equal('Remove').notify(done);
});
});
我的 cart.page.js 看起来是这样的:
import Page from './page';
class CartPage extends Page {
get addButtonText() { return browser.element('.button'); }
// getAddTextButton() { return this.addButtonText.getText(); }
get removeButtonText() { return browser.element('.remove_button'); }
open() {
super.open('/shopping-cart');
browser.pause(5000);
}
}
export default new CartPage();
我正在尝试编写第二个测试:
import chai from 'chai';
import cartPage from '../pageobjects/cart.page';
import regeneratorRuntime from "regenerator-runtime";
const chaiAsPromised = require("chai-as-promised");
const { expect } = chai;
const { assert } = chai;
chai.use(chaiAsPromised);
chai.should();
describe('Test2 - All elements are clickable on the Cart Page', function () {
before(function () {
cartPage.open();
});
it('should validate if the Add button is clickable', function (done) {
cartPage.addButtonText.click();
我看不到按钮被点击。我在尝试 console.log 时得到 {status:pending}。我无法在文本字段中设置任何值。我正在使用 wdio 运行测试,尝试使用 sync: true、false 或将其注释掉,但我看不出有任何区别
我不确定我的方法是否可行。我已经尝试了许多使用页面对象模式的存储库,但每次都失败了
解决方案
推荐阅读
- google-app-engine - 如何从 Cloud Storage 存储桶提供 App Engine 网站的 /static/ 目录内容?
- c - 有人可以告诉我为什么这不起作用吗?
- facebook - Facebook 和 Instagram,在自己的网站上获取和显示自己的帖子
- shell - 退出tmux后如何自动退出终端
- stm32f7 - 我可以将 c++ 与 stm32f7 一起使用吗?
- docker - 在 Dockerfile 中设置非 root 用户的环境,使其修改后的版本在构建时可用
- c# - 为什么在基于身份 Cookie 的身份验证中一段时间后 User.Identity.IsAuthenticated 设置为 false
- ios - 如何处理 JSONDecoder 中的空日期字符串
- android - 如何知道热重载是否足以应用 Flutter 应用程序中的更改?
- google-cloud-platform - 通过 generate_signed_url 函数访问图像时出现 403 错误