Like us on Facebook

LightBlog

November 25, 2010

Identify element using Firebug

November 25, 2010 0
In selenium we will identify the element by using firebug or xpath.

Firebug

First u need to install firebug in firefox..
Firebug is an addon for firefox. You can get firebug from this link "http://getfirebug.com/"

after installing firebug u can see a bug symbol at the bottom right corner of the firefox page.

Later follow below steps how to use firebug...
1. Open www.google.com
2. Click Advanced Search.
3. Take u r cursor on the  "Results per page:" dropdown. and right click in options u can see "Inspect element"
4. click inspect element.


5. You can see name= "num"



Hope this post is useful....

Print values in the dropdown using Xpath

November 25, 2010 2
Print values in the dropdown using Xpath
The below script explains you how to get the values in a dropdown and print the values to a notepad or excel sheet using the xpath...




import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Dropdowngooglexpath {
public Selenium selenium;
public SeleniumServer seleniumserver;

  @BeforeClass
  public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testDropdowngoogle()throws Exception {
selenium.open("http://www.google.com");
//click on Advanced Search Window
    selenium.click("link=Advanced Search");    
    selenium.waitForPageToLoad("5000");
     //Print all the available options from the results dropdown in the google advanced search page
//here i am using xpath to identify the element
    String[] option = selenium.getSelectOptions("xpath=/html/body/table[2]/tbody/tr/td/table/tbody/tr/td/div/form/div/table[2]/tbody/tr[1]/td[2]/select");      
    //The above command returns a array of strings(options)
   //write results to excel and note pad
    File file = new File("C:/Dropdownvalues.xls");//excel
    File file1 = new File("C:/Dropdownvalues.txt");//notepad
    BufferedWriter out = new BufferedWriter(new FileWriter(file));//excel
    BufferedWriter out1 = new BufferedWriter(new FileWriter(file1));//notepad
    out.write("Options in drop down\n");//Excel
    out1.write("Options in drop down\n");//notepad
    for (int i = 0; i < option.length; i++) {
        System.out.println("Option: " + i + " is" + option[i]);
        out.write(""+option[i]);
        out.newLine();      
        out1.write(""+option[i]);
        out1.newLine();      
    }
    out.close();//excel
    out1.close();//notepad
  }
 @AfterClass
 public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();

 }
 }

November 24, 2010

Print values in the dropdown

November 24, 2010 17
Print values in the dropdown
The below script explains you how to get the values in a dropdown and print the values to a notepad or excel sheet


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Dropdowngoogle {
public Selenium selenium;
public SeleniumServer seleniumserver;

  @BeforeClass
  public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testDropdowngoogle()throws Exception {
selenium.open("http://www.google.com");
//click on Advanced Search Window
    selenium.click("link=Advanced Search");  
    selenium.waitForPageToLoad("5000");
     //Print all the available options from the results dropdown in the google advanced search page
    String[] option = selenium.getSelectOptions("name=lr");      
    //The above command returns a array of strings(options)
   //write results to excel and note pad
    File file = new File("C:/Dropdownvalues.xls");//excel
    File file1 = new File("C:/Dropdownvalues.txt");//notepad
    BufferedWriter out = new BufferedWriter(new FileWriter(file));//excel
    BufferedWriter out1 = new BufferedWriter(new FileWriter(file1));//notepad
    out.write("Options in drop down\n");//Excel
    out1.write("Options in drop down\n");//notepad
    for (int i = 0; i < option.length; i++) {
        System.out.println("Option: " + i + " is" + option[i]);
        out.write(""+option[i]);
        out.newLine();      
        out1.write(""+option[i]);
        out1.newLine();      
    }
    out.close();//excel
    out1.close();//notepad
  }
 @AfterClass
 public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();

 }
 }

How to verify the check box is checked or not?

November 24, 2010 15
How to verify the check box is checked or not?
Here i am writing steps how to verify the check box is checked or not?



import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Checkbox {
public Selenium selenium;
public SeleniumServer seleniumserver;

  @BeforeClass
  public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testCheckbox()throws Exception {

selenium.open("http://www.google.com");
selenium.windowMaximize();
selenium.click("link=Search settings");
selenium.waitForPageToLoad("50000");
/*Here i am verifying the check box for English. English check
box is already checked so if case will be executed*/
//here pen is the id of the check box
if(selenium.isChecked("pen"))
{
System.out.println("check box already checked");
}
else
{
System.out.println("Check box not checked");
}
}
 @AfterClass
 public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();

 }
 }

November 22, 2010

Use Java script in Selenium RC script

November 22, 2010 2
Use Java script in Selenium RC script
Will update the post once i know how to use Java script in selenium script...

How to work on Frames using selenium

November 22, 2010 1
How to work on Frames using selenium
It is not an easy talk to identify the frame name or ID..when the frame name is changing dynamically...
For example login in gmail and try to compose a mail...Compose mail button is kept in a separate frame..for the we need to select that frame...first we need to select that frame and later we need to click on that button..

i am searching for how to identify the frame..after gettign i will update the post....

****Will post soon******

November 20, 2010

How to identify window Name, ID and Title in Selenium

November 20, 2010 0
How to identify window Name, ID and Title in Selenium
I saw many posts on identifying window Name, ID and Title or Attribute....but all are giving Syntax...We can find that syntax in Selenium document. In this post, I would like to give an example how to identify window Name, ID and Title or Attribute....
*** coming soon ***


How to Handle New windows

November 20, 2010 0
How to Handle New windows
*****Coming soon*****

November 19, 2010

Selenium Interview Questions - 1

November 19, 2010 0
Selenium Interview Questions - 1
Q1. What is Selenium?
Ans. Selenium is a set of tools that supports rapid development of test automation scripts for web
based applications. Selenium testing tools provides a rich set of testing functions specifically
designed to fulfil needs of testing of a web based application.

Q2. What are the main components of Selenium testing tools?
Ans. Selenium IDE, Selenium RC and Selenium Grid

Q3. What is Selenium IDE?
Ans.
 Selenium IDE is for building Selenium test cases. It operates as a Mozilla Firefox add on and
provides an easy to use interface for developing and running individual test cases or entire test
suites. Selenium-IDE has a recording feature, which will keep account of user actions as they are
performed and store them as a reusable script to play back.

Q4. What is the use of context menu in Selenium IDE?
Ans. It allows the user to pick from a list of assertions and verifications for the selected location.

Q5. Can tests recorded using Selenium IDE be run in other browsers?
Ans.
 Yes. Although Selenium IDE is a Firefox add on, however, tests created in it can also be run in
other browsers by using Selenium RC (Selenium Remote Control) and specifying the name of the test
suite in command line.

Q6. What are the advantage and features of Selenium IDE?
Ans. 1. Intelligent field selection will use IDs, names, or XPath as needed
2. It is a record & playback tool and the script format can be written in various languages including
C#, Java, PERL, Python, PHP, HTML
3. Auto complete for all common Selenium commands
4. Debug and set breakpoints
5. Option to automatically assert the title of every page
6. Support for Selenium user-extensions.js file

Q7. What are the disadvantage of Selenium IDE tool?
Ans.
 1. Selenium IDE tool can only be used in Mozilla Firefox browser.
2. It is not playing multiple windows when we record it.

Q8. What is Selenium RC (Remote Control)?
Ans.
 Selenium RC allows the test automation expert to use a programming language for maximum
flexibility and extensibility in developing test logic. For example, if the application under test returns
a result set and the automated test program needs to run tests on each element in the result set, the
iteration / loop support of programming language’s can be used to iterate through the result set,
calling Selenium commands to run tests on each item.

Selenium RC provides an API and library for each of its supported languages. This ability to use
Selenium RC with a high level programming language to develop test cases also allows the automated
testing to be integrated with the project’s automated build environment.

Q9. What is Selenium Grid?
Ans. Selenium Grid in the selenium testing suit allows the Selenium RC solution to scale for test suites
that must be run in multiple environments. Selenium Grid can be used to run multiple instances of
Selenium RC on various operating system and browser configurations.

Q10. How Selenium Grid works?
Ans. Selenium Grid sent the tests to the hub. Then tests are redirected to an available Selenium RC,
which launch the browser and run the test. Thus, it allows for running tests in parallel with the entire
test suite.

Q 11. What you say about the flexibility of Selenium test suite?
Ans.
 Selenium testing suite is highly flexible. There are multiple ways to add functionality to Selenium
framework to customize test automation. As compared to other test automation tools, it is
Selenium’s strongest characteristic. Selenium Remote Control support for multiple programming and
scripting languages allows the test automation engineer to build any logic they need into their
automated testing and to use a preferred programming or scripting language of one’s choice.
Also, the Selenium testing suite is an open source project where code can be modified and
enhancements can be submitted for contribution.

Q12. What test can Selenium do?
Ans.
 Selenium is basically used for the functional testing of web based applications. It can be used for
testing in the continuous integration environment. It is also useful for agile testing

Q13. What is the cost of Selenium test suite?
Ans.
 Selenium test suite a set of open source software tool, it is free of cost.

Q14. What browsers are supported by Selenium Remote Control?
Ans. 
The test automation expert can use Firefox, IE 7/8, Safari and Opera browsers to run tests in
Selenium Remote Control.

Q15. What programming languages can you use in Selenium RC?
Ans.
 C#, Java, Perl, PHP, Python, Ruby

Q16. What are the advantages and disadvantages of using Selenium as testing tool?
Ans.
 Advantages: Free, Simple and powerful DOM (document object model) level testing, can be used
for continuous integration; great fit with Agile projects.

Disadvantages: Tricky setup; dreary errors diagnosis; can not test client server applications.

Q17. What is difference between QTP and Selenium?
Ans.
 Only web applications can be testing using Selenium testing suite. However, QTP can be used for
testing client server applications. Selenium supports following web browsers: Internet Explorer,
Firefox, Safari, Opera or Konqueror on Windows, Mac OS X and Linux. However, QTP is limited to
Internet Explorer on Windows.

QTP uses scripting language implemented on top of VB Script. However, Selenium test suite has the
flexibility to use many languages like Java, .Net, Perl, PHP, Python, and Ruby.

Q18. What is difference between Borland Silk test and Selenium?
Ans.
 Selenium is completely free test automation tool, while Silk Test is not. Only web applications
can be testing using Selenium testing suite. However, Silk Test can be used for testing client server
applications. Selenium supports following web browsers: Internet Explorer, Firefox, Safari, Opera or
Konqueror on Windows, Mac OS X and Linux. However, Silk Test is limited to Internet Explorer and
Firefox.

Silk Test uses 4Test scripting language. However, Selenium test suite has the flexibility to use many
languages like Java, .Net, Perl, PHP, Python, and Ruby.

Selenium Basics Part - 3

November 19, 2010 1
Selenium Basics Part - 3

Selenium Commands – Selenese


command is what tells Selenium what to do. Selenium commands come in three “flavors”:ActionsAccessors and Assertions.
  • Actions are commands that generally manipulate the state of the application. They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the current test is stopped.
Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.
  • Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions.
  • Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.

Script Syntax

Selenium commands are simple, they consist of the command and two parameters. For example:
verifyText
//div//a[2]
Login
The parameters are not always required; it depends on the command. In some cases both are required, in others one parameter is required, and in still others the command may take no parameters at all. Here are a couple more examples:
goBackAndWait


verifyTextPresent

Welcome to My Home Page
type
id=phone
(555) 666-7066
type
id=address1
${myVariableAddress}
The command reference describes the parameter requirements for each command.
Parameters vary, however they are typically:
  • a locator for identifying a UI element within a page.
  • a text pattern for verifying or asserting expected page content
a text pattern or a selenium variable for entering text in an input field or for selecting an option from an option list.







Test Suites
A test suite is a collection of tests. Often one will run all the tests in a test suite as one continuous batch-job.
When using Selenium-IDE, test suites also can be defined using a simple HTML file. The syntax again is simple. An HTML table defines a list of tests where each row defines the filesystem path to each test. An example tells it all.
Test Suite Function Tests - Priority 1


A file similar to this would allow running the tests all at once, one after another, from the Selenium-IDE.
Test suites can also be maintained when using Selenium-RC. This is done via programming and can be done a number of ways. Commonly Junit is used to maintain a test suite if one is using Selenium-RC with Java. Additionally, if C# is the chosen language, Nunit could be employed. If using an interpreted language like Python with Selenium-RC than some simple programming would be involved in setting up a test suite. Since the whole reason for using Sel-RC is to make use of programming logic for your testing this usually isn’t a problem.


Commonly Used Selenium Commands
To conclude our introduction of Selenium, we’ll show you a few typical Selenium commands. These are probably the most commonly used commands for building tests.
open
opens a page using a URL.
click/clickAndWait
performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle
verifies an expected page title.
verifyTextPresent
verifies expected text is somewhere on the page.
verifyElementPresent
verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText
verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable
verifies a table’s expected contents.
waitForPageToLoad
pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
waitForElementPresent
pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
Summary
Now that you’ve seen an introduction to Selenium, you’re ready to start writing your first scripts. We recommend beginning with the Selenium IDE and its context-sensitive, right-click, menu. This will allow you to get familiar with the most common Selenium commands quickly, and you can have a simple script done in just a minute or two. 

Locating Elements

For many Selenium commands, a target is required. This target identifies an element in the content of the web application, and consists of the location strategy followed by the location in the format locatorType=location. The locator type can be omitted in many cases. The various locator types are explained below with examples for each

Locating by Id

Locating by Name

Locating by XPath

Locating Hyperlinks by Link Text

Locating by DOM

Locating by CSS


Store commands

storeElementPresent

This corresponds to verifyElementPresent. It simply stores a boolean value–”true” or “false”–depending on whether the UI element is found.

storeText

StoreText corresponds to verifyText. It uses a locater to identify specific page text. The text, if found, is stored in the variable. StoreText can be used to extract text from the page being tested.

storeEval

This command takes a script as its first parameter. Embedding JavaScript within Selenese is covered in the next section. StoreEval allows the test to store the result of running the script in a variable.






Selenium Basics Part - 2

November 19, 2010 3
Selenium Basics Part - 2

Get started with Selenium!


1.    Watch: see the magic.


This video will tell you how to record tests using Selenium IDE.

2.    Begin: write and run tests in Firefox

Selenium IDE is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.

3.    Customize: your language, your browser.

Selenium Remote Control (RC) runs your tests in multiple browsersand platforms. Tweak your tests in your preferred language.

4.    Deploy: scale out, speed up.

Selenium Grid extends Selenium RC to distribute your tests across multiple servers, saving you time by running tests in parallel.

Who should use it? 

Developers can use it - for “browser” regression testing ( and replace htmlunit/httpunit in some cases) .
Per the one of the forces behind selenium(Neal ford) - it should really be used by Business Analyst first .
QA should enhance/use it do regression test/cross browsers testing on all platforms .

Platforms Supported by Selenium

Browsers

Browser
Selenium IDE
Selenium Remote Control
Selenium Core
Firefox 3
Record and playback tests
Start browser, run tests
Run tests
Firefox 2
Record and playback tests
Start browser, run tests
Run tests
IE 8
not supported
Start browser, run tests
Run tests
IE 7
not supported
Start browser, run tests
Run tests
Safari 3
not supported
Start browser, run tests
Run tests
Safari 2
not supported
Start browser, run tests
Run tests
Opera 9
not supported
Start browser, run tests
Run tests
Opera 8
not supported
Start browser, run tests
Run tests
Others
not supported
Partial support possible*
Run tests**

Operating Systems

OS
Selenium IDE
Selenium Remote Control
Selenium Core
Windows
Works in Firefox 2+
Start browser, run tests
Run tests
OS X
Works in Firefox 2+
Start browser, run tests
Run tests
Linux
Works in Firefox 2+
Start browser, run tests
Run tests
Solaris
Works in Firefox 2+
Start browser, run tests
Run tests
Others
Should work in Firefox 2+
Start browser, run tests*
Run tests**

Programming Languages

Programming languages are supported through Selenium Remote Control "drivers." These are libraries made for each language that expose commands from the Selenium API natively in the form of methods/functions.
Language
Selenium IDE
Selenium Remote Control
Selenium Core
C#
Generate code
Library ("driver") support
n/a
Java
Generate code
Library ("driver") support
n/a
Perl
Generate code
Library ("driver") support
n/a
PHP
Generate code
Library ("driver") support
n/a
Python
Generate code
Library ("driver") support
n/a
Ruby
Generate code
Library ("driver") support
n/a
Others
Generate custom code*
Commands via HTTP requests**
n/a

Testing Frameworks

Testing frameworks aren't required, but they can be helpful if you want to automate your tests.
Framework
Selenium IDE
Selenium Remote Control
Selenium Core
Bromine
Comes with template to add to IDE
Manipulate browser, check assertions via custom driver
Special support**
JUnit
Out-of-the-box code generation
Manipulate browser, check assertions via Java driver
n/a
NUnit
Out-of-the-box code generation
Manipulate browser, check assertions via .NET driver
n/a
RSpec (Ruby)
Custom code generation template*
Manipulate browser, check assertions via Ruby driver
n/a
Test::Unit (Ruby)
Out-of-the-box code generation
Manipulate browser, check assertions via Ruby driver
n/a
TestNG (Java)
Custom code generation template*
Manipulate browser, check assertions via Java driver
n/a
unittest (Python)
Out-of-the-box code generation
Manipulate browser, check assertions via Python driver
n/a
Others
Custom code generation template*
Manipulate browser, check assertions via HTTP requests***
n/a
n/a
Utilizes the Python driver
n/a