5

While writing test cases using protractor.js for Angular 2 application , if I want to get element(by.model("xyz.test")) its always giving failure saying angular is not defined.

Any idea how to fix this issue?

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
  • Where do you import `by` from? – Günter Zöchbauer Jun 28 '16 at 15:45
  • by comes default when writing the test cases http://www.protractortest.org/#/ – Snehasis Mohapatra Jun 30 '16 at 06:52
  • If you are using [angular ag-Grid](https://www.ag-grid.com/), here is a good solution for this, that I was able to find myself: [ag-grid-access-and-edit-cell-from-protractor-e2e-tests](https://stackoverflow.com/questions/53219964/ag-grid-access-and-edit-cell-from-protractor-e2e-tests) – HDJEMAI Nov 10 '18 at 05:37

3 Answers3

8

As mentioned by @Carmen Popoviciu, who is one of the contributors to the Protractor style guide, by.model and by.binding are not yet working with Protractor and Angular 2:

"Keep in mind that currently not all locator strategies are supported for ng2 apps. Things like by.model() or by.binding() are not working just yet. Check the Protractor changelog for new releases"

https://github.com/CarmenPopoviciu/angular2-go-protractor

Gabriel Kohen
  • 4,166
  • 4
  • 31
  • 46
  • @SnehasisMohapatra, it might not have been the answer you had wish for but if it answers your question for now please mark the question as answered. – Gabriel Kohen Nov 10 '16 at 15:39
  • same subject : https://stackoverflow.com/questions/47814700/failed-unknown-error-angular-is-not-defined?noredirect=1#comment82591605_47814700 – Mikhaël Gerbet Dec 14 '17 at 14:07
1

The answer from @Gabriel Kohen is definitely accurate but I thought I would add another answer with some links to the documentation that actively discourage use of by.model and by.binding

https://github.com/angular/protractor#compatibility

https://github.com/angular/protractor/blob/master/docs/locators.md#locators

At this point it's probably unlikely they will ever be supported.

cliff.meyers
  • 17,666
  • 5
  • 51
  • 66
0

Here's a github issue to follow about this, by.model is mentionned in the comments.

(that's the only open ticket I could find at the minute, if anyone has better)

Arnaud P
  • 12,022
  • 7
  • 56
  • 67