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.

Comments 66

  • 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

    • 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…

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

    could you please provide solution for that.

    Thanks,
    Sriram.

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

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

  • 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.

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

  • Thank You for all your efforts

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

  • 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

    • 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

  • 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

  • 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.

  • 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

    • 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

  • 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….

  • 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.

    • 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.

  • 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

    • 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.

  • 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

  • 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.,

  • 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

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

    • Design the framework according to your page object modelling requirements

    • 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

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

  • 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….

  • great job!!! seetharam

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

  • 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.

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

  • 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

  • Hi Seetaram,

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

    Thanks,
    Padma.

  • How to get the screenshot on each failure in webdriver.

  • 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 !!

  • Hi All,

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

  • In selenium Driver how to automate the telerik autocomplete field.

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

    thanks,
    pavan
    id: guptha239@gmail.com

  • 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.

  • 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

    • 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.

  • 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 :

    • 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

  • 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

  • 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

    • what is the error you are getting?? i thing the issue is with the loacting technique, You can use Xpath instead of ID.

    • what is the error you are getting?? i thing the issue is with the locating technique, You can use Xpath instead of ID.

  • Hi Sitaram,
    I am trying to automate a WebRTC (Real Time Communication) Application ,designed on HTML5 and it runs on Chrome browser .
    In this application i need to access and capture the input from the Microphone or Camera from web application.

    When i click on capture button, chrome is showing info bar(a kind of popup alert) with “allow” and “deny” options., Since this info bar i cannot handle with Selenium web driver.

    After doing for research i came to know that ,If i manually launch chrome browser from command line with a switch “–use-fake-ui-for-media-stream” chrome is allowing to access the camera without info bar.
    Example: C:\Users\user>start chrome –use-fake-ui-for-media-stream

    But if try the same with simple web driver script i am still getting the info bar with same allow and deny options how to to suppress this info bar as it worked manual chrome browser launch from command line? :
    here is my code:

    import java.io.IOException;
    import java.net.URL;
    import java.util.Arrays;
    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    public class UseChromeSwitch {
    public static void main(String[] args) throws IOException {
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(“chrome.switches”,Arrays.asList(“use-fake-ui-for-media-stream”));;
    RemoteWebDriver driver1 = new RemoteWebDriver(new URL(“http://127.0.0.1:4444/wd/hub”), capabilities);
    driver1.get(“http://www.html5rocks.com/en/tutorials/getusermedia/intro/”);
    driver1.findElement(By.id(“capture-button”)).click();
    }
    }

    Note Before running above code you need to run the from command line:
    java -Dwebdriver.chrome.driver=”C:\chromedriver.exe” -jar “C:\selenium-server-standalone-2.41.0.jar”

    Note: Please try this on laptop which has builtin camera otherwise you cannot access the camera.

    Thanks,
    Rajendra

  • Hi Seetaram,

    Is there any ready automation framework available which built on Selenium, so that we can start building our test scripts?? Which includes reports generation, Version control and with the Continuous integration support??

  • I have one bottleneck.

    When I am running selenium scripts through eclipse ,Excel results got updated.But when I ran through ANT instead of eclipse.Resutls were not written into excel.

    Can any one please tell me ,what may be the problem ?

  • please anybody help below issue
    i need real time challenges in e commerce website while writing test scripte in selenium.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.