selene icon indicating copy to clipboard operation
selene copied to clipboard

collection.first_by as alias or substitution of collection.element_by?

Open yashaka opened this issue 3 years ago • 2 comments

Thoughts:

  • collection.first_by(element_condition) is kind of shortcut for collection.by(condition).first
    • + so such name for command would be easier to remember
    • + and will be less questions like: "what is the difference betwean .element_by(condition) and .by(condition).first ?
  • collection.element_by(element_condition) returns Element by finding one ELEMENT among many...
    • + hence, is kind of consistent with element.element(selector) that also finds ELEMENT
      • - but "not among" - it actually finds "inside"
  • + .first_by is a bit more concise than .element_by

yashaka avatar Sep 27 '22 14:09 yashaka

we also will probably have methods to find INSIDE collection – elements by selector...

e.g. for

 <table>
  <tr>
    <td>A1</td><td>A2</td>
  </tr>
  <tr>
    <td>B1</td><td>B2</td>
  </tr>
</table> 

so:

  • browser.all('tr').all('td').should(have.texts('A1', 'A2', 'B1', 'B2'))
  • browser.all('tr').element('td').should(have.texts('A1', 'B1'))

or with s/ss stile:

  • ss('tr').ss('td').should(have.texts('A1', 'A2', 'B1', 'B2'))
  • ss('tr').s('td').should(have.texts('A1', 'B1'))

if we go with "using collection.element(selector)" naming then collection.element_by(condition) might get one more argument to be deprecated in favor of .first_by(condition) ... See more at #449

yashaka avatar Sep 27 '22 16:09 yashaka

.element_by has one benefit over .first_by... The phrase items.element_by(have.text('foo')) leads to a more natural meaning that such element should be only one... while items.first_by(have.text('foo')) gives a clue that it's just one of many... Hence, probably, we have to keep .element_by nevertheless... And question is just to add first_by as alias or not? Maybe I tend to NOT now... Cause first_by(condition) will not add much more value on top of by(condition).first

yashaka avatar Oct 03 '22 12:10 yashaka