Sunday, September 5, 2010

Configuring Selenium RC with TestNG using eclipse

Recently I was trying Selenium RC with TestNG using eclipse. I found it little tough without any proper step by step documentation. I took help of my collegues and completed. In fact I am not using this tool in my project but I always try to find time to work with selenium. After all you can not stop your learning :)
This tool is pretty good and rapidly taking place in market.

Any way I had successfully ran a sample test case using TestNG in eclipse with selenium RC. While it was starting but decided to post one article on “Configuring Selenium RC with TestNg using eclipse” to help testers those who want to start with same. I also maintain my blog as a database for self reference. So if you find it beneficial for you, you can write few words and if not then you can ignore :(



Finally here, step by step process to configure and run your first java test using TestNG and selenium RC in eclipse

1- Install JRE http://www.java.com/en/download/
2- Download eclipse http://www.eclipse.org/downloads/
3- Download TestNG http://testng.org/testng-5.14.zip
4- Download selenium RC http://seleniumhq.org/download/
5- Launch you eclipse

The workspace, you can select any working directory. In my case it’s “Selenium_Project”


Now clicking on Ok button, it will launch eclipse.




6- Install TestNG plugin

Go to help->install new software






Click on add. This will open a small window where you need to put location “http://beust.com/eclipse”.

Click on OK. You will see that an entry is added there. Now tick that box and click on next.



7- Add project

Click File->new->Java project

Give project name and finish


 

 
This will create project “MyProject”




8- Add TestNG jar to library

Select MyProject and then Go to (menu bar) project->properties->Java build path->Libraries



Click on add external JARs and add TestNG jar file (testng-5.14.jar) from folder which you get after downloading TestNG in step#3.



9- Add Selenium RC jar to library

Add selenium Jar file same way we have added testNG jar. Selenium jar file can be found in the “selenium-java-client-driver-1.0.1” folder which you get after downloading it in step#4.





10- Add Class file

In MyProjectt right click on scr folder then new->class


Name the class (e.g Login) and finish.


Now add your test code here under this class. As in my previous article I had mentioned that you can simply record your test using IDE and pick java code and use here. For more detail refer : http://vishalsachan.blogspot.com/2010/06/hi-folks-sorry-for-bieng-inactive-from.html



11- Run test

Run your clas file as TestNG





Ohh i forget one step here. before executing test/running class file you need to start selenium server. thia is similar to every time so i am just copying it from my previous article.



To start the selenium test server, first go to the location where your JRE is placed. For example
C:\Program Files\Java\jre6\bin\
and then Run the command java -jar selenium-server.jar
here it is supposed that you have placed your selenium -server.jar file in same location. In case if you have placed it in other location you can run it in following way:

C:\Program Files\Java\jre6\bin\java -jar jar “E:\SELENIUM\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1\selenium-server.jar”

This will start you selenium server.


Thanks.
 

Thursday, July 1, 2010

Selenium IDE: Use XPath if no id found in elemnet you want to work with

If you are working with IDE and recording your script. There may be some cases where you IDE can not record the action to the element that do not have any id. In such case you need to find the id manually and provide it to the script to cover your action. XPath help you here to navigate your site.

In one of my project when I was recording my script for create a post, I found that IDE is unable to record the text box activity. Actually that text box was Javascript content editor 'Tinymce' . Later I recognized that IDE is unable to find this editor as there was no label used for this. So I used X paths to locate the element ID. It looks like..
id('commentBodyField')

The XPath can be found using the Firefox plug-in. https://addons.mozilla.org/firefox/addon/1095
to find the XPath just right click over the desired element and click on view Xpath.

Tuesday, June 29, 2010

Monday, June 14, 2010

Testing web application using Selenium RC with eclipse

Hi Folks , sorry for bieng inactive from last few months. I was really busy these days. I respect all of yours comments and query. In fact I am not working with Selenium now but as you people asked me some queries on Selenium RC with eclipse in one of my previous article http://vishalsachan.blogspot.com/2009/09/using-selenium-rc-in-your-java-project.html

I am planing to write a use full article here where I will cover end-to-end testing your web application using Selenium in Eclipse. This is infact a detail version of my prev article mentioned above.

As said earlier I am not in touch with Selenium i.e I am not using this currently, so I will try my best to use my memory and old days 'R and D' to get it completed with high quality and quantity. Huaaaa

Here I will start with selenium IDE but will not go in detail as asuming that you people are comfirtable with IDE part. If you need any help in IDE then you can refer to other articles in this blog only.

Record and save you java script
1- Open Firefox and enter the URl to browse your application
2- Launch IDE from Tool menu.
3- Record your script
4- Choose the programing language as JAVA and save your script. To chose the language go to Option-> Clipboard formate and select Java-Selenium RC

Now you have a java code saved in your disk. I am making it simple and not covering scripting in detail. My motive is to teach you the end to end process of using this IDE and RC to run a simple test using Eclipse. Rest You can change your script as per your need.
Now we have ur test with us.
The next step is to open your eclipse and create a project.

1- Creating you java project in eclipse
The fiste stpe in eclipse is to create/add your project. To do this follow the steps below:
   -> Launch Eclipse
   -> Creat a java project named TestProject (for example)

2- Add Junit Library to your project
The next step is to add Junit Liabraries which consiste of following steps: 
  ->  Go to Project Properties
  ->  Go to Java Build Path
  ->  Click on Libraries tab
  ->  Click on 'Add Library' button
  ->  Select 'Junit' option from list and click on next
  ->  Select version 'Junit4' from drop down and click on finish.

4-Add Selenium Java Client Jar into Project:-
Once you added the java liabraries , the next step is to add selenium jar file. you can find it under selenium-remote-control-1.0-beta-1\selenium-java-client-driver-1.0-beta-1 folder what you have downloaded from

http://selenium-rc.openqa.org/download.html

To add this Jar file follow the below steps:
  ->  Go to Project Properties
  ->  Go to Java Build Path
  ->  Click on Libraries tab
  ->  Click on 'Add External Jars'  button
  ->  Browse and add the 'selenium-java-client-driver.jar' from the sourse where you had saved it.

5- Initiating the Selenium Test Server
To start the selenium test server, first go to the location where your JRE is placed. For example
C:\Program Files\Java\jre6\bin\
and then Run the command java -jar selenium-server.jar
here it is supposed that you have placed your selenium -erver.jar file in same location. In case if you have placed it in other location you can run it in following way:

C:\Program Files\Java\jre6\bin\java -jar jar “E:\SELENIUM\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1\selenium-server.jar”

This will start you selenium server.

6- Adding your test (Java class )  in our Project
To add you test (which you have saved earlier) as a java class file to the project (TestProject, already saved) follow the steps:
 ->  In eclipse go to create a new java class
 ->  Create it with name MyFirstTestCase (for example) and paste the code from the file u had saved it
 ->  Choose "com.thoughtworks.selenium.SeleneseTestCase" as its super class
 ->  Finish it

7- Modifying your test script (java class)
Once you are done with ur class file, it will look like,

Package.*
import com.thoughtworks.selenium.SeleneseTestCase ;
public class MyFirstTestCase extends SeleneseTestCases {
      public void setUp() throws Exception {
            setUp( " http://vishalsachan.blogspot.com/ " , "*firefox'); }

............ You test script..............
}

In case you want to run this in diff browser then simply you can change your script
setUp( " http://vishalsachan.blogspot.com " , "*firefox'); to setUp( " http://vishalsachan.blogspot.com " , "*chrome'); or whatever browser you need to run wid.

8- Running your test
Finally we are ready to tun our first test. To run this in eclipse you click on Run button
select option Run as "JUnit Test'

Ohh ya one thing I forgot to mention that if you  have eclipse with JRE version lower than 1.5 in Build Path
then might be the case when you run the test , it will show some error related to version not suporting. so for this remove the default Eclipse JRE and add JRE version 1.5 or mor to System Library in Build Path.
To add this follow the steps:
-> Go to Java Build path and select Libraries tab
-> Under this select JRE system Library
-> Remove your default one
-> Now click on add Library and select JRE system Library and click next
-> Add JRE
-> Now add this JRE to your class path

So finally I am done with your end to end execution of ur java test using selenium RC in eclipse. Thanks.

Thursday, May 27, 2010

Black box testing design techniques

Black box testing is testing based upon requirement.In this we don't consider the internal logic structure.
For example, here in black box testing, if any input is passed into the system and if the result is what was expected, then the test is passed.

Following are the design techniques for black box tests:
1- Equivalence class partitioning
2- Boundary value analysis
3- decision tables
4- Orthogonal arrays.

Now we will cover one by one in detail.

1- Equivalence class partitioning:
This technique is based on mathematical set theory. When your input domain is too large
then you break down this domain into finite number of sub domains (or sets). Now when you test you software, every value in
these set will be treated as same value. So you can pick one value from each set and test you software. This way you are
able to test the large set of data with few number of test only.

So the motive behind using the techniques is clear and that is to reduce the number of test cases to save time and cost.

Example:
Suppose in a software there is a field which except numbers from 1-100. now the range 1-100 is called as partition which is
a valid partition. Other than this there are two more invalid partition and they are: <=0 and >=101 . Now we can choose one
value from each of these partitions.

Valid partition is (1,2,3...............98,99,100)
Invalid partition 1 is (0,-1,-2,-3......... so on)
Invalid partition2 is (101,102,103,......so on)

Further Equivalence partitioning is no stand alone method to determine test cases. It has to be supplemented by boundary
value analysis.


2- Boundary value analysis:
In this case, we use the term boundary conditions to identify the set of allowable or inputs,
for a particular function. Testing boundary conditions includes testing inputs that fall outside the boundaries.
The boundaries are the values on around of the beginning and end of the partitions.
Here in a valid partition the beginning value is 1 and end value is 100. so the testable values will be like 0,1,2 and 99,100,101.

so this is something the boundary values for X will be X-1, X and X+1.


3- decision tables:

This technique of decision tables can be used as a method to identify all possible inputs or combination of inputs
for a test case.
A decision table is typically divided into four quadrants, as shown below

----------------------------
=
Condition = Input values
=
----------------------------
=
Action = Output values
=
----------------------------

4- Orthogonal arrays:
This is also known as taguchi method.

Let me explain why this comes into picture. The equivalence class portioning and boundary value analysis allow u test only
single value at a time and after that decision table start to look at combination of variables. But here the combination
can becomes very large very quickly. Thus the question becomes: how do you limit the combination without compromising
the quality.
Now the orthogonal arrays technique addresses this problem. The use of this is to determine the number of experiments require
to find best solution to given design problem by testing many variables at once.

An orthogonal array is a subset of combination of values for variables such that for every pair of variables,
every pair of values occurs an equal number of times.As an example, consider a module of code that has
three decision statements where variables A, B, and C can be true (T) or false (F)
All possible combination of the three variables A, B, and C with two possible values, true and false,
can give you eight test variations.(The number of combination is the number of values raised to
the number of possible variables, or 23 = 8.)

TTT
TTF
TFT
TFF
FTT
FTF
FFT
FFF

The orthogonal array for this example offer you only following four cases.
TTF
TFT
FTT
FFF


for the rule applied here and detail pls visit
http://www2.research.att.com/~njas/oadir/oa.4.3.2.2.txt