unic / ScalaWebTest

ScalaWebTest is a library for writing ScalaTest/Selenium based integration tests for web applications. It helps you with your basic setup and provides a new and very efficient approach to testing.
https://scalawebtest.org
Apache License 2.0
29 stars 9 forks source link

HTML Gauges can't handle ID-less sibling elements of the same type #36

Closed jenssuhr closed 7 years ago

jenssuhr commented 7 years ago

Using ScalaWebTest 1.1.0 (but the issue occurred with previous versions as well), HTML gauges seem to have a problem with sibling elements without IDs.

Page HTML:

...
<select name="foobar" class="select">
  <option value="foo" selected="selected">foo</option>
  <option value="bar">bar</option>
  <option value="baz">baz</option>
</select>
...

ScalaWebTest gauge:

fits(
  <select name="foobar" class="select">
    <option value="foo" selected="selected">foo</option>
    <option value="bar">bar</option>
    <option value="baz">baz</option>
  </select>
)

Result:

Misfitting Attribute: [value] in [HtmlOption[<option value="foo" selected="selected">]] with value[foo] didn't equal [baz]
Misfitting Attribute: [value] in [HtmlOption[<option value="bar">]] with value[bar] didn't equal [baz]

This also happens with other elements like div and li.

DaniRey commented 7 years ago

Hi Jens

I tried to reproduce this issue but wasn't able to. Can you have a look at https://github.com/unic/ScalaWebTest/pull/37/files and https://travis-ci.org/unic/ScalaWebTest/builds/237816435 ?

What am I missing? Can you create a pull-request with a failing test?

Kind Regards Dani

jenssuhr commented 7 years ago

That's pretty weird. If I copy both my test and the full HTML output of the tested page to the scalatest project and run the integration tests, the test succeeds. If I run the same thing in my AEM application, it fails.

DaniRey commented 7 years ago

I suspect there is something else, which is different when served from AEM.

Your input got me thinking about some behavior optimizations. The misfits which confused you, are due to the fact that the gauge verifies the attributes, before verifying the order of the elements.

In some cases this helps in other cases it leads to strange error messages. Imagine the content is the same as in your Page HTML, but the gauge has bar and baz in the opposite order. In this case it is preferred, if the gauge reports a wrong element order. To do so we have to search for bar in all possible positions, not only after baz.

In case the element order is correct, but the attributes do not align, the misfits from verifying elements, which are at the wrong position, are alienating. I'm still looking for a solution to cover both situations in a good way.

Your ticket triggered the idea to verify all attributes and the element order, and then only report misfits for the closest matches. But I'm not yet sure if this may workout. I will open a new ticket to try this out.

DaniRey commented 7 years ago

We analyzed this issue together and could see that the description of this issue is off. Therefore I will close it as not a bug. But we could find one issue and one possible improvement, which will be tracked in separate issues. Bug https://github.com/unic/ScalaWebTest/issues/38 opened Enhancement https://github.com/unic/ScalaWebTest/issues/39 opened