I'm new to AngularJS and I'll be using the e2e part mostly (with jasmine). After literally a few days of getting nowhere with this (I'm finding the documentation pretty anorexic to say the least!) I'm wondering if someone could help me here:
A website generates an html list of a=href links. I can 'click' on a link using angularjs e2e like this:
element('li a').click();
Fine. But here's two questions:
If there are 6 links in the list, which link is this clicking?? (in the html code that's being tested, these links have no unique id and some could be exactly the same reference / url etc..)?
How can I loop through each link in the list? i.e. element(links[1]).click() -> ... do whatever then navigate back -> element(links[2]).click() -> ... do whatever then navigate back ... etc...
(NOTE: angularjs e2e's version of 'element' is not the same as 'angular.element'.)
SOLVED!!!
element('li:eq(0) a').click(); //<-- clicks the first link.
element('li:eq(1) a').click(); //<-- clicks the 2nd link.
etc...
A developer here showed me this, but I've no idea how he knew!
Okay - in case anyone else is curious (I can't be the only person on earth trying to figure this stuff out!) I've worked question 1 out for myself: By hard-coding values into a list I found that
element('li a')
... will select the last listed item.
So, on with the seemingly unsolvable issue of making 'element()' select a specific item in a list.
console.log("ROYDEBUG: " + element('li a'));
... returns "ROYDEBUG: [object Object]" to the console log.
BUT I can get it to recognise that there are 'x' list items. 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 it knows there are 6 items in the list. However I can't use "element().click()" to these returned 'elements' because they're just the text string from the 'href=' part of each link (as you can see in the console output above).