Selenium - Where to put Selenium.stop() within testing framework?

When using Selenium with a testing framework such as JUnit or TestNG, it is better to put selenium.stop() in the "closing method"(i.e. @After*) instead of in the test method itself. In this way, if tests failed, then the testing framework will be able to close the browser. Thus, you will save a lot of computer resources if your tests are opening and closing the browser thousands of times.

Code below show that TestNG will close the browser even the method failed.

Selenium - Speed benchmark of locators

Selenium locators are not all equals. Some locators are faster than others. Therefore, I took up the task to measure the speed of each Selenium locators. The speed test that I did is to measure the time that each locator took to fill up the 1st 50 input fields of the 500 inputs fields. From the results, ID locator is the fastest.

Selenium - First Selenium application in Java

The following shows you step-by-step how to run your first Selenium RC application in Java.

  1. It is assumed that you have JDK installed and set in your computer. If you are getting the version number(e.g javac 1.6.0_06) by running the following command in the Command Prompt, then your Java Compiler is installed and set correctly.
    javac -version
  2. Download Selenium RC.



Selenium is a tool that employs Javascript in order to take control over your browsers and simulate web surfing activities. Therefore, Selenium is able to replicate any action typically undertaken by a user, such as clicking, typing and retrieving data from web pages.

When combining Selenium with other testing frameworks such as JUnit or TestNG, you are getting a very powerful and complete testing framework for web applications.



  • Apache is installed.
  • PHP is installed.
  • MySQL is installed.

To check if you have all the requirements, do the following steps:

  1. Paste <?php phpinfo(); ?> into a text editor and save as info.php
  2. Copy info.php into the root directory of the webserver(eg. htdocs folder)
  3. Open with an web browser You should see PHP Version X.X.X and MySQL Support. Otherwise, some requirements are not installed.

TestNG - Execution order of TestNG's annotations

Codes below show the execution order of commonly used annotations of TestNG.


TestNG is a java testing framework. It was created by Cédric Beust out of frustration over JUnit's deficiencies. It was designed to cover all categories of tests such as unit, functional, integration, etc.

The idea is very simple. It is breakdown into the following steps:

  1. Create your class.
  2. Create test scenarios by using methods of your class and then you have to implement the logic to check whether the methods behave correctly or not. If they do, then tell TestNG that it is good. Otherwise, tell it it is bad.

JUnit - Parameterized Tests

Sometimes you want to use a generic test method to test with different sets of values. But if you use a loop to do that, then the whole method will fail if 1 of the set of values fails. As a result, it is not helpful as you don't know which specific set of values failed. JUnit report will only show that the generic test method as a whole failed. But if you are writing 1 test method per set of values, then there is a lot of codes, which is not efficient and practical.

JUnit - Execution order of JUnit's annotations

 * Show the execution order of each annotations.
 * Given this test, the methods will execute in the following order:
 * oneTimeSetUp()
 * setUp()
 * testMyFunction1()
 * tearDown()
 * setUp()
 * testMyFunction2()
 * tearDown()
 * oneTimeTearDown()
 * **NOTE**: JUnit doesn't guarantee the execution order of the test functions(@Test).
 * @author: Xuan Ngo
import org.junit.*;
public class JUnitCheatSheet
  public static void oneTimeSetUp()
    // one-time initialization code


JUnit is unit testing framework for the Java programming language. It allows you to easily verify the individual unit of source code through assertions.


Subscribe to RSS