My title for this is terrible but I can't think of a better way to word it right now.
I have a web screen where if you click a submit button without filling in fields, 9 validation error messages appear. I have defined a page object with these elements as a collection:
smalls :errors, class: ["form__error", "!ng-hide"]
This is using a page object model where "errors" becomes a method that can be called, essentially wrapping the HTMLElements. A key thing there is I'm negating a class attribute.
If I do this:
It outputs 9 correctly. So I know the element definition is referencing the right collection and finding the appropriate objects with the class.
However, if I do this:
puts errors.count
puts errors.count
puts errors.count
I get the following output:
This is without any change to the page. Somehow it's losing reference to 7 of the errors, even though on the screen nothing has changed. I have a sleep in place to make sure I can see the screen. And when I do a check in the console for ".form__error", I see 9 returned and I see they have the same class attributes. But somehow just calling "errors" again is losing reference to some of the elements in the collection.
Here's another example of how this happens.
If I do this:
errors.each do |error|
puts(error.text)
end
I get the text of all nine errors correctly, once again showing that my element definition is working and finding only those elements with the class. But now I'll combine the things I'm doing and do this:
puts errors.count
errors.each do |error|
puts(error.text)
end
I get an output of 9 with no error messages listed. So it only recognized the "errors" on the first execution. Now I'll change the order of those:
errors.each do |error|
puts(error.text)
end
puts errors.count
In this case, I get the nine error messages text listed out but no count at all.
Now here's the kicker: if I remove the negated class element, everything works:
smalls :errors, class: "form__error"
This now returns consistent results. They are wrong results unfortunately because the app has some extra "form__error" text that I don't want to count. I only want the "form__errors" that also not have a "ng-hide" attribute as part of the class.
I'm hoping I'm describing this well enough that it makes sense to someone what might be happening.