Coding paradigm: line by line all my opinions are belong to me

Atlassian Plugin SDK - how to provide optional selenium tests

You probably are familiar with one of the most popular web UI testing tool - Selenium and it’s most famous tool Selenium IDE.

I don't want to read all this, give me the code
You could find all the code you need on github.
Sorry for not embedding all the code in the article. That way the article becomes clumsy unreadable monster. If anyone could recommend me some collapsable/expandable solution - I would appreciate it a lot.
Why do I need to bother with yet-another-testing-tool? The main advantages or features of the tools are (imo):
  • real UI behavior testing - tests are run inside the real browser and will fire/use real end-user key, mouse, etc events
  • ability to export the test in whole bunch of programming languages (java, python, ruby etc ...)
  • ability to run tests on multiple target web-drivers (firefox, internet explorer, etc ..)
  • Selenium IDE (mentioned earlier) is really nice tool which allows to create simple tests cases very fast, in few minutes or even seconds, literally
  • basically the only way to automate difficult Ajax/RIA component testing on different target environments; other httpUnit like approaches are not good enough
How could I automate that? Selenium has child project - Selenium Remote Control which could be used. Quote and image from Selenium Remote Control site:
Selenium RC comes in two parts.
  1. A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
  2. Client libraries for your favorite computer language.
Lucky to us, selenium has maven artifacts available to be used to plug-in into Atlassian PDK build procedure. Goals:
  1. make this optional (enabled by default) option
  2. selenium-rc server side should be forked before integration tests will be executed
  3. selenium-rc client side tests should be executed as part of the integration test suite
  4. selenium-rc should be revoked upon integration-test completion
Solution:
  1. is achieved by default maven profile (activated by !property)
  2. is achieved by maven - specifying selenium-rc start-server goal to be run on pre-integration-test phase
  3. to achieve this please refer to Atlassian article - Writing Integration Tests. Basically that means - you should put your code inside src/test/java/it/ folder and specifying proper locatest.properties file.
  4. is achieved by maven - specifying that selenium-rc stop-server goal should be executed on post-integration-test phase.
To get pom.xml file snippet - see this pom.xml gist How to check: execute atlas-integration-test command from the project home folder. Recommendations: Atlassian FuncTestCase (Jira in this case. There should be one for other Atlassian products as well) contains a lot of useful utilities and setup methods, which personally I've found very useful. So, the idea is to reuse it as much as possible. That could be done in you create your own abstract base MySeleniumTestCase which would contain FuncTestCase instance as testHelper member field and would make it available via getHelper() or other similar way. Still, you should use your own loginAs method on top of Selenium, cause helper object will have different (not in-browser) http session.
Benefits:
  • ability to reuse utility methods (such as create new custom fields, restore from xml dump etc ..)
  • ability to configure your Selenium test against jira integration test environment - using helper to obtain JiraEvironmentData's host, port, context path etc..
Unlucky I'm not able to share that piece of code, so you should to create it on your own. Still, it should be pretty straightforward, since all you need to do - is do declare member field and delegate to is in your test setUp/tearDown, as well as using it to configure your Selenium test host, port etc ..
Problems with Continuous Integration Ok, so we think we have automated our process so far and it runs locally. On my machine it launches internet explorer and executes the test. Awesome. The next thing is putting the test on our CI, which should be pretty straightforward, right? Wrong! Problems with CI:
  1. CI slave might be Linux terminal machine, no UI and therefore no real launch browser capabilities.
  2. There is a bug with previous pom.xml file. Yes, the profile is optional, however Atlassian PDK framework execute all the it/ tests regardless what type of tests are they, therefore all the Selenium tests will fail.
The former one is solvable by using Selenium-RC Headless X11 with XVFB maven goal. The solution is to execute the goal on Linux machine and skip one on a Windows box. That could be achieved by additional profile setting xvfb skip flag to true and activated on windows platform only.
The later one could be solved by specifying AMPS plugin testGroups. Using that we could specify different sets of independent functional tests, located in different locations (it/functests* and it/selenium/*). We could use configuredTestGroupsToRun property as well, but I decided not to.
So, as a result we have completely independent sets of integration/functional tests, with ability to launch them all-together or pick just one of them.
The code
Please see updated_pom.xml file.

NB. If you've found typos or errors, please suggest a correction or edit on github.
comments powered by Disqus