Warning: file(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php on line 40

Warning: file(https://scipilot.org/blog/wp-content/plugins/ap-extended-mime-types/mime-types.txt): failed to open stream: no suitable wrapper could be found in /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php on line 40

Warning: Invalid argument supplied for foreach() in /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909

Warning: Cannot modify header information - headers already sent by (output started at /home/sciptorg/public_html/blog/wp-content/plugins/ap-extended-mime-types/ap-extended-mime-types.php:40) in /home/sciptorg/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1909
{"id":88,"date":"2013-06-30T13:21:47","date_gmt":"2013-06-30T02:21:47","guid":{"rendered":"http:\/\/scipilot.org\/blog\/?p=88"},"modified":"2016-06-29T11:54:19","modified_gmt":"2016-06-29T00:54:19","slug":"re-learning-unit-testing-selenium-2-phpunit-selenium","status":"publish","type":"post","link":"https:\/\/scipilot.org\/blog\/2013\/06\/30\/re-learning-unit-testing-selenium-2-phpunit-selenium\/","title":{"rendered":"Re-learning unit testing with Selenium 2 and phpunit-selenium"},"content":{"rendered":"

Now that I’ve finished re-building my house (almost) I’ve got two or three years of programming projects to catch up on. One of the most pressing is updating the Motif.org.au site with the new reading tests that have been developed and normed for ‘phase 2’.<\/p>\n

My problem is that I’ve been working on the site on-and-off over the last two years, there’s a version on staging which has completed UAT but it took so long that I’ve had to modify the live site with content updates. My old PC died so I’ve lost my old dev environment. I’ve switched from SVN to Git in one dependency. The live site has had a year of traffic too, so the staging database is way out of date. I feel extremely nervous about pulling all this together and re-launching the staging version, before going ahead with the queue of subsequent changes.<\/p>\n

Automation to the rescue!<\/p>\n

I’ve used Selenium IDE and RC before for full-stack UAT testing, and done a lot of unit testing and UAT scenario testing via PHPUnit so I thought it would be pretty easy to pull together some tests to ensure the site and the language tests are all still working properly while I finish off a list of integrations, package updates and refactoring I want to do before launch. The site isn’t huge and it’s well structured but the language tests have to work perfectly. It would be a pretty serious consequence to be mis-diagnosing children’s learning abilities, due to a software bug. This site really does affect people’s lives.<\/p>\n

So I started confidently pulling together a testing environment mostly copied from previous projects but decided to start writing the tests from scratch and use the latest patterns. I came very quickly unstuck, and found the Selenium 2 documentation for both the server, Web Driver and phpunit-selenium to be quite mysterious.<\/p>\n

I spent days feeling like I was missing something – I thought it was the proper documentation! In fact I had quite a few major misunderstandings about Selenium and phpunit-selenium. I was doing it wrong.<\/p>\n

So partly for my own memory, partly to help anyone else who is diving a little deeper into Selenium testing, I’m going to document my learnings here.<\/p>\n

The first main problem was Selenium v1 verses Selenium v2.<\/strong> There’s so much mixing of help and tutorials on the web, it’s easy to get the wrong advice. Even on Stack Overflow almost every question has a mix of right and wrong answers, the wrong ones often in v1 syntax when answering a v2 question. One of the underlying causes I believe is that there’s some helpfully intended but obscure backwards compatibility out there which some people (like me!) don’t know they’re using.<\/p>\n

e.g. on the phpunit-selenium readme it says:<\/p>\n

“This package contains a base Testcase Class that can be used to run end-to-end tests against Selenium 2 (using its Selenium 1 backward compatible Api).”<\/p><\/blockquote>\n

Now I’m not sure whether the “it’s” refers to this package or the server, but someone is providing a v1 API! (It’s actually both.) In the case of phpunit-selenium:<\/p>\n

    \n
  1. PHPUnit\/Extensions\/SeleniumTestCase.php<\/a>\u00a0– if you inherit from this you use Selenium1 (RC) API<\/li>\n
  2. <\/a>PHPUnit\/Extensions<\/a>\/Selenium2TestCase.php<\/a>\u00a0– this implements the Selenium2 API\u00a0(Web Driver, via the Json wire protocol)<\/li>\n<\/ol>\n

    So that should be pretty clear right? Except for the fact the v1 test case is just called TestCase, (which is a mistake we all make when making the first version<\/em> of anything!) you are in control of which API you use when you make the inheritance choice. However I spent the last two weeks at work updating our hundreds of tests thinking I was using Selenium 2 – because a) we are using Selenium 2 server which is automatically started by Bamboo so I didn’t really get involved, b) all of our test cases extend from our common base class so you don’t see the inherited API class in your face, c) he Selenium HQ website’s attempts at explaining the differences between 1 and 2 make your head spin!<\/p>\n

    The best documentation for the Selenium 1 API<\/strong> doesn’t seem to be linked from the Selenium HQ website! Luckily Sebastian Bergmann provides it in his brief intro to phpunit-selenium.<\/p>\n