zinserjan / wdio-visual-regression-service

Visual regression service for WebdriverIO.
MIT License
102 stars 39 forks source link

Question: How to take a element screenshot per element, in a list of elements (e.g. ul>li)? #46

Closed mansn closed 7 years ago

mansn commented 7 years ago

Hi,

This question should maybe be asked in the wdio-screenshot repo, but anyway:

Disclaimer: This might be a bad idea, and I'd be really happy if you have any alternative solutions.

Let's say that I have a test where I want to:

  1. Take a screenshot of every list item element with the selector ul>li on the following page: http://webdriver.io/, using the command browser.checkElement(elementSelector, [{options}]);.
  2. Store all results in an array.
  3. Assert every position in the array and the test only passes if all of them are true.

I'm trying to accomplish this by:

  1. Get all "list items" using browser.elements('ul>li');
  2. Using a loop, use browser.checkElement on each item in the array (returned from the previous step) and push the results into a "results array".
  3. Using a loop, assert every position in the "results array".

I haven't found a way to do this, because browser.checkElement wants a selector to be passed. The selector is the same for every item in this case.

I might be missing something, or might've misunderstood something. This could be compared to clicking on a specific list item. Then I would just pass the element ID to browser.elementIdClick(). But.. in this case I can't pass an element ID to take a screenshot of a specific list item.

mansn commented 7 years ago

Nevermind.. =) I figured out that I could use :nth-of-child selector to accomplish what I wanted. Sorry if I've wasted anyone's time. I'm closing the "question".