Automatic GUI tests with selenium

From MPDLMediaWiki
Jump to: navigation, search


Selenium is a portable software testing framework for web applications. The tests can be written with a Firefox plugin. The plugin records all your steps and afterwards integrates it into a testcase. The tests can also be written in several programming languages.

The tests are run on your local workstation. That means, when have deployed your earEnterprise Archive File Formate, a selenium testing instance is started. This instance is then used to run all the earlier defined testcases.

Selenium architecture

Selenium Tool Suite

Selenium-IDEIntegrated Development Environment (Integrated Development Environment/firefox plugin)

  • is intended as a rapid prototyping tool
  • allows developing and running tests without the need for programming skills
  • Selenium Commands (Selenese) features:
    • Element can be located with
      • Identifier
      • Id
      • Name
      • XPathExpression Language Used to Navigate and to Find Structures in XML Documents
      • Hyperlinks (Link Text)
      • DOMDocument Object Model
      • CSSCascading Style Sheets
    • Text can be matched
      • Globbing
      • RegExp
      • Exact Patterns
    • AndWait Commands (for AJAX as well)
    • Stored Variables
    • Stored JS Snippet Evals
    • Pop-ups handling (Alerts, Confirmations, Multiply Windows)
  • can only run it’s test scripts against Firefox (since it is FF plugin)
  • programming in java is not needed
  • doesn't support iteration or condition statements (like testing each element of a variable length list)
    • complete list what is not directly supported:
      • condition statements
      • iteration
      • logging and reporting of test results
      • error handling, particularly unexpected errors
      • database testing
      • test case grouping
      • re-execution of failed tests
      • test case dependency
      • screenshot capture of test failures

Selenium-RCRights Checking (Remote Control/java)

  • java programming
  • covers all features of selenium
  • supports iterations and condition statements
  • tests of the any complexity
  • integration with JUnit
  • integration with maven

Selenium-WebDriver (new Selenium APIApplication Programming Interface)

  • new direction of Selenium development (i.e. Selenium 2.0)
  • has no limitations of Selenium-RCRights Checking 1.0
  • has backward compatibility with Selenium-RCRights Checking 1.0

Selenium-GridGlobal Release Identifier

  • solution to scale for large test suites or test suites that must be run in multiple environments

Selenium-Core (HTMLHypertext Markup Language inerface TestRunner.html)

  • deprecated

Flow Control (iterations and conditions) in Selenium

Possible options:

  • Run the script using Selenium-RCRights Checking and Java client library (java programming is needed)
  • Run a small JavaScript snippet from within the script using the storeEval command
  • Install the goto_sel_ide.js extension (for Selenium-IDEIntegrated Development Environment)

Firefox selenium plugin (Selenium-IDEIntegrated Development Environment) installation

  • Point your Firefox browser to and install the selenium plugin
  • After restarting the browser you should see 'Selenium IDEIntegrated Development Environment' in your 'Tools' folder.
  • If you open it, you get a toolbox for creating, recording and verifying your testcases.

Possible PubManPublication Management testing workflows

Create/Playback of testcases/test suits with Selenium-IDEIntegrated Development Environment

  • Prerequisites:
  • Creation of new testcase/test suite
    1. Open PubManPublication Management page to be tested in Firefox
    2. Open Selenium-IDEIntegrated Development Environment and start recording (see here and here)
    3. Proceed PubManPublication Management test case according to specification in the Firefox
    4. Stop recording
    5. Modify Selenium Commands in Selenium-IDEIntegrated Development Environment if needed
      Comments and annotates can be inserted directly in testcase (See here)
    6. Save testcase in working copy under the appropriate name
    7. Create or update already created Test Suite.
      Note: Test case files should not have to be co-located with the test suite file that invokes them. And on Mac OSOperating System and Linux systems, that is indeed the case. However, a bug prevents Windows users from being able to place the test cases elsewhere than with the test suite that invokes them.
    8. Commit created testcase/test suit to the SVNApache Subversion repo
  • Playback testcase/test suite
    1. Open Test Suite from working copy with Selenium-IDEIntegrated Development Environment->File->Open Test Suite
    2. Playback (See here )
Selenium Firefox UI

Further reading: Selenium-IDE documentation page.

Playback of testcases/test suits with Selenium-RCRights Checking

  • Prerequisites:
    • Local SVNApache Subversion working copy of PubMan testcases repo
    • Java =>1.5
    • Browsers Firefox [, IEInternet Explorer, Safari, Opera, etc.]
java -jar selenium-server.jar -htmlSuite "*firefox" "" "c:\absolute\path\to\my\HTMLSuite.html" "c:\absolute\path\to\my\results.html"

Playback of testcases/test suits with MAVEN

  • Prerequisites:
    • Local SVNApache Subversion working copy of PubMan testcases repo
    • Local SVNApache Subversion working copy of pubman_integration
    • Java =>1.5
    • maven
    • Browsers Firefox [, IEInternet Explorer, Safari, Opera, etc.]

Maven integration of selenium


Selenium is running a PubManPublication Management testcase.

To use selenium in a maven build environment, the selenium maven plugin is used. You can add this plugin simply by including the plugin into your pom.xml The plugin here is encapsulated in a profile, which means unless this profile is activated, no tests are made.

                                        <taskdef resource="">
                                            <classpath refid="maven.plugin.classpath" />
                                        <selenese suite="src/test/resources/selenium/TestSuite.html" browser="*firefox /usr/lib/firefox/firefox-2-bin" timeoutInSeconds="180"
                                            port="5555" results="${}/selenium-firefox-results.html" startURL="http://localhost:${cargo.port}/pubman/" />


The profile defines the jboss instance, where, in this case PubManPublication Management, is started and it defines the selenium client instance. In this case the Firefox browser is used. To start the GUIGraphical User Interface tests for this PubManPublication Management example simply type:

mvn -Pintegration-test clean install

To be done in the PubManPublication Management projects

  • Check the compatibility with Windows
  • Finish use of static identifiers within dynamic pages
  • Integrate different browsers than Firefox
  • Integrate Java GUIGraphical User Interface testcases into Maven

Selenium (introduction, architecture)


PubManPublication Management and Selenium tests


Related Links