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

标签 javascript selenium-webdriver mocha.js 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)

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

最佳答案

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

关于javascript - Webdriver.io + Mocha - 我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43374975/

相关文章:

python - 访问搜索栏并使用 selenium 进行搜索

java - 无法使用 sendKeys“WebElement 类型中的 sendKeys(CharSequence[]) 不适用于参数(字符串)”

javascript - 我在使用毯子的 Mocha 代码覆盖率中获得 0% 覆盖率 0 SLOC

mysql - 在压力下测试时,nodejs 运行时停止响应

javascript - 脚本标签文本/babel 变量范围

javascript - 重定向后无法访问组件中的 this.props.location

excel - 如何让 selenium 等待页面在 Selenium 中完全加载 - Excel VBA 的包装器?

javascript - mochawesome 报告的名称未按预期保存(即使 cypress.json 中的 'reportFilename' 已更改)

javascript - Jquery slideToggle 导致带有内联 block div 的空白

javascript - 如何设置 Openlayers 以使用 backbone.js?