Thursday, June 12, 2008

Selenium Core

Selenium Core is a test tool for web applications. Selenium Core tests run directly in a browser, just as real users do. And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux and Macintosh. No other test tool covers such a wide array of platforms. Team of programmers and testers at Thought Works developed it.

It allows the tests to run in any supported browser on the client-side, mainly allows you to do the following:
Browser compatibility testing: Test your application to see if it works correctly on different browsers and operating systems. The same script can run on any Selenium platform.
System functional testing:
Create regression tests to verify application functionality and user acceptance.


Advantages: Selenium Core works on
all the major browsers on all the platforms. Selenium Core is a simpler form of Selenium and it is suitable for non-developers, but it has some inherent limitations and few others mentioned below.

  • Recommended use: Non- developers
  • Better use: Developers writing custom tests
  • Optional command line

It Supports Platforms and browsers are as below:

Windows:

  • Internet Explorer 6.0 and 7.0
  • Firefox 0.8 to 2.0
  • Mozilla Suite 1.6+, 1.7+
  • Seamonkey 1.0
  • Opera 8 & 9

Mac OS X:

  • Safari 2.0.4+
  • Firefox 0.8 to 2.0
  • Camino 1.0a1
  • Mozilla Suite 1.6+, 1.7+
  • Seamonkey 1.0
  • Not yet supported: OmniWeb

Linux:

  • Firefox 0.8 to 2.0
  • Mozilla Suite 1.6+, 1.7+
  • Konqueror
  • Opera 8 & 9

Disadvantages: Must have write access on web server, because directly writes core tests in web applications. It is extremely complicated for first time users.


Selenium Core installation: If this is your first time using a Selenium tool, you may not want to just use Selenium Core directly; one good way to get introduced to Selenium's features is to use Selenium IDE , which embeds Selenium Core internally. Download Selenium IDE and you'll get Selenium Core along with it. Give it a spin!

Selenium Core is pure DHTML/JavaScript, to use Selenium Core you need to make it available from the same web server as the application you want to test. That means that you can't use Selenium Core (pure DHTML/JavaScript) to write a test of google.com this is because Selenium Core is pure DHTML/JavaScript, and so it is bound by JavaScript's security restrictions. Specifically, JavaScript enforces (This is a JavaScript security requirement. If you can't/won't modify the web server you want to test, Selenium Core may not be the right tool for you; you may just want to use Selenium IDE or Selenium RC instead. If you're on Windows and you only want to use Selenium Core with Internet Explorer, you may also use HTA mode to run your tests against a remote web site.)

Normally, this is as simple as extracting the Selenium Core zip file into the DocumentRoot, htdocs, or webroot of your webserver. Then, try to open the TestRunner.html page on your website, which should be in the core/ directory.


Run Selenium’s test suite: We can run our scripts using Test Runner only. Test Runner gives you nice browser interface to execute your tests and also gives summary of how many tests were executed, how many passed and failed.Here is a screen shot of Test Runner.

The screen is divided into four sections: "Test Suite", "Current Test", "Control Panel" and the main application frame where your application will reside. Initially, none of the Control Panel buttons will work, because you haven't selected a test suite. By default, Selenium Core offers to run the test suite in "../tests/TestSuite.html". Click "Go" to open that test suite.

If you installed the /tests along with /core, you should now see a list of tests to run. Press the "Run All Tests" button to run all of our automated tests. Note that some tests may fail if your browser blocks pop-ups, manages passwords, or does other helpful things that interfere with automation. Be sure to turn these features off before running the tests!


Here's a close-up view of the Selenium Control Panel:

Run All Tests: Run every test in the test suite.

Run Selected Test: Click on one test in the test suite, then click here to run just that one test.

Pause / Continue: While a test is running, press the Pause button to temporarily stop running commands. After you press Pause, you can press Continue to resume the test.

Step: Click on a test in the test suite, and then click on just one line of the test to set a "breakpoint." When the TestRunner reaches a breakpoint, it will automatically pause execution on that line. You may then press the Step button to run the next line of the test and pause again. You can also click on a breakpoint line to remove the breakpoint.


HTA Mode: Selenium Core provides an additional mechanism for running automated tests called "HTA mode." HTA Mode only works on Windows, and only with Internet Explorer; you can't use HTA mode to test any other browser. An HTA file is a special type of HTML file that is allowed to violate the same origin policy and to write files to disk. When running in HTA mode, you don't have to install Selenium Core on the same webserver as the AUT. HTA files are also allowed to save test results directly to disk, rather than POSTing the test results to a webserver.
To run Selenium Core in HTA mode, just double-click on TestRunner.hta, in the /core directory of your Selenium installation. (As you can see, TestRunner.hta is just a copy of TestRunner.html; but that ".hta" extension makes a big difference!) You can then run your test suite just like any other Selenium Core test, but since the tests are being run in HTA mode, you're free to run your tests against any website.

You can also run TestRunner.hta from the command line, passing arguments to it just like you would pass arguments to an HTML file, like this:

C:\selenium\core>TestRunner.hta "test=..%2Ftests%2FTestSuite.html&auto=true&close=true&resultsUrl=results.html&save=true"


Advanteges of HTA mode:

  • Can use tests against other sites
  • Suggested use: Regression testing against a site being rebuilt.

Disadvantage of HTA mode:

  • Only runs with IE