AngulareJS e2e checks every link in the list

I am new to AngularJS and I will use the e2e part mainly (with jasmine). After literally several days of inaction with this (I believe the documentation is quite anorexic, to say the least!) I wonder if anyone can help me here:

The website creates an html link list = href. I can 'click' the link using angularjs e2e as follows:

element('li a').click(); 

Fine But there are two questions:

  • If there are 6 links in the list, which link is a click ??? (in the tested html code, these links do not have a unique identifier, and some may be exactly the same / url links, etc.)?

  • How can I iterate over each link in a list? those. element (links [1]). click () β†’ ... to do what then moves back β†’ the item (links [2]). click () β†’ ... do what then moves backward ... etc ...

(NOTE: The version of angularjs e2e "element" does not match "angular.element".)

+2
source share
2 answers

SOLVE!!!

 element('li:eq(0) a').click(); //<-- clicks the first link. element('li:eq(1) a').click(); //<-- clicks the 2nd link. 

etc...

The developer here showed me this, but I have no idea how he knew!

+3
source

Well - in case someone else is curious (I cannot be the only person on earth trying to understand this material!) I worked on question 1 for myself: by the solid values ​​of the code in the list, which I found that

 element('li a') 

... will select the last specified item.


Thus, with the seemingly insoluble problem of creating an element (), select a specific element in the list.

 console.log("ROYDEBUG: " + element('li a')); 

... returns "ROYDEBUG: [Object Object]" to the console log.

BUT I can understand that there are elements of the list "x". If I do this:

  element('li a').query(function (selectedElements, done) { selectedElements.each(function(idx,elm) { var thisOne = selectedElements[idx]; //<-- (same as "= this;"). console.log("ROYDEBUG: " + idx + " - " + thisOne); //element(thisOne).click(); //<-- doesn't work :( //element(this).click(); //<-- doesn't work :( //element(selectedElements[idx]).click(); //<-- doesn't work :( }); done(); }); 

Then I get this in the console:

 ROYDEBUG: [object Object] ROYDEBUG: 0 - http://localhost:9876/app/index.html#/coupon/100 ROYDEBUG: 1 - http://localhost:9876/app/index.html#/coupon/100 ROYDEBUG: 2 - http://localhost:9876/app/index.html#/coupon/100 ROYDEBUG: 3 - http://localhost:9876/app/index.html#/coupon/100 ROYDEBUG: 4 - http://localhost:9876/app/index.html#/coupon/100 ROYDEBUG: 5 - http://localhost:9876/app/index.html#/coupon/100 

... so he knows there are 6 items in the list. However, I cannot use "element (). Click ()" for these returned "elements" because they are just a text string from the "href =" part of each link (as you can see in the output on the console above).

+2
source

Source: https://habr.com/ru/post/1446914/


All Articles