Webdriver.io + Mocha - 我做错了什么??

Webdriver.io + Mocha - What am I doing wrong??

我是 Mocha 和 Webdriver.io 的新手,所以如果我很愚蠢,请原谅...

这是我的代码 -

  // required libraries
var webdriverio = require('webdriverio'),
  should = require('should');

// a test script block or suite
describe('Login to ND', function() {

  // set timeout to 10 seconds
 this.timeout(10000);
  var driver = {};

  // hook to run before tests
  before( function () {
    // load the driver for browser
    driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
    return driver.init();
  });

  // a test spec - "specification"
  it('should be load correct page and title', function () {
    // load page, then call function()
    return driver
      .url('https://ND/ilogin.php3')
      // get title, then pass title to function()
      .getTitle().then( function (title) {
        // verify title
        (title).should.be.equal("NetDespatch Login");
        // uncomment for console debug
        console.log('Current Page Title: ' + title);
    return driver.setValue("#userid", "user");
    return driver.setValue("#password", "pass");
    return driver.click("input[alt='Log in']");

      });
  });

  // a "hook" to run after all tests in this block
 after(function() {
    return driver.end();
  });
});

我可以用 Mocha 执行这个,测试通过了,尽管它似乎没有完成我定义的所有 "steps"..

它打开页面,记录网站标题,并在用户 ID 中输入 'user',但是.. 它不会填充密码字段,或 select 登录名 link,并且似乎没有显示任何错误..

  Login to ND
Current Page Title: ND Login
    ✓ should be load correct page and title (2665ms)


  1 passing (13s)

但是,由于它没有执行所有步骤,我不希望它通过,不过,我也不明白为什么它不会执行最后几步。

欢迎任何帮助。

谢谢

卡尔

如原 post 评论中所述,您的测试中应该只有一个 return

  it('should be load correct page and title', function () {
    // load page, then call function()
    return driver
      .url('https://ND/ilogin.php3')
      // get title, then pass title to function()
      .getTitle().then( function (title) {
        // verify title
        (title).should.be.equal("NetDespatch Login");
        // uncomment for console debug
        console.log('Current Page Title: ' + title);
      })
      .setValue("#userid", "user")
      .setValue("#password", "pass")
      .click("input[alt='Log in']");
  });