Reusable Script In Selenium

import java.io.FileInputStream;

import jxl.Sheet;
import jxl.Workbook;

import com.thoughtworks.selenium.DefaultSelenium;
public class ReusableScript {
public static DefaultSelenium selenium = new DefaultSelenium("localhost",
6666, "*iehta", "http://");
public static String gmail() throws Exception {
selenium.start();
selenium.open("http://www.gmail.com");
selenium.windowMaximize();
Thread.sleep(2000);
selenium.click("link=Create an account »");
selenium.waitForPageToLoad("30000");
return "pass";
}
public static String Register() throws Exception {
FileInputStream fi = new FileInputStream(
"D:\\Framework\\TestData\\Register.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
for (int i = 1; i < s.getRows(); i++) {
if (!s.getCell(3, i).getContents().equals("")) {
if (s.getCell(2, i).getContents().contains("Text")) {
if (selenium
.isElementPresent(s.getCell(0, i).getContents())) {
selenium.type(s.getCell(0, i).getContents(), s.getCell(
3, i).getContents());
}
} else if (s.getCell(2, i).getContents().contains("Combo")) {
if (selenium
.isElementPresent(s.getCell(0, i).getContents())) {
selenium.select(s.getCell(0, i).getContents(), "label="
+ s.getCell(3, i).getContents());
}
} else if (s.getCell(2, i).getContents().contains("chkbox")) {
if (selenium
.isElementPresent(s.getCell(0, i).getContents())) {
selenium.click(s.getCell(0, i).getContents());
}

} else if (s.getCell(2, i).getContents().contains("Radio")) {
if (selenium
.isElementPresent(s.getCell(0, i).getContents())) {
selenium.click(s.getCell(0, i).getContents());
}

}
else if (s.getCell(2, i).getContents().contains("Button")) {
if (selenium
.isElementPresent(s.getCell(0, i).getContents())) {
selenium.click(s.getCell(0, i).getContents());
}
}
}

}

return "pass";
}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
gmail();
Register();

}

 

 

Syncronizition In Selenium

import com.thoughtworks.selenium.DefaultSelenium;


public class Sync {

/**
* @param args
*/
public static String google() throws Exception
{
DefaultSelenium selenium=new DefaultSelenium("localhost",6666,"*iehta","http://");
selenium.start();
selenium.open("http://mail.in.com");
selenium.windowMaximize();
selenium.type("f_id", "seleniumforum_Nageswar");
selenium.type("f_pwd", "selenium");
// selenium.setTimeout("100000");
selenium.click("//input[@value='' and @type='submit']");
//Thread.sleep(10000);
selenium.waitForPageToLoad("130000");
selenium.click("link=Sign out");
selenium.waitForPageToLoad("130000");
selenium.chooseCancelOnNextConfirmation();
selenium.chooseOkOnNextConfirmation();
return "pass";

}
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
google();

}



Handling Popup if popup name is constant

 selenium.click("stringlocator");
selenium.waitforpagetoload("40000");
selenium.selectwindow("popname");
perform actions on popup
selenium.selectwindow("null"); //return to mainwindow
selenium.selectwindow("mainwindow");
perform actions on mainwindow 

Handling Popups If Popup Name is Dynamically Changing


 selenium.click("stringlocator");
selenium.waitforpagetoload();
String str[]=selenium.getallwindownames();
system.out.println(str.length);
selenium.selectwindow(str[1]);
perform action on popup
selenium.selectwindow("null"); //return to mainwindow
selenium.selectwindow(str[0]);
perform actions on mainwindow 



What is maven?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

Maven's Objectives
Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:
  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features
For more details follow this link :

2 comments: