1

I am making a flower pot application, where you add flowers to it.

So imagine on the page, there are a bunch of flowers, and you can click on some + button to add those flowers to your flower pot.

Each button is basically the following -

<button ng-click="model.addToFlowerPot(flower)">Add</button>

Right now, I have maybe a dozen flowers from my flowerArray (flower in flowers) and I'm just using a repeater to show them all.

How can I tell protractor to only test one of those buttons to make sure that flower is added to the flowerPot?

I'm not entirely sure after reading http://www.protractortest.org/#/locators

Thanks

user1354934
  • 8,139
  • 15
  • 50
  • 80

1 Answers1

1

From what I understand, first you need to locate the flowers, this is what by.repeater() locator can help with:

var flowers = element(by.repeater("flower in flowers"));

Then, you choose what flower you want to work with. Let's say the first one:

var flower = flowers.first();  // or flowers.get(0);

Then, you can locate the "Add" button by text:

var addButton = flower.element(by.buttonText("Add"));
addButton.click();

You can also do that for every flower in the repeater using each():

flowers.each(function (flower) {
    var addButton = flower.element(by.buttonText("Add"));
    addButton.click();
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • oh... haha well that is certainly a bit more complicated, but also very fundamental to know. Thank you! – user1354934 Jul 22 '16 at 15:05
  • I'm having some trouble with this. I get an errror - `Failed: element not visible` :( – user1354934 Jul 22 '16 at 15:55
  • @user1354934 could you check if there is another button element with `Add` text inside each of the repeater elements..please see [this answer](http://stackoverflow.com/a/37815727/771848) - it has an overview of common solutions to this problem. Hope this helps. – alecxe Jul 22 '16 at 15:57
  • Every button will have "Add" in it. Thanks for the link - taking a look now. Sorry about the trouble. – user1354934 Jul 22 '16 at 15:57