无法使用WebdriverIO和Mocha执行页面对象模式

时间:2018-07-31 09:27:11

标签: javascript selenium selenium-webdriver automated-tests webdriver-io

我正在尝试在测试中使用页面对象模式。我真的遇到很多问题,例如使用Mocha我做断言时不应该“最终”使用,但是如果没有它,我的测试就会失败。难道我做错了什么?当我执行任何控制台日志时,都会收到有关我的承诺为{state:待处理}

的信息

这是我的第一个测试: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时,我得到{状态:未决}。我无法在文本字段中设置任何值。我正在使用wdio运行测试,尝试使用sync:true,false或已将其注释掉,但看不到任何区别

我不确定我的方法是否可以。我已经尝试过很多使用页面对象模式的存储库,但是每次都失败

0 个答案:

没有答案