Selenium Scripting: A How-To for Beginners


Selenium Scripting

Selenium is an open source tool which is used for automated testing of web based applications. The tool is very simple and easy to use. It is widely used for functional testing of browser based applications developed in any technology.

Our first selenium based functional test:

Selenium can be used to write tests for high level programming language for example – Java, C#, Ruby, Python etc. The most important concept, which one should learn before learning Selenium, is the PageObjects. PageObject is an object oriented library which is used to build test suits for web applications. It is very useful for applications which follow the MVC pattern as it can separate test code into Model, View and Controller patterns. A very basic selenium test case is developed by extending the class ‘SeleneseTestCase’. Here we have a setup method which is used to point the basic URL of the application along with the browser name.

Selenium RC and Selenium Grid Installation and execution:

Based on the programming language of our choice, selenium has a set of libraries available. We can download these libraries from the following URL –

In our document we will follow the Java Programming language –

  • Step 1 – Selenium RC is simply a jar file. Usually the name of the Jar file is – Selenium-Server-Standalone-<Version-Number>.jar. This does not require any special installation. Just download the zip file and extract the library in some location on your system.
  • Step 2 – Make sure you have the correct version (Ver 1.5 or higher) of Java installed on your computer. Also make sure the environment variables like JAVA_HOME and PATH should be appropriately defined. To ensure that Java is working fine on your system, just type the following on your command prompt terminal –

java –version

  • Step 3 – Running the selenium server – Simply open a command prompt terminal and go to the directory where you have extracted the zip file mentioned in Step 1. Execute the following command –

java –jar Selenium-Server-Standalone-<Version-Number>.jar

You can simply create a batch file which has the above command, so that every time you do not need to type the above command.

Using the Java Client Driver:

  • Step 1 – Download the Selenium java client driver zip file from the URL –
  • Step 2 – Once the download is over, extract the Selenium-java-<version no>.jar
  • Step 3 – Open your Java IDE and create a Java Project.
  • Step 4 – Add the library Selenium-java-<version no>.jar

Now you are good to start writing your selenium script with the help of java programming language using the selenium-java-client API.

Selenium test cases can be easily integrated with JUNIT. Once written we can simply execute the JUNIT test suite which in turn will execute the selenium test cases and produce the report of our needs.

In addition to these, we can use Selenium to test the java script code of an application.

The most important advantage of this approach is that, once written, we can save the scripts and it can be executed on different environments.

Considering the above features, we can conclude that Selenium is one of the most important tools for automation testing of browser based applications.

Tagged on: ,
============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric

Enjoy this blog? Please spread the word :)

Follow by Email