Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular is not defined on Ionic 2 using protractor 2

According to Protractor Angular 2 Failed: unknown error: angular is not defined angular selectors by.model are not supported.

I also went to http://www.protractortest.org/#/ and I noticed that seems that no change was made to fix this.

How can I set an input text using protractor and Angular 2?

EDIT

I can select my by making this:

let myelement: ElementFinder = element(by.css('.text-input'));

But I have several inputs on my html page. How can I have the 4th ion-input, per example?

like image 743
Goldbones Avatar asked Jun 23 '16 16:06

Goldbones


2 Answers

But I have several inputs on my html page. How can I have the 4th ion-input, per example?

You can issue element.all() and use .get(index) to access an element by index:

let myelement: ElementFinder = element.all(by.css('.text-input')).get(3);  
myelement.sendKeys("text");

Note that we use 3 since indexing is 0-based.

You can also make use of a convenient shortcut for CSS selectors:

let myelement: ElementFinder = $$('.text-input').get(3);
myelement.sendKeys("text");

FYI, negative indexing is also supported in case you want to get elements from the other end:

  • How to get the element before last?
like image 99
alecxe Avatar answered Oct 16 '22 12:10

alecxe


Protractor allows you to use the element.all function which returns an array of objects.

So for your particular example you could do something like this put inside of your test case:

    element.all(by.css('.text-input')).then(function(elements) {
       elements[3].sendKeys('some text')
    });
like image 1
Jarod Moser Avatar answered Oct 16 '22 12:10

Jarod Moser