AndrewKeig / protractor-cucumber

protractor-cucumber
MIT License
73 stars 59 forks source link

Protractor API Doesn't Work in Step Definitions? #44

Open JimLynchCodes opened 8 years ago

JimLynchCodes commented 8 years ago

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.

floribon commented 8 years ago

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.