【问题标题】:node.js: calling a function in webdriverio using mochanode.js:使用 mocha 在 webdriverio 中调用函数
【发布时间】:2016-08-03 07:14:35
【问题描述】:

我正在编写许多测试用例。在所有这些中都有一个共同的部分(登录用户并做一些其他事情)。

所以我不想在每个测试中都写那部分,我想要一个函数来调用它。

我尝试过使用 .then 和 .call 但它会抛出错误:

   .setValue('#signin_email', LogInEmail)
    ^
SyntaxError: Unexpected token .

这是怎么做到的?

【问题讨论】:

  • 你能包含更多代码吗?尤其是.setValue之前的部分

标签: node.js selenium mocha.js webdriver-io


【解决方案1】:

你是这个意思吗? http://webdriver.io/guide/usage/customcommands.html

browser.addCommand("LogInEmail", function () {
    return browser
      .setValue('#signin_email', 'emailaddress')
      .setValue('#password', 'password');
});

// to invoke
browser.LogInEmail()

【讨论】:

    【解决方案2】:

    如果你想在每次 mocha 测试之前运行你的公共部分,然后像这样把它放在 beforeEach() 函数中。

        describe('some test', function() {
    
         beforeEach(function() { 
                // your common part here     
           }); 
    
        it('it should do something, function() {
           ...
           });
           ...
        it('it should do something else', function() {
           ...
           });
    
    
       });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2013-11-01
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多