I had to make sure my tests run on a Mac, I don’t often do this, but I’m using a Mac laptop as my main laptop now.
And I honestly wasn’t expecting to have too many issues running the tests.
But - lo, 12 tests failing out of 36.
Normally my first thoughts are version issues. But my Mac is running the same version of Firefox and WebDriver.
So I have some ‘real’ cross-platform issues.
It has been a long time since I addressed screen size issues, but the app I’m using as an example ToDoMVC uses a good chunky CSS style. And appears quite large in my Mac Firefox.
Particularly my default Firefox window size when running in retina mode, as it only takes up a quarter of the screen.
Which meant that when I created a new window and added some Todos, the screen was a tad weeny.
Which makes it a nice little playground for automation.
Anyway, the fact that there was a teeny screen meant that when I clicked on something to make the CSS hover click in, to make the delete button display, WebDriver cleverly recognises that the WebElement is off-screen, so scrolls it on screen, but now the hover event doesn’t kick in because the mouse is off-screen.
I solved this with a hack of clicking, then clicking again - just in case a scroll had happened.
I only had to make this change in a single place in the abstraction layer so it didn’t feel too bad.
But I’d forgotten about offscreen issues because I hadn’t encountered any for a while. I don’t think I’d have had this problem with ‘real’ click event functionality, it was only because I needed to trigger the CSS hover, by a click, that gave me the issue.
All my tests were working fine on Windows.
But a few were failing on Mac.
A click on an element that worked fine on Windows, failed on the Mac.
After a little investigation I discovered that Windows was allowing me to be lazier than the Mac.
I’ve been finding and clicking on “#filter li”
But I really should have been finding and clicking on “#filter li a”
i.e. the child Anchor, not the enclosing ListItem.
So even though I thought “a click on the element worked find on Windows, but failed on the Mac”, the truth was, that I hadn’t been clicking on the correct element in the first place.
It seems as though the click event was propagating down the DOM to the Anchor tag on Windows, but not the Mac.
Lessons Learned (again):
- Be as specific as possible in your locators so that you are selecting the actual element you want the event to reach.
- Cross-platform execution often exposes errors in our automation code: particularly our location strategies and synchronisation strategies
Videos of the debug process are available on YouTube, showing use of:
- Firefox Inspect functionality
- IntelliJ Evaluate functionality
- Chaining findElement methods