Pragmatic QA

Setting Up a Test Project With Selenium, TestNG and Maven

| Comments

It is useful to Selenium and TestNG using an IDE, but in the real world projects are not restricted to the use of IDE. Projects need build tools like ANT or MAVEN to compile, install, deploy and run the application.

I am involved in couple of projects that use Maven as the build tool, although Maven is more than just the build tool. It covers the complete life-cycle of the project and testing is a pivotal part in project life-cycle especially for projects that tend to follow TDD and Acceptance Test Driven Development.

In order to achieve this you need to install java and maven2 on your machine. Make sure that you have set the JDK_HOME and M2_HOME directory correctly.

Once you have done this, you can open a terminal on your screen and go to your default workspace or the directory where you want to create the project.

List Directory Structure in Unix/Linux

| Comments

Today I found a really useful combination of commands to list the directory structure in Unix/Linux operating systems as follows.

lang: bash
1
ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/\[^-\]\[^\/\]*\//–/g’ -e ‘s/^/ /’ -e ‘s/-/|/’

The result of this command is as below. It is listing the directory structure under the functionalTests directory.

lang: bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
functionalTests haroon$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/
   |-src
   |---main
   |-----java
   |-------com
   |---------pragmaticqa
   |-----------tests
   |---test
   |-----java
   |-------com
   |---------pragmaticqa
   |-----------tests
   |-target
   |---classes
   |-----com
   |-------pragmaticqa
   |---------tests
   |---surefire-reports
   |-----Command line suite
   |---test-classes
   |-----com
   |-------pragmaticqa
   |---------tests

You can also use Unix tree command to list the directory structure, as of writing this one I was not aware of the tree command.

Funny Assertion!!!

| Comments

Today I came across a piece of code while debugging some tests, that I thought of sharing with everyone. It was not easy to select a title for this post, but I am going to stick with “Funny Assertion”.

lang: java
1
2
int termsCount = termIDs.length;
assertEquals(termsCount, 4, "There should be three terms under Genres");
Result:
java.lang.AssertionError: There should be three terms under Genres
Expected :4
Actual   :3

The tests expects the termsCount to be 4 in under Genres, but the comment in the assertion expects the term count to be 3. In a single line of code, you can see contradiction.

Although this looks funny, but it does present me the opportunity to highlight the problem of ignoring the comments in the assertion. Often we ignore the comments in the assertion while developing tests but it leads to misleading test results, and misleading test results then lead to time wasted on debugging non issues.

The comments in the assertion is a very powerful way to communicate the expected behaviour of the assertion or the test results to your fellow developer. The comments in the assertion can serve as documenting the test results.

If the assertion was written correctly then it was obvious that the test expects the termsCount to be 3 because the comment in the assertion is pointing to the fact that when the test was developed, the test developer expected that there will be 3 terms under a give condition. This would make it easy to debug the application.

As my personal preference, I see it really beneficial in having comments in the assertions. We should learn the lesson from this and give proper consideration to the comments in the assertion.

Tellurium and Test Automation Process

| Comments

Today I will focus on how Tellurium fits into test automation of a large scale project and how easy and effective it is to use Tellurium. Test automation with any testing tool involves following main stages.

Planning Tests –> Developing Tests –> Running Tests –> Analysing Results

Planning Tests

As a test automation engineer, this is the foremost thing you would do. We should treat any test automation project in the same way as we would treat a development project. We should keep all aspects of software engineering in mind such as Readability, Re usability, Modularity and Maintainability.

At this point you should define clear objectives for test automation, you also need to analyse the application under test and determine that which objects and operations are used by the business processes that you are going to automate. You also need to define the data set up and tear down so that your tests starts from a known state of the database and after the test execution tear down the data that it has created during test execution, so that you can run these tests on different environments. This would also ensure that your tests do not leave the database in inconsistent state.

Selenium RC and Pop-up Handling

| Comments

Recently I have been asked by one of the readers about the pop-up handling in Selenium in general and Selenium RC in specific. As per my understanding Selenium IDE does not support recording on the pop-ups because If the popup is a new window, i.e., not in the html body of the main winodw, Selenium IDE, Dom Inspector, and other Firefox plugins do not work. The reason is there are multiple document variables to handle and it might not be a good idea to record any popup window which make the event listener more complicated.

Setting Up Selenium & TestNG Using Eclipse

| Comments

I found that it is not easy for the beginners to setup Selenium RC and run the GoogleTest.java example after downloading it from www.openqa.org . The purpose of this post is to help beginners (new users to Selenium RC) help setting up Selenium RC with TestNG using Eclipse.

This assumes that you have done the following steps.

Download and install Eclipse (www.eclipse.org)

Download the latest TestNG (www.testng.org)

Download Selenium RC (www.openqa.org)

Install TestNG plugin for eclipse (http://testng.org/doc/download.html)

Please follow the step by step instructions to setup the test environment.