繁体   English   中英

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

[英]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来执行此操作,并且测试似乎可以完成我定义的所有“步骤”,因此测试可以通过。

它将打开页面,记录网站标题,并在用户ID BUT中输入“用户”。它不会填充密码字段,也不会选择登录链接,并且似乎没有显示任何错误。

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


  1 passing (13s)

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

任何帮助都将受到欢迎。

谢谢

卡尔

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