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

时间:2017-04-12 16:29:23

标签: javascript selenium mocha webdriver-io

我是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执行此操作,并且测试通过,即使它似乎没有执行所有"步骤"我已定义..

打开页面,记录网站标题,然后输入用户'在用户ID中,但是.. 它不会填写密码字段,也不会选择登录链接,并且似乎没有显示任何错误..

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


  1 passing (13s)

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

欢迎任何帮助。

由于

卡尔

1 个答案:

答案 0 :(得分:1)

如原始帖子评论中所述,您的测试中只应有一个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']");
  });