Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Monday, February 28, 2011

How to configure/change running other than on default port

Pogrammatically changing the default port.

RemoteControlConfiguration class which is contained in selenium-server.jar:

import org.openqa.selenium.server.RemoteControlConfiguration;

@Test

public void remoteControlConfigExample()
{
final int SELENIUM_PORT = 8888;
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(SELENIUM_PORT);
SeleniumServer seleniumServer=null;
try
{
seleniumServer = new SeleniumServer(rcConfig);
seleniumServer.start();
} catch (Exception e)
{
e.printStackTrace();
}
Selenium selenium=null;
selenium = new DefaultSelenium("localhost", SELENIUM_PORT, "*firefox","http://www.google.com");
selenium.start();
//Add your piece of actions here & then followed by
selenium.close();
selenium.stop();
if(seleniumServer!=null)
{
seleniumServer.stop();
}
} automationwithselenium.blogspot.com-Google pagerank and Worth

Saturday, February 26, 2011

Selenium RC UI Mapping

Why should we map the Elements or identifiers or locators in UI?

Imagine that if you have a case with hundreds of input in login field. Now the login text box has been changed to drop down list or the name of the identifier has been changed from Textbox_Login to txt_login.

If we execute our existing test scripts they will fail as they cannot find the locator and making changes in all scripts that involve would be hard.

Hence we map the UI objects & store them in a centralized location for making the script more efficient and maintainable.

So we create a Properties file where we store all the UI objects identifiers & for any further changes we can just tweak this properties file as against all testscripts.

Create the properties file :

Create a file like resLogin.properties and we can assign the UI element as follows:

resuser.firstname = "ctl00_txtFirstName";
resuser.middlename = "ctl00_txtMiddleName";
resuser.lastname = "ctl00_txtLastName";
resuser.loginname = "ctl00_txtLoginName";
resuser.password = "ctl00_txtPassword";


All you have to do now is make a call in your selenium scripts.

For ex :

selenium.type("resuser.firstname","Shabana");
selenium.type("resuser.middlename"," ");
selenium.type("resuser.lastname","K");
selenium.type("resuser.loginname","autouser1");
selenium.type("resuser.password","welcome");

In the above example for any identifiers being changed you have to make changes in the properties file & replace the one highlighted. automationwithselenium.blogspot.com-Google pagerank and Worth

Types of Framework

Any framework is made up of a number of reusable modules & function libraries that are developed with the following characteristics in mind:

Maintainable
Reusable
Manageable
Accessible
Robust
Flexibility
Measurable


Frame work has several types and most popular are the below :

a.Keyword driven frame work
b.Data driven driven frame work
c.Hybrid framework

Key word Driven Frame work :

Keyword driven framework is an action based test method used in planing and implementation of automation.

Data Driven Framework :

Data driven is the design of possible inputs what may be given by the end user.
This would cover maximum probabilities of an input data.
It can either be Spread sheet(excel)/sql/CSV.
We have to connect and pass the values to the respective field or element.
The data should be designed by the experienced person on the project. It may be a client or even non technical person but should be more familiar from an end users prospective.
We have to map the file path properly.

Hybrid Framework:

The Hybrid Automation Framework is otherwise referred to in the industry as a "Hybrid Keyword Data Driven Automation Framework". automationwithselenium.blogspot.com-Google pagerank and Worth

Strategy to setup Selenium Framework Design

Its alwayz important to set the ground rules straight & think through these factors for designing a framework:

These are my views which has worked well in my past experience.

1. We need to create UI Map.

2. Libraries for UI objects.

3. Design classes based on application under test.

4. Plan for test execution approach to minimize the time.

5. Design report generation.

6. Prepare a Step table and step suite.

7. Prepare a Data set where ever needed.

8. Design Keyword Driven action fixtures this is purely on the approach we follow if its data driven framework ignore this step.

9. Design and develop the psudo code. automationwithselenium.blogspot.com-Google pagerank and Worth

Generate JUnit report with Ant & Eclipse IDE


Reports are crucial for any tests carried out.

Steps to configure and generate the test result from java eclipse using Ant:

this post is for users who have already familiar with java and eclipse.

Generating the ANT build:
Right click on the project and
select Export --> Ant Buildfiles.-->Next-->Select the project-->Finish.

Configuring jar:

Select Windows menu-->Preference -->Global Entries -->Add External JARs-->Select the folder where the eclipse is installed. eclipse -->Plugin -->Currently its located in "org.junit_4.8.1.v4_8_1_v20100427-1100"-->"junit.jar"-->OK.

Run the Ant Build:


Create a folder "junit" in side the project folder.

Right click on the AntBuildfile-->RunAs -->AntBuild

Return to java project and run as junit test.

End of test run you will find the test result in a html file named as index.html it will be stored inside the junit folder.
automationwithselenium.blogspot.com-Google pagerank and Worth

How to does selenium work with Tabbing

Key Press and Fire Event
Imagine that if you have a function in your application that can be invoked by pressing the "Tab" key.

Eg. Values being populated on focus out.

We can use keyPress with ASCII value for the key which you want to trigger the function.

Eg:
Command Target Value
keyPress Txt_Login \9


here "\9" is ascii value of horizontal tab.

Some functions may be used Onblur. It will trigger the function when the field looses the key focus.

We can use fireEvent with "blur" or "focus" command as follows:


Command Target Value
fireEvent Txt_Login blur automationwithselenium.blogspot.com-Google pagerank and Worth

Tuesday, February 22, 2011

Xpath tips !!!

Get All elements :

// Get all elements where pet equals cat
String xpath = "//*[@pet='cat']";

// Get all elements where pet contains the string dog
xpath = "//*[contains(@pet,'dog')]";
// Get all elements that have the age attribute
xpath = "//*[@age]"; 



Absolute path (would break if the HTML was changed only slightly) - xpath=/html/body/form[1]

First form element in the HTML - //form[1]

The form element with attribute named ‘id’ and the value ‘loginForm’ - xpath=//form[@id='loginForm']

First input element with attribute named ‘name’ and the value ‘username’ - //input[@name='username']

First input child element of the form element with attribute named ‘id’ and the value ‘loginForm’ - //form[@id='loginForm']/input[1]

Input with attribute named ‘name’ and the value ‘continue’ and attribute named ‘type’ and the value ‘button’ - //input[@name='continue'][@type='button']

Fourth input child element of the form element with attribute named ‘id’ and value ‘loginForm’ - //form[@id='loginForm']/input[4]
automationwithselenium.blogspot.com-Google pagerank and Worth

Monday, February 21, 2011

How to do a DDT having a Db connection in selenium

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import java.sql.*;
import javax.sql.*;
import java.io.*;
public class contact extends SeleneseTestCase
{


public void setUp() throws Exception
{
// add details of browser & other details
}

public void testContact() throws Exception {
System.out.println("Connecting to the database");
String url="jdbc:mysql://localhost:/main.jsp";
Class driverClass = Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection(url,"", "");
System.out.println("Connected to the database");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp_account");
ResultSetMetaData rsmd = rs.getMetaData();
int columns = rsmd.getColumnCount
while (rs.next())
for (int i = 1; i < columns; i++)
{
System.out.print(rs.getObject(i + 1)+" |");
}
System.out.println(" ");
}
}}
automationwithselenium.blogspot.com-Google pagerank and Worth