简体   繁体   中英

node.js: calling a function in webdriverio using mocha

I am writing many test cases. In all of them there is a common part (signing in the user and doing some other stuff).

So instead of writing that part in every test, I want a function to call it.

I have tried using .then and .call but it throws error:

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

How is this thing done?

Do you mean this? http://webdriver.io/guide/usage/customcommands.html

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

// to invoke
browser.LogInEmail()

If you want to run your common part before every mocha test then put it in beforeEach() function like this.

    describe('some test', function() {

     beforeEach(function() { 
            // your common part here     
       }); 

    it('it should do something, function() {
       ...
       });
       ...
    it('it should do something else', function() {
       ...
       });


   });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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