"Karmanyevadhikaraste ma phaleshu kadachana,
Ma karma phala hetur bhurmatey sangostva akarmani."
DB connection
Install my sql
In selenium, write code as
import java.sql.*
public class Db_connect{
connection conn=null;
String url= jdbc:mysql://localhost:3306/";
String DBName="Test" (Table name)
String driver="com.mysql.jdbc.Driver";
String username="kkjkj"
String password="fff";
try{
class.forName(driver).newInstance(); //create object of instance of driver
conn=DriverManager.getconnection(url+dbname+username,[password) //get connection
Statement stmt= conn.createstatement();
resultset s= stmt.executequery("select * from users");
rs.next();
syso(rs.getstring(1);
while(rs.next)
syso(rs.getstring(1)
Prepare statement pp=conn.prepare statement
pp.setstring(1,"p");
resultset rs3=pp1.executequery();
}catch(Exception e)
{
finally
conn.close();
In selenium, write code as
import java.sql.*
public class Db_connect{
connection conn=null;
String url= jdbc:mysql://localhost:3306/";
String DBName="Test" (Table name)
String driver="com.mysql.jdbc.Driver";
String username="kkjkj"
String password="fff";
try{
class.forName(driver).newInstance(); //create object of instance of driver
conn=DriverManager.getconnection(url+dbname+username,[password) //get connection
Statement stmt= conn.createstatement();
resultset s= stmt.executequery("select * from users");
rs.next();
syso(rs.getstring(1);
while(rs.next)
syso(rs.getstring(1)
Prepare statement pp=conn.prepare statement
pp.setstring(1,"p");
resultset rs3=pp1.executequery();
}catch(Exception e)
{
finally
conn.close();
Grid-type pf connections
We can start hub in remote machine using vmware start a node there and start a node in local machine connecting to vmware hub and run tests parallel
we can use webconfig configuration file to configure
now the tests has ran parallelely...parallel="tests" threadcount="10"> in xml file..
now want to run them at a time
parallel="classes" >
we can use webconfig configuration file to configure
now the tests has ran parallelely...parallel="tests" threadcount="10"> in xml file..
now want to run them at a time
parallel="classes" >
Grid-Example
Connecting Grid:
1. Start the Hub:
java -jar selenium-server-standalone-2.14.0.jar -role hub
The hub will automatically start-up using port 4444 by default
to change java -jar selenium-server-standalone-2.39.0.jar -role hub -port 4441
2. Start the nodes
java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://localhost:4444/grid/register
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://
localhost:4441/grid/register -nodecongig webconfig.txt -port 5556 http://
localhost:4441/grid/console -browser browserName=firefox,version=3.6,maxinstances=5,platform=WINDOWS -nodecongig webconfig.txt
java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -Dwebdriver.ie.dr
iver="C:\IEDriverServer.exe" -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://
localhost:4441/grid/register -port5557 -browser browserName=firefox -browser browserName=chrome -browser browserName=iexplorer nodeTimeout 300
3. Create script to run using DesiredCapabilities capability = DesiredCapabilities.firefox();
and Pass that into the RemoteWebDriver object:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
4. create a testng.xml file and keep the tests in there, and run test ng Suite
You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console
import java.net.MalformedURLException;
import java.net.URL;
//import net.sourceforge.htmlunit.corejs.javascript.ast.ThrowStatement;
//import org.apache.xerces.util.URI.MalformedURIException;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Grid_demo3 {
@Parameters("browser")
@Test
public void Google_Serach(String b) throws MalformedURLException {
//pass the browser in the search function and print
System.out.println(b);
//make desired capability to null and give if else conditions for multiple change of browsers
DesiredCapabilities cap = null;
if(b.equals("firefox")){
cap= DesiredCapabilities.firefox();
cap.setPlatform(Platform.ANY);
cap.setBrowserName("firefox");
}else if (b.equals("chrome")){
cap= DesiredCapabilities.chrome();
cap.setPlatform(Platform.ANY);
cap.setBrowserName("chrome");}
else if (b.equals("iexplore")){
cap= DesiredCapabilities.internetExplorer();
cap.setPlatform(Platform.WINDOWS);
cap.setBrowserName("iexplore");}
//no need to give path of chrome exe as we r giving it in node
//C:\Meeraja-Selenium\libraries>java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-serve
// r-standalone-2.39.0.jar -role webdriver -hub http://localhost:4441/grid/register -port5557 -browser
// browserName=firefox -browser browserName=chrome
RemoteWebDriver driver= new RemoteWebDriver(new URL("http://localhost:4441/wd/hub"),cap);
driver.get("http://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("meera");
driver.findElement(By.id("Passwd")).sendKeys("ana");
}
}
test.xml
<suite name="Selenium Grid with webdriver" verbose="3" parallel="tests">
<test name="Grid_demo3" >
<parameter name="browser" value="iexplore"/>
<classes>
<class name="Grid_demo3" />
</classes>
</test>
</suite>
xml elements should be properly nested
xml tags are case sensitive
xml tags should have root element
xml element attributes should be in quotes
<parameter name="browser" value="iexplore"/>
xml tags should have closing tags
<test name="Grid_demo3" >
<parameter name="browser" value="iexplore"/>
<classes>
<class name="Grid_demo3" />
</classes>
</test>
</suite>
xml elements should be properly nested
xml tags are case sensitive
xml tags should have root element
xml element attributes should be in quotes
<parameter name="browser" value="iexplore"/>
xml tags should have closing tags
setup node-selenium grid
C:\Meeraja-Selenium\libraries>java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -Dwebdriver.ie.dr
iver="C:\IEDriverServer.exe" -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://
localhost:4441/grid/register -port5557 -browser browserName=firefox -browser browserName=chrome -bro
wser browserName=iexplorer nodeTimeout 300
iver="C:\IEDriverServer.exe" -jar selenium-server-standalone-2.39.0.jar -role webdriver -hub http://
localhost:4441/grid/register -port5557 -browser browserName=firefox -browser browserName=chrome -bro
wser browserName=iexplorer nodeTimeout 300
MOuse movements
public class Mous_move {
public static void main(String[]args){
WebDriver mydriver = new FirefoxDriver();
EventFiringWebDriver webdriver= new EventFiringWebDriver(mydriver);
MyListener myListner= new MyListener();
mydriver.register(myListener);
mydriver.navigate("http://timesofindia.com");
public static void main(String[]args){
WebDriver mydriver = new FirefoxDriver();
EventFiringWebDriver webdriver= new EventFiringWebDriver(mydriver);
MyListener myListner= new MyListener();
mydriver.register(myListener);
mydriver.navigate("http://timesofindia.com");
Download file using selenium
in firefox, give about:config will give verious properties of forefox
there r d/f type of files,
rar file
doc file
exe file
create a firefox profile
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.dir","D:\\test");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/msword,etc");
there r d/f type of files,
rar file
doc file
exe file
create a firefox profile
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.dir","D:\\test");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/msword,etc");
Go Back and Forward buttons
public class Front_BackButttons {
public static void main(String[] args) throws InterruptedException {
WebDriver driver =new FirefoxDriver();
driver.navigate().to("http://google.com");
//navigate only have functions to go forwrad or backward
driver.findElement(By.xpath("ddsds"));
Thread.sleep(5000L);
driver.navigate().back();
Thread.sleep(5000L);
driver.navigate().forward();
Thread.sleep(5000L);
driver.quit();
wells batch testing reqs
Test Design and Test Execution for Digital Payments (Direct Pay).
Batch Testing using Autosys, Working with Flat file formats, Data Validation using SQL/Toad and Unix.
Must have Financial Institution test experience.
HR Job Description:
- Creates, prepares and implements systems quality assurance reviews for numerous applications. Responsible for primary development of testing strategies.
- Consults with users, providing advice and direction.
- Performs more complex analysis of business requirements and system specifications.
- May serve as a coordinator for all testing activities on a project.
- Creates test plans and scripts for own projects.
- May lead and review test plans written by others.
- Performs moderately complex to complex test data conditioning, regression testing and testing validation.
- Provides specific guidance on defects to developers.
- Gives direction to less experienced analysts.
- Logs, tracks, and verifies resolution of software and specification defects.
- Documents all phases of the Systems QA process.:
- 5+ years IT quality assurance and systems/application testing experience.
Java Script Alerts
go to rediff..
sign on click
don't enter email and click enter...alert will popup with msg enter email
public class Alerts {
public static void main(String[] args) throws InterruptedException {
WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.rediff.com");
driver.findElement(By.linkText("signin ")).click();
driver.findElement(By.xpath("//*[@id='btn_login']")).sendKeys(Keys.ENTER);
Thread.sleep(1000L);
Alert Al= driver.switchTo().alert();
System.out.println(Al.getText());
Al.accept();//means OK
//Al.dismss(); //Cancel
//To switch back to regular page
driver.switchTo().defaultContent();
sign on click
don't enter email and click enter...alert will popup with msg enter email
public class Alerts {
public static void main(String[] args) throws InterruptedException {
WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.rediff.com");
driver.findElement(By.linkText("signin ")).click();
driver.findElement(By.xpath("//*[@id='btn_login']")).sendKeys(Keys.ENTER);
Thread.sleep(1000L);
Alert Al= driver.switchTo().alert();
System.out.println(Al.getText());
Al.accept();//means OK
//Al.dismss(); //Cancel
//To switch back to regular page
driver.switchTo().defaultContent();
Handling Calenders
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.text.ParseException;
public class Calender_Handle {
public static void main(String[] args) throws ParseException {
String d = "24/04/2014";
////first we need to extract month and date
SimpleDateFormat df= new SimpleDateFormat("dd/mm/yyyy");
Date myDate = df.parse(d);
Calendar cal= Calendar.getInstance();
cal.setTime(myDate);
int day= cal.get(Calender.Day
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.text.ParseException;
public class Calender_Handle {
public static void main(String[] args) throws ParseException {
String d = "24/04/2014";
////first we need to extract month and date
SimpleDateFormat df= new SimpleDateFormat("dd/mm/yyyy");
Date myDate = df.parse(d);
Calendar cal= Calendar.getInstance();
cal.setTime(myDate);
int day= cal.get(Calender.Day
File upload
//for file upload always input type is File and id = multi type file
WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.salesforce.com");
driver.findElement(By.xpath("//login']")).click();
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys("user");
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys("pwd");
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//File_Tab']")).click();
driver.findElement(By.xpath("//input[@id='multiFileInput']")).sendKeys("c:\\ssccc.jpeg");
//select File option some times is flash ...
WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.salesforce.com");
driver.findElement(By.xpath("//login']")).click();
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys("user");
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys("pwd");
driver.findElement(By.xpath("//*[@id='u_0_n']")).sendKeys(Keys.ENTER);
driver.findElement(By.xpath("//File_Tab']")).click();
driver.findElement(By.xpath("//input[@id='multiFileInput']")).sendKeys("c:\\ssccc.jpeg");
//select File option some times is flash ...
managing web table with css
WebDriver driver= new FirefoxDriver();
driver.get("http://www.timeanddate.com/worldclock");
//html/body/div[8]/table/tbody/tr[2]/td[3]/a
//under table with class name <table class="border2 lpad wa wc-tab ccols4">
//String xpath="//table[@class='border2 lpad wa wc-tab ccols4']/tbody//tr[2]/td[3]/a";
// to write it as css selector
String cSelect = "table[class= 'border2 lpad wa wc-tab ccols4'] tbody tr:nth-child(2) td:nth-child(3) a";
System.out.println(driver.findElement(By.cssSelector(cSelect)).getText());
driver.get("http://www.timeanddate.com/worldclock");
//html/body/div[8]/table/tbody/tr[2]/td[3]/a
//under table with class name <table class="border2 lpad wa wc-tab ccols4">
//String xpath="//table[@class='border2 lpad wa wc-tab ccols4']/tbody//tr[2]/td[3]/a";
// to write it as css selector
String cSelect = "table[class= 'border2 lpad wa wc-tab ccols4'] tbody tr:nth-child(2) td:nth-child(3) a";
System.out.println(driver.findElement(By.cssSelector(cSelect)).getText());
Element present at xpath
public boolean isElementPresent_xpath(String objectXpath){
int count=driver.findElement(By.xpath(objectXpath)).size();
if(count==0)
return false;
else
return true;
String firstname="Meeraj";
String lastname="Anasuri";
Assume names are in a web table,
//Validations:
String part1="//*@id='hkjhjkh[" ;
String part2="]/td[2]";
int i=2 // as xpath starts at 2 for this
while( isElementPresent_xpath(part1+i+part2))
String fname=driver.findElement(By.xpath(part1+i+part2).getText();
if(fName.equals(firstname)){
//then check for last name
String xpathLastnamecol= part1+i+part2.replace("td[1]","[2]");
String lName=driver.findElement(by. xpathLastnamecol).getText();
if(lName.equals(LastName)){
system.out.println();
recordFound=true;
break;
}}
Assert.assertTrue(recordFound,"Record of full name");
int count=driver.findElement(By.xpath(objectXpath)).size();
if(count==0)
return false;
else
return true;
String firstname="Meeraj";
String lastname="Anasuri";
Assume names are in a web table,
//Validations:
String part1="//*@id='hkjhjkh[" ;
String part2="]/td[2]";
int i=2 // as xpath starts at 2 for this
while( isElementPresent_xpath(part1+i+part2))
String fname=driver.findElement(By.xpath(part1+i+part2).getText();
if(fName.equals(firstname)){
//then check for last name
String xpathLastnamecol= part1+i+part2.replace("td[1]","[2]");
String lName=driver.findElement(by. xpathLastnamecol).getText();
if(lName.equals(LastName)){
system.out.println();
recordFound=true;
break;
}}
Assert.assertTrue(recordFound,"Record of full name");
cookies
cookies-to keep session of users browser place some code in u r
driver.get("http://www.neocell.com");
Set<Cookie> cookies= driver.manage().getCookies();
//there r multiple options to get cookies,delete cookies,add cookies etc
//cookie is a inbuilt class
System.out.println("Total Cookies" +cookies.size());
Iterator<Cookie> iter= cookies.iterator();
while(iter.hasNext()){
Cookie c= iter.next();
System.out.println(c.getDomain() + "----" + c.getName() +"---" +c.getValue()); // the website which cookie belongs to and get the name of the cookie and the value of cookie
}
//driver.manage().deleteAllCookies();
//driver.manage().deleteCookieNamed("name");
driver.get("http://www.neocell.com");
Set<Cookie> cookies= driver.manage().getCookies();
//there r multiple options to get cookies,delete cookies,add cookies etc
//cookie is a inbuilt class
System.out.println("Total Cookies" +cookies.size());
Iterator<Cookie> iter= cookies.iterator();
while(iter.hasNext()){
Cookie c= iter.next();
System.out.println(c.getDomain() + "----" + c.getName() +"---" +c.getValue()); // the website which cookie belongs to and get the name of the cookie and the value of cookie
}
//driver.manage().deleteAllCookies();
//driver.manage().deleteCookieNamed("name");
webdriver timeouts
webdriver timeouts:
driver.get("http://www.gmail.com");
//timeouts will wait for the elemnt to load
// suppose we give 5 sec, 5 sec is max time it waits and throws error then, if it ready in 3 sec, it will continue
//pageloading time- for the next page to load
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
WebElement table= driver.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(keysToSend);;
Frames:
like apage inside a page..
tag name iframe
there will be multiple iframes in a page- o ask developer about iframe
go to page source, find the link name and made own xpath
to switch frame
driver.switchTo().frame(1) //control to 1 st frame
to find no.of frames in a web page,
driver.findelement by tagname(iframe).size();
WebDriver driver= new FirefoxDriver();
driver.get("http://www.timesofindia.com");
System.out.println(driver.findElements(By.tagName("iframe")).size());//no.of frames in a page
//switch to frame
driver.switchTo().frame("liveScores");//get it from page source
//once move to the required frame, then click on url
//to kniw, if it is frame or not, right clcik on it and will see the option frame
driver.findElement(By.xpath("ccc"));
WebDriver driver= new FirefoxDriver();
driver.get("http://www.timesofindia.com");
System.out.println(driver.findElements(By.tagName("iframe")).size());//no.of frames in a page
//switch to frame
driver.switchTo().frame("liveScores");//get it from page source
//once move to the required frame, then click on url
//to kniw, if it is frame or not, right clcik on it and will see the option frame
driver.findElement(By.xpath("ccc"));
Frame inside Frame:
driver.get("http://www.borro.com");
driver.findElement(By.xpath("kkjkj")).click();
Thread.sleep(1000L);
//ligbox loaded
List<WebElement> frames= driver.findElements(By.tagName("iframe"));
System.out.println(frames.size());
System.out.println(frames.get(0).getAttribute("id"));//particular element
System.out.println(frames.get(1).getAttribute("id"));//2nd element
driver.switchTo().frame(1);
driver.findElement(By.xpath("kkjkj")).sendKeys("jj");
}
driver.get("http://www.borro.com");
driver.findElement(By.xpath("kkjkj")).click();
Thread.sleep(1000L);
//ligbox loaded
List<WebElement> frames= driver.findElements(By.tagName("iframe"));
System.out.println(frames.size());
System.out.println(frames.get(0).getAttribute("id"));//particular element
System.out.println(frames.get(1).getAttribute("id"));//2nd element
driver.switchTo().frame(1);
driver.findElement(By.xpath("kkjkj")).sendKeys("jj");
}
Reading the web table contents-rows and column data
public class Web_Tables {
public static void main(String[] args) {
//no.of rows in table
WebDriver driver= new FirefoxDriver();
driver.get("http://www.w3schools.com/tags/tag_table.asp");
WebElement table= driver.findElement(By.xpath("//*[@id='main']/table[2]")); //partial xpath
List<WebElement> rows= table.findElements(By.tagName("tr"));//retrive all rows with tag tr
System.out.println("no.of rows " + rows.size());
for(int rownum=1;rownum<rows.size();rownum++){ //to ignore heading we can ignore first row, so starts from 1
List<WebElement>cells= rows.get(rownum).findElements(By.tagName("td")) ;//corresponding cell content for each row
System.out.println("Total cols is" +cells.size());
//to get the content in all the cells in column
for(int colnum=0;colnum<cells.size();colnum++){
System.out.println(cells.get(colnum).getText() + "---");
}
System.out.println();// to get a new line
}
}
}
public static void main(String[] args) {
//no.of rows in table
WebDriver driver= new FirefoxDriver();
driver.get("http://www.w3schools.com/tags/tag_table.asp");
WebElement table= driver.findElement(By.xpath("//*[@id='main']/table[2]")); //partial xpath
List<WebElement> rows= table.findElements(By.tagName("tr"));//retrive all rows with tag tr
System.out.println("no.of rows " + rows.size());
for(int rownum=1;rownum<rows.size();rownum++){ //to ignore heading we can ignore first row, so starts from 1
List<WebElement>cells= rows.get(rownum).findElements(By.tagName("td")) ;//corresponding cell content for each row
System.out.println("Total cols is" +cells.size());
//to get the content in all the cells in column
for(int colnum=0;colnum<cells.size();colnum++){
System.out.println(cells.get(colnum).getText() + "---");
}
System.out.println();// to get a new line
}
}
}
Subscribe to:
Posts (Atom)