Speedrun install for WebDriver 2.43.1 on Mac OS X 10 Mavericks

I added the notes and video for my ‘speedrun’ install of WebDriver 2.43.1 with Java, Maven and IntelliJ on the speedrun page.

I used VM Fusion to create a VM on my Mac with a clean install of OS X 10 Mavericks, then went through the process of installing on the Mac.

I updated the speedrun checklist to account for the Mac OS differences, and made notes on the install.

For some reason, when I installed on my ‘proper’ mac, I didn’t have to set the JAVA_HOME variable, but I did on the VM, so the video shows a full environment setup for JAVA_HOME, M2_HOME, M2 and updating PATH.

I found it interesting how Mac prompted me to the correct location a few times – ie. the install of JDK 1.8, so I did this earlier in the process than I did with Windows XP.

Also, since Mac OS X 10 Mavericks is slightly more ‘modern’ than Windows XP, I didn’t have to install an alternate browser to download the files, or an alternate text editor to amend the pom.xml file and update it to version 2.43.1 of WebDriver.

I edited the video down to 13 minutes, although the elapsed time (if I exclude the Wifi failure I had in the middle, was about 45 minutes).

You can find the speedrun video and installation notes on the speedrun page.

Posted in WebDriver | Leave a comment

First WebDriver Speedrun Install added

I have created a new page on the site for ‘speedruns’

seleniumsimplified.com/speedrun-installs

These are start to finish single run install of:

  • Java
  • Firefox
  • WebDriver
  • Maven
  • IDE
  • And running first test from command line and IDE

They have been edited to remove the boring bits, have annotations as simple explanation, but no verbal commentary.

I have an install checklist on the page, but you can also find that in our ‘start’ github project.

I’ll add more speedruns for different operating systems and versions over time.

For now, I have added Windows XP (using the modern.ie).

If you need more help getting started than the speedrun offers then watch our free get-started course or the free preview videos on our full course.

Posted in Uncategorized | Leave a comment

Selenium WebDriver Page Object Abstractions and Beyond

I’ve been collating my thoughts on Page Objects and Abstraction Layers, particularly the implementation of them using Java.

I presented my initial thoughts at Let’s Test 2014 in a half day workshop. This could easily have been a full day workshop to allow for more experimentation with the different coding styles.

I released the slides to the tutorial on slideshare.

I confess to some nervousness about releasing the information since I don’t normally release the slides to tutorials and courses in case it cuts down on the value of running the tutorial or course again.

But, in this case, I don’t see enough information on the web about multiple Abstraction Layers and different ways of doing Page Objects, so I thought I’d throw my work out there, along with the supporting source code.

I’m presenting this material as a ‘talk’ rather than a workshop at StarWest 2014, and at Oredev 2014.

On a related note. I fronted a discussion at the Test Management Summit 2014 on Automation Abstractions. The slides for which were taken from the above presentation.

The aim for the slides and presentation is to demonstrate multiple approaches, so that people don’t just pick up the first ‘framework’ they see, or build ‘Page Objects’ without thinking through the modelling approaches open to them.

In the code and presentation I have examples of:

  • Page Objects
  • Page Objects that synchronize as slow loadable components
  • Navigation separate from Page Objects
  • Domain Objects
  • DOM WebElement abstractions
  • and more…

The code and slides demonstrate some of my biases.

The main point is that ‘none of these approaches are best’, and we make decisions when we build our automation. We should take responsibility for those decisions and experiment with what works best in our environment, with our coding skills, with our development standards, for our application.

I’ll expand this material in the future. But I hope it helps somewhat in its current form.

You might also find the slides for my BDD tutorial relevant since I discuss some of my thoughts on BDD and Domain Specific Languages as Abstraction Layers.

Posted in Conferences, Practices | 2 Comments

Selenium Conference 2014

The Selenium Conference “seconf 2014” starts on the 4th of September.

This year, we are one of the sponsors of the conference. Although we can’t attend.

For a limited time, to celebrate the Selenium Conference, check out our Selenium Conference page for special discounts on our online courses.

I don’t think the conference has live streaming this year. But subscribe to the Selenium Conference YouTube channel as there are sure to be videos from the conference available during September.

Posted in Conferences | Leave a comment

Upgrading the HTMLUnit Version for WebDriver with Maven Dependencies

Since HTMLUnit impressed me so much in my last run through of tests I wanted to see how the current version would perform.

I noticed that WebDriver 2.42.2 uses version 2.14 of HTMLUnit,  but the current version of HTMLUnit is 2.15. I wanted to try 2.15 and see if it made a difference.

I import the full selenium-server dependency since it makes life easy for me.

<dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-server</artifactId>
 <version>2.42.2</version>
</dependency>

This brings in HTMLUnit 2.14.

To bring in 2.15, I have to add a dependency on HTMLUnit itself in my pom.xml. And, provided HTMLUnit versions are backwards compatible, I should be good to go.

In the pom.xml before I import selenium-server, I import HTMLUnit

<dependency>
 <groupId>net.sourceforge.htmlunit</groupId>
 <artifactId>htmlunit</artifactId>
 <version>2.15</version>
</dependency>

And when I run the tests against this version of HTMLUnit, I discover that a few more tests have failed.

Oh well, I guess the guys at SeleniumHQ know what they are doing, and the picked the best version.

But the point is – you can override the dependencies if you have a specific use case that needs it, or a clash in those dependencies.

 

 

 

 

Posted in Maven | Leave a comment

Selenium WebDriver getAttribute nuance

I used to have an exercise on my course with the aim of recreating the ‘getTitle’ command using different mechanisms.

It was a fun exercise, you can try it for yourself. I’ll wait while you do it…

*Spoilers*

When I first created the exercise, it was pretty easy since you could just grab the title element and do a getText on it.

But… in later versions of WebDriver, getText stopped working on title and I dropped the exercise.

You could still complete the exercise by parsing the full page text, and of course executing JavaScript to get the innerHtml of the element (but we would not have covered JavaScript execution at that point on the course).

And now…

I noticed, in 2.42.2, that I can use getAttribute(“text”) to get the text from the title element.

I haven’t reinstated the exercise but I thought it would be interesting to compare getText() and getAttribute(“text”) on different tags.

I found it interesting that:

  • getText() on
    • html returns the text for the page (minus tags)
    • body, div, strong, ul (as per html)
  • getAttribute(“text”) on
    • title returns the title (getText does not)
    • script returns the inline script details
    • option returns the text, as does getText
  • sometimes getAttribute(“text”) worked on some a tags, where getText did not

I don’t think I’ll rely on this nuance as WebDriver may not always do this, but I thought it interesting enough to note.

Feel free to repeat the exercise on your pages if you want. The code I used is in my WebDriverExperiments project on github

TagInvestigationTest.java

And as a side note, you can see the type of investigation process I go through when I find an oddity or something I don’t understand – I write code to check and explore combinations that would take too much time to investigate by hand.

As you can see from the code, sometimes I write hacky code, because it is essentially throw away for my learning purpose, and I ignore the simple defects in it.

 

 

 

 

Posted in WebDriver | Leave a comment

A quick WebDriver 2.42.2 retrospective

I spent a fair few hours working through all the tests and examples on my Selenium WebDriver Course to check compatibility with WebDriver 2.42.2 and the most recent browsers.

I used…

  • Chrome Version 35.0.1916.153 m
  • IE Version 11.0.9600.17126
  • Firefox version 30.0
  • HTMLUnit 2.14 (included with WebDriver 2.42.2)

Let’s get opera out of the way quickly – since operadriver only supports Opera up to version 12.16, and the current version is 22 – I didn’t run the tests against this. Pity, since Opera still feels like a fast browser.

And let’s get IE out of the way quickly, but not dismiss it. IE 11 still awaits the official driver from Microsoft, so we should expect the current driver to have issues with it. There were a whole bunch of tests I was able to reinstate against IE because the driver functionality has moved on since I last checked it. But sadly, the speed of sendtext kills tests in IE11. I didn’t spend a lot of time debugging the tests against IE 11 – hopefully Microsoft will get an official driver out soon.

Pity, as the IE driver has improved a lot for 8,9, and 10. Previously I had failing tests for user interactions, alerts, input alerts, and these no longer occur.

HTMLUnit driver impressed me the most. I haven’t given it much love and attention over the years, but since I saw that WebDriver has recently upgraded the version of HTMLUnit that it uses, I thought I’d give it a shot. Out of my basic “All” browsers test suite, it only failed 12 tests, (out of 155) so I’m going to spend a bit more time investigating the limits of HTMLUnit driver. I was very impressed. Remember, start HTMLunitDriver with ‘true’ to get the JavaScript support.

Firefox trundled along happily with no changes to my codebase to keep the tests running due to the driver, just one change to the codebase and it was my fault:

  • I found a bug in one of my tests because Firefox was no longer tolerant of my mistakes
    • I had left a release in after a drag and drop, and now I receive an exception about “can’t release button when not clicked”, so I fixed my code
    • actions.dragAndDrop(draggable2,droppable1).release().perform();
    • don’t do that, do this
    • actions.dragAndDrop(draggable2,droppable1).perform();

Chrome required a few changes:

  • I had to deal with the “–ignore-certificate-errors” reporting by adding a chrome option when starting the driver “options.addArguments(“test-type”);”
  • Chrome seems to create rogue cookies when you add a cookie with the domain in it (I raised this as an issue 7499 (now moved to ChromeDriver issue 824) but I suspect most people will never encounter this issue). And the workaround – just don’t add the domain, the cookie will still be created fine.
  • Chrome now supports submitting forms with a keypress on the submit button (which it didn’t last time I checked) so I re-enabled that test for Chrome

Always remember to double check issues with your automation manually kids.

I found an issue with Chrome – that had nothing to do with WebDriver.

One of my tests uses sendkeys to select items from a dropdown by typing in the text of the dropdown option. This has previously worked, and still works on Firefox. But it doesn’t work on Chrome through WebDriver. And it doesn’t work on Chrome when I repeat the test manually, so I’m putting this down to a Chrome nuance, rather than a WebDriver nuance.

I also found an interesting side-effect of getAttribute, that I’ll blog about separately.

Posted in WebDriver | 2 Comments

Upgrading Selenium WebDriver from v 2.40.0 to 2.42.2

A new version of Selenium WebDriver came out recently and I had to make a few changes to my main course source code as a result. I had not upgraded publicly for a while so I was moving from 2.40.0 to 2.42.2, but I had been using 2.41.0 in tutorials and workshops.

In this blog post I’m going to describe the process I went through in order to do it.

  • Amend the WebDriver version in the pom.xml
  • run a “mvn clean test-compile” to catch any compile errors after the upgrade
    • If I just use “mvn clean compile” it won’t report the errors as nothing has changed in the source code
  • fix any errors

In this case, when I jumped to 2.42.2 I encountered compile issues with the “WebDriverBackedSelenium import” and the “HTMLUnit BrowserVersion” variables.

The ultimate fixes were pretty simple, but it is really the process that is interesting.

 

Fixing the Import

I read the changelog to see if anything interesting has happened. I find this by going off to SeleniumHQ.org, clicking “download”, clicking “Browse Git”, clicking “changes”, look at the release for 2.42.2, and view the changelog.

A search for “WebDriverBackedSelenium” in the changelog reveals that in 2.40.0 it was moved to “com.thoughtworks.selenium.webdriven” and deprecated in its current import

And sure enough, when I check back to the code in 2.40.0 it is deprecated. The change log doesn’t tell me when it was removed, but I’m interested so I just change the pom.xml file to 2.41.0 and the error appears, so it was deprecated in 2.40.0 and removed in 2.41.0.

The easy way for me to fix this error is to remove the import statement and let IntelliJ find it, or I could copy the import from the change log. I let IntelliJ do it. But I make the changes against 2.42.2 rather than 2.41.0.

To make IntelliJ fix this I

  • delete the import line in the code
  • use auto fix in IntelliJ with “Intention Actions” (Alt+Enter)
  • choose the correct import from the list in IntelliJ, or let IntelliJ find it if there is only one

Fixing HTMLUnit Issue

There was no mention in the change log for the HTMLUnit issue.

When I view the code of BrowserVersion in 2.42.2 I can see that htmlunit-2.14 is in use, and in 2.40.0 it was htmlunit-2.13 so I assume it is just an upgrade of HTMLUnit that has caused my issue.

In the HTMLUnit change log I can see that they recommend FIREFOX_24 so I’ll change the code to use that.

Change Happens

With the issues fixed, I check the compile

  • “mvn clean test-compile”

And all works.

Change happens. We just have to learn how to deal with it.

Hope this, and the associated video help.

Posted in Maven, WebDriver | Leave a comment

Mac cross-platform lessons learned with Selenium WebDriver

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.

Hmm.

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.

Screen Sizes

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.

Normally this isn’t too big an issue, but TodoMVC is heavily JavaScript, and heavily CSS.

So some buttons only appear when the mouse is hovering over an element, and they are hidden/displayed by css rather than JavaScript.

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.

Specific Locators

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.

How odd.

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:

  • debugging,
  • FireBug
  • Firefox Inspect functionality
  • IntelliJ Evaluate functionality
  • Chaining findElement methods

 

 

Posted in WebDriver | Leave a comment

Schadenfreude Lessons Learned from Training Course Upgrades

On a recent training session, I was describing to the participants, why we need to keep our environments stable, and not just auto update everything.

We need to keep our browser versions from auto-updating, and we need to treat each new release of WebDriver as a mini upgrade project.

Because:

  • Sometimes there are bugs in WebDriver.
  • But sometimes WebDriver changes expose bugs in our use of WebDriver, or our assumptions in our use of WebDriver.

As a quick example, I’m building the source code for a tutorial that I will present at Let’s Test, and I’m making sure the code works on the Mac. I also want to try and update WebDriver to the latest version so that I’m good to go when the tutorial rolls around.

So I upgrade the version of WebDriver to 2.41.0 on my Mac, and run the tests. And some of my tests are failing.

I assume due to Mac (cross-platform) incompatibilities.

But I’ve made a cardinal sin.

I haven’t followed my own advice for upgrade processes.

Namely:

  • Make sure the tests are working and stable, before upgrading the environmental elements i.e. – browsers, and driver version

Fortunately it doesn’t take me too long to figure out that, I should really update the version of WebDriver on my windows box (where all the tests are running fine) first.

I do that, and I get the same issue.

And – as I mentioned in the course it has shown an error in my thinking, or assumption in WebDriver.

I’ve been using KEYS.ENTER to complete input fields. And now I need to use KEYS.RETURN

Before, it was an arbitrary choice for me, which one I used, but now, only KEYS.RETURN does what I want.

For some reason, that I haven’t investigated.

Very often with WebDriver, I’m more focused on what I try to do with it, than assuming it is a bug in WebDriver.

Here I think there is some nuance for the different keys that I haven’t understood, but I’m quite happy to change my tests to use KEYS.RETURN and have the tests working with 2.41.0, and with 2.40.0

Whereas, KEYS.ENTER, didn’t work with my use case on 2.41.0, but works fine for 2.40.0

Lessons:

  • Upgrade on a stable platform
  • Upgrade in steps: driver, then browsers
  • Check small changes against previous versions of driver
  • Don’t assume it is a cross platform issue

Of course, I still have to fix the ‘real’ cross platform issues – see the next posts for that.

 

Posted in WebDriver | Leave a comment