Selenium

Selenium is an easy-to-use and popular open source web applications Test Automation tool.  Now a days’ lot of enterprises and ISVs (Independent Software Vendors) are looking out for open source tools. Open source communities are strong and getting support is also easier than for the licensed tools.  Best example for this is LAMP (Linux, Apache, MySQL, PHP) which is used for web development and Selenium, used for test automation.

Selenium provides lot of features for test automation such as easy recording and play back of tests using Selenium IDE.  Selenium supports multiple platforms, browsers, and programming languages.  Especially, supporting multiple programming languages such as C#, Java, Ruby, Python, PHP, Groovy, etc is really fascinating.

This blog explains test automation with Selenium from the scratch in a tutorial manner.  Even if a tester who does not have any prior automation testing experience can also start learning Selenium by going through the various posts in this blog.  Blog posts cover lot of topics such as Recording tests with Selenium IDE, setting up Selenium with Eclipse, learning Java concepts and programming, understanding Selenese methods, writing data driven tests with MS excel, CSV, XML, etc.  These topics are explained in a manner that will help the readers to understand the Selenium easily.

Below is an Index of Topics covered in the blog on Selenium:

Selenium Basics:

  1. What is Selenium?
  2. How Selenium identifies the objects?
  3. Write XPath to identify the objects
  4. Record tests using Selenium IDE
  5. Sample application to learn Test Automation – Sugar CRM (an open-source CRM application )
  6. Learn Selenium Step-by-Step
  7. Reading these articles together (one by one) is highly suggested to understand recording and running of Selenium Tests (sample application used in all these posts)
    1. Recording Tests with Selenium
    2. Export Tests into Java / JUnit and run in Eclipse
    3. Execute the tests with JUnit 4
  8. Assertions for verifying test output

Selenium and JUnit:

  1. Setting up Selenium with Eclipse
  2. Introduction to JUnit 4 annotations
  3. JUnit 4 annotations – Before vs BeforeClass
  4. How to write Selenium tests with JUnit

Parameterization Techniques:

  1. Parameterization with MS Excel
  2. Parameterization with CSV file
  3. Parameterize tests in Selenium IDE

Properties, Logs, and Reports:

  1. Parameterize global settings using properties files.
  2. Create Logs for step-by-step analysis of test execution.
  3. Generate HTML reports / XML reports for detailed summary of test execution.

Test Automation Framework:

  1. What is Test Automation Framework
  2. What are the features of a framework
  3. Designing a framework for Test Automation

The above topics are covered in the various blog posts.

{ 56 comments… read them below or add one }

Rakesh December 27, 2011 at 9:59 am

Hi seetaram,

How to handle pop up window with RC (java). I have confirm button to which i am clicking as
selenium.click(“css=input[type=\"image\"]“);
After this an popup appears.
I want to click cancel on the confirmation dialog but it always click on OK and proceeded to next page. The confirmation dialog not flashes even. If doing manually it is coming up fine.

Used selenium.chooseCancelOnNextConfirmation() but still it immediately goes to next page and cancel the things.
So my query is how to handle these pop ups with RC
Thanks

Reply

seetaram January 2, 2012 at 7:27 am

use selenium.chooseCancelOnNextConfirmation() for Javascript popup. use Selenium IDE and record once. Check the code Selenium IDE generates and find out is it selenium.selectWindow. Then code accordingly…

Reply

SriRam January 13, 2012 at 10:47 am

there is no dynamic wait method in web driver like selenium.waitforPageToLoad(),

could you please provide solution for that.

Thanks,
Sriram.

Reply

Stavan May 16, 2012 at 5:46 pm

You can write your own method using while loop.
Example:

boolean status = true;
while(status){
if(driver.findElement(By.id()) != null){
status = false.
}
}

Reply

surya January 18, 2012 at 8:37 am

What is the syntax of XPATH,CSS,DOM ?(In Seleniuim)

Note: i got the Xpath but i am unable to find the CSS & DOM syntax in selenium. can you please explain for CSS & DOM.
please send it to my mail.

Reply

Vishal Aggarwal January 20, 2012 at 1:11 pm

Thanks Seetaram …!!! It’s one of the most comrehensive site on the internet on selenium, covering all important topics at one single place.

Reply

tester January 20, 2012 at 1:54 pm

Thank You for all your efforts

Reply

tester2 February 2, 2012 at 2:01 pm

Best site ever! Thanks a lot and keep up the good work!

Reply

Mini Chakiyar April 4, 2012 at 5:41 pm

Hi Seetharam,

Many Many thanks for the detailed information about selenium. its helping us a lot. I am looking for documentation on integrating CI server with selenium tool. Can you please share any info on this

Regards,
Mini

Reply

seetaram April 16, 2012 at 12:40 pm

I have not prepared any documentation as such.. I can provide you the steps to integrate with CI server such as Hudson…
1. Generate HTML reports through Ant
2. If the reports are JUnit reports Hudson has an inbuilt support for JUnit
3. Create a Job on Hudson and invoke the ant build file from Hudson job. Run the ant target from Hudson job
4. Configure the Hudson to display your test results. For this, there is an option on Hudson

Reply

priyanka April 10, 2012 at 5:22 am

excellent site !!!

I have created two java files ie
testscripts.tests.Login_version1
AddProcessingStep

And configured the xml file as shown below at default location.


Now Could you please explain how to run this test suite?

When i did right click on a specific java file , and run through test ng only that file will get executed.

Kindly have a look.

Thanks,
Priyanka

Reply

seetaram April 16, 2012 at 12:24 pm

need more clarification.. on what you are doing…I am not able to understand what xml you have created…

Reply

Murali Krishna May 18, 2012 at 10:56 am

Hi Seetharam,

Many thanks for details information provided for selenium in a simplest form.
But one thing to be rectified.
There is a mismatch between the name of the link and the launch page content.
for example the name of the link is “Export Tests into Java / JUnit and run in Eclipse” when i click this the link goes to the page “Selenium – Setting up Selenium & Eclipse”. here both are different pages.
kindly check and rectify these type of mistakes. sorry to pointing about this.

Reply

seetaram May 18, 2012 at 3:54 pm

Many thanks for showing me the issue… definitely will be rectified…

Reply

Uma May 22, 2012 at 5:42 am

Hi Seetaram,

Thank you for providing valuable information regarding Selenium tool.

With the help of your tutorial, it has been very useful for us to record and run the scripts.
I have a few Queries listed below.
1. There are 3 types of Selenium tool – IDE, RC, and Webdriver. Which one will be the best for testing the UI based project which I am testing?
2. How we test the database(DB) testing through selenium? What is the command and target?
3. For Image/table/button… testing we can use XPATH expression for validating. Am I correct? If yes what is the command that we use to validate?
4. How we parametrize the data through (XL) and import them to selenium?
5. Is the JavaScript knowledge really need to test the UI App. using Selenium tool? Why Iam asking is, I don’t have any knowledge about Java since i am a manual tester.

It will be very useful if you send me the answers for the above Question to the above E-mail address as soon as possible.

Many Thanks,
Uma.R

Reply

seetaram May 25, 2012 at 3:18 pm

Hi Uma,

All of your questions are answered in the blog through various articles. You need to go through the blog.

1. It is better to use WebDriver as it is the latest Selenium and uses browser specific drivers.
2. Use JDBC – already explained
3. Use getText method of webdriver / selenium – explained
4. XL – explained in the blog
5. Absolutely no need to have any knowledge of JavaScript but knowledge of Core Java is very much essential.

–Seetaram

Reply

CJ May 25, 2012 at 8:07 am

I’m learning Selenium and find your blog helpful. I’m not able to get your code to run as a JUnit test in the Eclipse IDE and don’t really understand how to debug the lengthy failure trace log.

Nonetheless, the tutorials have been helpful, even if I can’t run the code successfully.

Also wanted to mention that all of the links listed under the title “Test Automation Framework” in the table of contents (above) all point to the same page.

Thanks….

Reply

aileen May 30, 2012 at 3:02 am

Hi Seetaram,
I’m new to Seleniume and Java, I found our blog is really helpful. But I have some problems when I start to use Seleniume with Eclipse.
1. Failed to start browser other than IE. I tried to use both “*chrome” and “*firefox” to setup a seleniume session, however, I always received an error message “can’t enable testing browser”. Actually the seleniume server launched firefox by default event I use “*chrome”.
2. How to keep the test result web page? After the test ends, the test result web page is closed automatically.
3. I read some comments raised by other people that we need to add seleniume server.jar to the java project, I’d like to know why. I tried with my Eclipse, if I only add client-java.jar to the project, a lot of “class is not found” errors will be reported. If I add server.jar to the project and remove client-java.jar, those errors disappears.
4. About extends SelenseTestBase. If I remove “extends SelenseTestBase”, the test can also be run. Can you give more explanation about “extends SelenseTestBase”, do we need to extends this class ?

Thank You.

Reply

seetaram June 7, 2012 at 2:52 pm

Download the latest Selenium from Seleniumhq website. Download mozilla firefox 12 (latest) and then try to execute.. I hope this will work. Regarding the 4th point, you need to learn inheritance concept in Java.

Reply

Prabhu July 6, 2012 at 6:25 am

Hi Seetaram,
I am unable to solve a problem.Please help me out.My Problem is i have to parameterise the values inside the setup() method instead of hard coding these values i.e)new DefaultSelenium(“localhost”, 5555, “*chrome”, “http://www.google.co.in/”); Any help is appreciated.

Thanks in advance
Prabhu

Reply

ravi July 31, 2012 at 4:44 pm

Hi prabhu,

you can parametrize the values from XL file Or CSV file. Also you can use Object repository.
Selenium does not have Object repository so you need to create that.

Reply

sudheer kumar July 11, 2012 at 12:24 pm

Hi,
Can you please tell me how to use selenium for Cognos Reports’ Data validation.
And give some meterials for datavalidation with selenium..
thanks in advance

Reply

Amit July 11, 2012 at 1:03 pm

Hi , Thankyou for nice post.

I need to spanshot every page on a website . I have crawled the site and have the links of all pages on that site. How can I take snapshot of every pages of website . Can it be done using selenium logging .
I need snapshot of particular webpage in particular browser like how this webpage look like in crome and mozilla etc.,

Reply

seetaram July 29, 2012 at 12:56 pm

Use selenium APIs to grab the screenshot

Reply

PA July 12, 2012 at 4:19 pm

Hi Seetaram … My client wants to read values from and store values to a MySQL DB … similar to how v do in excel … what is the best way to do this … I could not find any solution online … currently I am able to read ONLY one set of values from DB and pass this test data in webdriver … My sample DB has 2 columns : email and password and I have email1, password1; email2, password2, email3, password3 as testdata in the DB table … currently the browsers open and pass the first set of values email1 & password1 and execute the test … How do I increment to the next set of data … any help is appreciated … Thanks in Advance

Reply

seetaram July 29, 2012 at 12:51 pm

Use JDBC

Reply

ravi July 31, 2012 at 4:46 pm

Get the dataBase values Using JDBC and store them in List and pass to the Emai2..password2..like in for loop

Reply

Kaustubh July 14, 2012 at 6:45 pm

How to handle page object modeling pattern for any E-commerce website??

Reply

seetaram July 29, 2012 at 12:50 pm

Design the framework according to your page object modelling requirements

Reply

ravi July 31, 2012 at 4:49 pm

This is a design Pattern where you need to create one Java class(ie:one Object) per page. So while writing test cases you will be communicating internally among the classes.
Example
HomePage.java->>LoginPage.java–>>UpdateProfile.java..–>Signout.java..

Regards,
Ravi

Reply

Archi September 24, 2012 at 8:09 am

Under Selenium Basics:, there are 8 links, please let me know the sequence in which it has to be read.

Reply

seetaram October 2, 2012 at 6:35 pm

Please explore, expectation is too much!!!

Reply

Pooja Mishra October 10, 2012 at 6:34 am

Hello Seetaram,

Good morning,

Can u explaint the data driven frame work ..from scratch..as m new to selenium…but i automated my application a bit in eclipse -junit and now thr are some modules where i need to change the data everytime…else because of duplications it throws error..for that i need to make use of excel sheets for taking the data and running the application,Seetaram can u plz tell me form scratch and also i need to invoke the eclipse and then go to the project and then run it ….code for that…..i need it ….as we do in QTP …i want the same in selenium….

please do reply …i really need it….

Reply

Sunil October 29, 2012 at 3:16 pm

great job!!! seetharam

Reply

Andr November 14, 2012 at 6:35 pm

Seetaram,
thank you for this site. all very informative in one place. keep the site going.

Reply

RK December 19, 2012 at 8:49 am

Hi Seetaram,

I have come across a situation where i need to automate Clarify CRM application with Selenium. I already automated it with QTP. now we need someother open source to automate the same. Do we have any support for Clarfiy CRM in Selenium? plz advice on any possible way to automate Clarify CRM using Selenium. Thanks in advance.

Reply

kumar February 14, 2013 at 7:11 pm

Experts writing here..nice to see that and thanks a lot for doing it.

Reply

Srikanth February 20, 2013 at 2:44 am

Hi Seetaram,
Thank you for providing usefull information.
If Interviewer asks “Tell me about your selenium framework” .How can i explain that?
Help me out.

Regards,
Srikanth

Reply

seetaram March 7, 2013 at 6:06 am

If you have worked on test automation framework then you should be able to explain about the framework you have worked…!!!

Reply

Padma April 24, 2013 at 5:25 am

Hi Seetaram,

I am planning to learn Selenium with TestNG framework on my own. I need your suggestions.

Thanks,
Padma.

Reply

Riya April 24, 2013 at 7:28 am

How to get the screenshot on each failure in webdriver.

Reply

sai May 8, 2013 at 3:59 am

How to capture the salesforce native reports into Excel format. we can able to get the screenshot and store it, but how can we extend it to excel format..

Please !!

Reply

Sruthi May 14, 2013 at 4:52 am

Hi All,

I am unable to convert the String Data Type to Any Other Data Type. Can Any one Help me on this.

Reply

Vinai Theertha Perumal May 21, 2013 at 6:21 am

In selenium Driver how to automate the telerik autocomplete field.

Reply

pavan guptha June 13, 2013 at 12:52 pm

Hi Seetaram,
Could you please provide me exact material for JAVA that is suited for selenium beginner.

thanks,
pavan
id: guptha239@gmail.com

Reply

seetaram August 21, 2013 at 8:59 am

Core java is enough

Reply

Sasmita Sahoo September 2, 2013 at 9:04 am

Hi,
I need a help. I want to automate one e-commerce site. how will I do it means how I show it as my automation project. Plz suggest.

Reply

seetaram September 2, 2013 at 12:33 pm

Are you working on the e-commerce project? If yes, then you can definitely show that as you have worked on that project…. :-)

Reply

Madhu September 23, 2013 at 10:15 am

Hi,

I am using Eclipse webdriver, can you please let me know how to select radio button in flight application (newtour.demoauto.com).

thanks,
Madhu

Reply

seetaram September 25, 2013 at 6:12 am

Try to understand the basic things like:

1. What is Selenium?
2. How it works?
3. How it identifies the objects on the AUT
4. Core Java knowledge
5. Start recording few scripts using Selenium IDE and generate the code and copy to Eclipse. Execute it.

If you understand all the above then I don’t think that you will have this question.

Reply

Punitha January 6, 2014 at 8:48 am

Hi ,

If i click on modify link two conditions are available:

1.When transactions present we cannot modify the page
2.Transactions are not present so we can modify the page

How do i capture the two conditions?

Reply

seetaram January 10, 2014 at 6:53 am

Need to check the application, I cannot judge just based on the comment.

Reply

Rajendra Prasad Reddy Penumalli January 31, 2014 at 12:45 am

Hi Sitaram,
I am rajendra from Bangalore and i have 9+ years of experience in testing in both Manual and Automation.First of all i thanking you for sharing knowledge on Test Automation.
Now in our company as part of COE activities, we are creating a Generic Selenium 2.0 based Hybrid Test Automation Framework(A mix of Keyword+Data Driven ).
Also we would like to include DB Verifications,Application Log File Verifications(for Errors and Specific Strings in Logs) and XML verifications ..etc
I did an extensive research on different types of frameworks and the types of web applications we normally do in my organization.
I would like to use following Software combination :
Selenium 2.0
log4j – For logging
JDBC -for Database Connectivity
XML SAX Parser -XML Parsing
jsch-0.1.47.jar for executing commands on remote application server over ssh
Eclipse Juno 6 bit
Test NG..etc
But here i understand how to write a Keyword Driver with Switch- Case statement , but i am not getting any idea to link Test NG Assertions.
As you know in Keyword driven framework we will drive the test based on the vertical sequence of the ‘keywords’ in XL sheet with corresponding row cell locator.
For example if any step fails or if actual and expected results is not matching during the test execution i would like to report specific reason for that failure.
Also I want to generate XLST reports.
My Questions is: is it possible to use Test NG with Keyword Driven Framework?
Could you provide a sample code for this implementaion?

Thanks,
Rajendra Prasad Reddy
+91-9008566233
Bangalore

So we are planning to :

Reply

seetaram February 19, 2014 at 8:55 am

Quesiton: But here i understand how to write a Keyword Driver with Switch- Case statement?

[Seetaram]No need to write switch case, instead use Reflection mechanism

If you want to use Keyword-driven approach, then there is no need to use TestNG, instead use the main method which will be the starting point of your execution. TestNG itself is a framework which provides lot of facilities for the automation of testing activities.

Your framework could have the following components:
1. Script reader which reads the test scripts from the excel sheet (Entire excel file can be one TestSuite wherein each excel sheet can have one test case)
2. Executor which will use Recursion & Reflection mechanism to read the test script until the end of script and then find out corresponding Java method
3. Result of every test case execution should be kept in some List or Map
4. At the end of all the execution generate an HTML report. Use templating engines or any Reporting engines for this purpose
5. Write your own Exceptions which will be thrown by the executor and then logged using log4j

I hope this will help you,

If you need any more information please feel free to send me an email at seetaramhegde@gmail.com

Best Regards,
Seetaram

Reply

Kiran February 20, 2014 at 3:02 pm

Hello Folks,

I am new to automation testing have been working on manual testing and i don not know any programming languages, is it easy to learn selenium.
Please suggest me

Thanks
Kiran

Reply

Ketki February 27, 2014 at 6:13 am

Select sel=new Select(driver.findElement(By.id(“reg_height”)));
Thread.sleep(3000);
sel.selectByIndex(13);

Above code is working for height selection in matrimony site .
Following code for selecting country but it is not working:
Select sel1=new Select(driver.findElement(By.id(“reg_country_res”)));
Thread.sleep(3000);
sel1.selectByIndex(22);

Can somebody help ?
Thanks,
Kaetki

Reply

Leave a Comment

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email