[Ovirt-devel] Testing oVirt with Selenium.

Mohammed Morsi mmorsi at redhat.com
Thu Aug 21 19:27:40 UTC 2008

Everything should be setup and ready for oVirt developers to test
interface functionality via Selenium. Interface tests can be added to
the test/functional/interface_test.rb module and will be picked up and
executed automatically when ‘rake test’ is run. Note if the
‘selenium.rb’ module is missing from the ‘test/’ directory, the
interface tests will _not_ be loaded. Since this module cannot be added
to the code base due to licensing issues, the oVirt autobuild system is
configured to automatically pick it up from /var/selenium/selenium.rb
(if present, else the interface tests will be skipped as mentioned
before) and copy it to the oVirt test appliance.

These tests contact a Selenium test server, giving it the web-accessible
location of the oVirt wui. Both the Selenium Server and oVirt wui
locations can now be specified via the config/selenium.rb config file
(pending one of my recent patches being committed). If you are running
the tests via autobuild, or on an build-all.sh generated appliance whose
host is running the Selenium server (remember to open the port), you
don’t need to edit any of these values, as the fixed 192.168.50.x
virtual network will be employed. If you have a different test setup,
you will need to modify this configuration file to specify the location
of the Selenium Server and the location of the oVirt wui server from
Selenium’s perspective.

If your able to run ‘rake test’ without any errors after all this, then
selenium is integrated, and you should be able to add your own tests.
See the tests already there and pending ack on the list to see how to do
this. Opening / closing the browser and navigating to the main page is
already taken care of via the setup/teardown methods so that all that
remains is to actual test the input / output of the oVirt interface.

Locators for page elements can be specified via a number of means,
perhaps the easiest being xpath (good primer via wikipedia
http://en.wikipedia.org/wiki/Xpath ) . Though one could specify the full
path to the element they are looking for eg /html/body/div[2]/... its
easiest to get as close as you can via the ‘descendant or self’
specifier, eg ‘//’, in conjunction to fixed identifiers and attributes,
indexes, etc. For example to get the 3^rd list item in a list under the
div identified by ‘foobar’ somewhere on the page, a user would use the
locator “//div[@id=’foobar’]/ul/li[3]” (note lists start at index 1). If
you are unsure about your xpath locator, firebug is a great tool to
assist you, see more information here
http://selenium-core.openqa.org/xpath-help.html There are many other
means to specify locators other than Xpath, such as by javascript, css,
etc; see here for more info http://selenium-core.openqa.org/reference.html

Now that you can locate elements on a page, operating on them is
trivial. You may use the Selenium ruby api
(Selenium also provides bindings for many other languages) to interface
with the site. Some useful commands are:


      click(locator) - click on a page element


      type (locator, text) – type some text into an element


      get_xpath_count(locator) – determine the number of nodes found for
      a locator, useful for counting list items and what not



Since our site is very javascript heavy, the ‘waitForCondition’ method,
which takes a javascript expression and a timeout and waits until the
expression evaluates true or the timeout occurs (whichever happens
first) is critical. Make sure to invoke this before attempting to
perform any operations on page elements loaded by javascript, less they
might not be present and your test fails. To wait for the existance of a
div identified by ‘foobar’,


And thats about it, Selenium provides many more methods to test the
application than I describe here, but this should give you a general
idea of where to start. Hope this helps.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20080821/f10255d3/attachment.htm>

More information about the ovirt-devel mailing list