Until recently, my test cases written with Robot Framework were not driven by the GUI. Those tests were interacting with the SUT using many different ways: process library, database access, file system, REST requests etc. Those access usually don’t change too often during the lifetime of a product as they often become a contract for users/tools communicating with product (i.e. API). Whereas driving the SUT through the UI can be brittle and engage the team in a constant refactoring of the tests. This is summarized in the famous pyramid of tests. But, having no automated GUI tests, my pyramid was headless! So I decided to invest a bit in the topic.
From there I had the choice between :
- writing tc with Robot using the Robot Framework Selenium 2 library
pro: integrated with other existing Robot tc + easy to start
con: library a bit behind the official one + selenium users are mostly not using this API - writing tc in Java using the Selenium 2 Java binding
pro: up to date + large community of users
con: another set of tools to write/launch/report test cases in addition to Robot
I took the easy path and went for the Robot Library. There is an excellent demo of the library which helps to start-up. Before digging into the tests of my SUT, I added another 2 steps:
- going a bit further in my knowledge of Chrome Developer Tool. There is an excellent online course by Code School. Those tools are soon becoming very useful when creating GUI driven test case. Note that, Firefox dev console seems to offer the same service, but somehow I feel more ease with Chrome ones.
- running a testing dojo with a group of peers. We used Jenkins as SUT (as I already did to perform some stress test trials) and it worked quite well although Jenkins does not seem to be the easiest web app to test as we had to use XPATH to locate element which can become obsolete quite fast.
I was then able to create my first tests on the SUT I am testing. Those were more easy as expected as all the element I had to address had unique IDs! The biggest obstacle is to chain actions without using the horrible sleep keyword (see Martin again). With the Robot Selenium library, the easiest way is to use (and abuse) the “wait until page contains element” keyword.
Last but not least, I needed to launch the tests using Jenkins (very easy and quite nice with the plugin) on a linux VM…. without a display! Here enters PhantomJS that is a headless browser supported by the Robot Selenium library. But somehow, my tests were randomly failing with it, so I gave it up and went back to Firefox. And here is the last character of this little story: xvfb. This display server sends the graphic to memory so no need to have a full/real display available. The install is not immediate but some shared their feedback on it so it is quite smooth after all.
So the current configuration of my Robot Selenium tc in Jenkins is:
- xvfb running on the VM on which tests are going sending display to :89
- in Jenkins, in my Robot task, in “Build Environment / Set environment variable” I put “DISPLAY=:89”
And that’s it, tests are running OK on this VM. And on the top of that, when there is a failure in the tests, the Robot Selenium lib is able to perform a screenshot and save it to disk to ease analysis of the issue!
Extremely useful article! Thanks a lot!
super article…..
Thank you so much
XVFB can also be controlled from robotframework
e.g following script can be wrapped inside RF
https://github.com/Work4Labs/selenium-simple-test/blob/7fe4a44df804e8e7f18aad9ecef5667c8abf22d4/src/sst/xvfbdisplay.py
Thank you for sharing this. This is a good idea.
I created make this simple wrapper arround xvfb available for everybody
https://pypi.python.org/pypi/robotframework-xvfb/1.0.1
Hey does the above wrapper works on OSX.
I don’t think it does
Hi Laurent,
Thanks for this post. It was very useful. Even after a couple of years this article holds good. Its was lot easier with xvfb wrapper for python and made my life lot simpler.
My environment are as follow: solaris 5.10 + python 2.7 + robot framework + robotframework-selenium2library-1.7.4 + xvfbwrapper-0.2.4.
Laurent & Balaji,
Which browser did you finally used? PhantomJS or Firfox? If you used firefox was it opening the browser or it was true headless.
we are using Firefox now, the real one, not headless. And we still use XVFB on VMs that don’t have displays.
Hi all,
I’m using a Linux RELH running Jenkins that start robot framework with xvfb. The duration of my test suite under firefox is 50 mins but with chrome 10 hours. Does anybody have an idea why the same test takes that long under chrome?
I have no idea why it would take so long with Chrome.
Can’t you see if there is a specific phase/keyword that last a long time?
is their any article for java?