简体   繁体   English

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

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

I am new to Mocha and Webdriver.io, so please excuse me if I am being stupid... 我是Mocha和Webdriver.io的新手,所以如果我很笨,请原谅...

Here is my code - 这是我的代码-

  // 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();
  });
});

I can execute this with Mocha, and the test passes, even though it doesn't seem to do all of the "steps" I have defined.. 我可以使用Mocha来执行此操作,并且测试似乎可以完成我定义的所有“步骤”,因此测试可以通过。

It opens the page, logs the website title, and enters 'user' in the userid, BUT.. It doesn't populate the password field, or select the login link, and there doesn't appear to be any errors displayed.. 它将打开页面,记录网站标题,并在用户ID BUT中输入“用户”。它不会填充密码字段,也不会选择登录链接,并且似乎没有显示任何错误。

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


  1 passing (13s)

But, as it hasn't executed all the steps, I don't expect it to pass, though, I also don't understand why it won't do the last few steps. 但是,由于它没有执行所有步骤,因此我不希望它通过,但是我也不明白为什么它不执行最后几步。

Any help would be welcome. 任何帮助都将受到欢迎。

Thanks 谢谢

Karl 卡尔

As mentioned in the original post comments, you should only have one return in your test: 如原始帖子评论中所述,您的测试应该只有一个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']"); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM