Regular Expression - Sed

Helpful Sed one-liners commands.

REM Delete empty line
sed -e "/^$/d" 1x.txt > 2x.txt

REM Delete all newline.( Concatenate each line of 1x.txt into 1 line of string )
sed ":a;N;$!ba;s/\n//g" 1x.txt > 2x.txt

REM Print line without 'code'
sed -n "/code/!p" 1x > 2x.txt
REM In bash shell, use single quote.

REM Delete line 2 up to line 10 inclusively.
sed -e "2,10d" 1x.txt > 2x.txt

REM Skip the 3rd line(Replace 'a' with 'b' for all lines except the 3rd line).
sed -e "3n; s/a/b/g" 1x.txt > 2x.txt

Regular Expression

Regular expression is an expression that describe the pattern of characters or strings.

[a-z, 0-9, _]*: Permit strings that contains a-z and/or 0-9 and/or _.

Selenium - Locators

In order for Selenium to control and manipulate each HTML element(e.g. <a>, <input>, <div>, etc) on the website, you have to provide it with a reference to each element. That reference is used by Selenium to identify the element and apply the actions on that element. The term used in Selenium to denote the reference of an element is called locator.

TestNG - Run specific groups of tests

One of the nice features of TestNG is that it allows you to run specific groups of tests among all the tests that you have written. In my case, this feature is handy when I want to run read only tests on the production environment. The idea is to associate each test method to a group. When you want to run each group of tests separately, you only invoke your desired groups through the configuration file of TestNG. The following shows you how to do it.

  1. To associate a test to a group, simply specify the group name in the groups attribute of the @Test annotation.

Java - Installation of JDK

JDK is the software development kit for creating Java programs. Instructions below show you step-by-step how to install and set it up.

  1. Download JDK. Install it and follow the instructions shown on the screen.
  2. Now that the JDK is installed, you have to add the binary folder path of the JDK to the PATH environment variable of your MS Windows.
    1. Depending on the version of your MS Windows, the steps below may be different but similar.


Java programming language

Selenium - Misuse of waitForPageToLoad()

The common mistake that people usually do is to use waitForPageToLoad() function to wait for what appears to be a webpage being loaded. But, in fact, it is Ajax or JavaScript that is doing some changes to a portion of the webpage. As a result, the waitForPageToLoad() function will always time out because it is expecting for the whole webpage to load that never happened.

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.


Subscribe to RSS