protractor-cucumber icon indicating copy to clipboard operation
protractor-cucumber copied to clipboard

Protractor API Doesn't Work in Step Definitions?

Open JimLynchCodes opened this issue 8 years ago • 1 comments

Hi, I'm VERY confused about the proper way to use protractor with cucumber.

I thought that the whole point of using cucumber with protractor was that you can use the protractor api in the step definition methods. However, when I put things like element(by.css(.something)) it gives me errors, "element is not a function".

All of the Protractor methods cause the test runner to crash. How can I use the Protractor api in the step definition methods? Thanks.

JimLynchCodes avatar Jun 26 '16 16:06 JimLynchCodes

I believe they are part of the cucumber World, which is the this given from a step definition.

So you should write this.element(this.by.css(...))

Personally I am setting them as global to be able to use the proper Protractor API:

  this.Before(function() {
    global.$          = this.browser.$;
    global.$$         = this.browser.$$;
    global.browser    = this.browser;
    global.by         = this.by;
    global.element    = this.browser.element;
    global.protractor = this.protractor;
  });

And then element(by(...)) will work.

floribon avatar Jul 20 '16 12:07 floribon