Friday, 21 November 2014
Thursday, 20 November 2014
Ant
Selenium – Use Ant to Generate HTML Reports
ANT is used to run unit tests, do the application deployment on containers such as Tomcat, WebLogic, GlassFish, etc, and to run Automated Selenium Tests.
Reports:
Reports are the important part of a tester life.We all have to show reports to our Teammates Seniors and managers Whether the Reports are Pass or Fail.
In selenium we have to generate Reports.How much Test cases are passed or How much are failed or skipped.By using ant in Testng we can Generate very good Reports in Selenium.
What is Ant?
Ant is a Build and compile tool which is made by Apache.
Ant runs our programs on Linus
Ant runs our Programs on cmd Prompt.
With the help of Ant you can run your java Programs on cmd prompt.
Ant helps us to generate very good Reports in Testng.
Ant is not a tool you just have to download it or Configure it into your system
How to Download Ant click here
Click on This and Download this apache-ant -1.9 zip File
Extract it into Any Directory of your System
I have extract it into my E:folder.You can Extract it where you want.
Configure Path:
After Extracting Now you have to configure ant into your System.We need to set our Envirnment variable.Before setting enviornment variable let me show you My apache bin directory path.
Go to computer>Right click>properties>Advance systems Setting
Click on Envionment Variable
Click on new
Add a new System variable.Give the path upto your Bin folder of Apache
Now Set path apache path into the existing Directory.First Search Path and Click on Edit>Then edit path as ;%ANT_HOME%\bin.Now click on ok
Go to cmd prompt and Write ant -version.
Ant is installed succesfully.
Here is the video Tutorial for Generating Reports Using Ant
Tutorial 1
Tutorial 2
Here is the video Tutorial for Generating Reports Using Ant
Tutorial 1
Tutorial 2
Wednesday, 19 November 2014
How to Add Priority in Testng
If you need your order of Testcases should be same at run time as you created in Testng then use Priority in Testng Click Here
Monday, 17 November 2014
How to upload file in Selenium Webdriver using Robot Class
Upload File
Problems in Selenium while handling window prompt
Selenium find some difficulties to find object and perform actions which is related to mouse or keyboard type of activity.It is difficult to handle Keyboard and mouse events/Action using selenium commands.There are some specific scenario where selenium command is launched but actual event did not fired.At that time Excecution stops and reports error.
Selenium doesn't provide support to handle browser pop-ups and window based pop ups.There are some methods in Robot class which are used to do the interaction with popups in WebApplications.For handling the pop-up and window-prompt we need to use Robot class..
What is Robot Class?
By using Robot Class we can perform actions on keyboard or mouse events.Robot class is very easy to use with automation process. It can be easily integrate with current automation framework.
Some of the methods of robot class which we are going to use
.keyPress();
KeyPress is a method if we pressctrl button of keyboard.
.keyRelease();
If we have press a ctrl button we have to release that button also.
Here i am giving you an example if i press ctrl v from keyboard.Then first i have to
Make an object of Robot Class and implement the robot methods.
Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL); //This is for pressing ctrl button of Keyboard
r.keyPress(KeyEvent.VK_V); //This is for pressing v button of keyboard
Now we have to release that keys so we will write..
r.keyRelease(KeyEvent.VK_V); //This is for relasing the ctrl button of KeyBoard
r.keyRelease(KeyEvent.VK_CONTROL);//This is for releasing V button of keyBoard.
Here i this scenario i have used Robot class.
Scenario
1.Go to
http://api.checklist.com/login
2.Enter Email as rgulati883@gmail.com
3.Enter Password as jaiguruji
4.Click on Login
5.Click on Checklist1
6.Click on upload
7.Then add path of your File
8.Click on open button.
4Click on Checklist1(0)
5.Click on upload
6.So next step is we copy the path where our file on desktop.
// StringSelection ss = new StringSelection("Your file path ");
StringSelection ss = new StringSelection("C:\\Users\\Hp\\Desktop\\FileuploadTest.txt");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
When you do a cut or copy of text in the operating system, the text is
stored in the clipboard
The following method returns the content that is currently in the
clipboard.
// Calling key press event to press Enter Key from keyboard to place cursor in window textbox
r.keyPress(KeyEvent.VK_ENTER);
//Releaseing the Enter Key
r.keyRelease(KeyEvent.VK_ENTER);
8.After that we copy and paste that path in this FilepathText box.
/*
* Now we are going to trigger CTRL+V action so first we will press CTRL and then V and finally will
* release these key.
*/
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
9.Now click on Open
// After pasting path now we are going to click on Open and that can be
//triggered by pressing enter key from Keyboard.
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
//Release open
10 File is added
package test;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestFileupload {
public static void main(String[] args) throws InterruptedException, AWTException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Hp\\Desktop\\Chromepth\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// WebDriver driver = new FirefoxDriver();
driver.get("http://api.checklist.com/login");
driver.findElement(By.xpath("//*[@id='email']")).sendKeys("rgulati883@gmail.com");
driver.findElement(By.xpath("//*[@id='loginForm']/div[2]/input")).sendKeys("jaiguruji");
driver.findElement(By.xpath("//button[@class='btn btn btn-primary pull-right']")).click();
Thread.sleep(8000);
driver.findElement(By.xpath("//*[@id='userChecklists']/li[1]/a/span")).click();
WebElement UploadImg = driver.findElement(By.xpath("//*[@id='taskUploadFile']"));
UploadImg.click();
// StringSelection ss = new StringSelection("Your file path ");
StringSelection ss = new StringSelection("C:\\Users\\Hp\\Desktop\\FileuploadTest.txt");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot r = new Robot();
// Calling key press event to press Enter Key from keyboard to place cursor in window textbox
r.keyPress(KeyEvent.VK_ENTER);
//Releaseing the Enter Key
r.keyRelease(KeyEvent.VK_ENTER);
/*
* Now we are going to trigger CTRL+V action so first we will press CTRL and then V and finally will
* release these key.
*/
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
// After pasting path now we are going to click on Open and that can be
//triggered by pressing enter key from Keyboard.
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
//Release open
}
}
//After using this code file is added.
Friday, 14 November 2014
Tuesday, 11 November 2014
Set in java
09:05
No comments
Set doesn't add duplicate elements like in list.
There is no get function in set.
Set use iterator for extracting the elements.
The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.
We use set in selenium windows handling concept.(Switching from one tab to different tab)Set gives us a unique ids of the windows.
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class SetDemo {
public static void main(String []str){
Set<String> s = new HashSet<String>();
s.add("test1");
s.add("test2");
s.add("test3");
System.out.println("Total size "+s.size());
s.add("test1");
//If i again add test1 and run
System.out.println("Total size after repeated set test1 "+s.size());
//Size is same because set doesn't add duplicate elements.
//how can we extract that elements which we add above?
//for retriving elements we use iterator in sets
Iterator <String>it = s.iterator();
while(it.hasNext()){
//This line say that if element is present then it will print
System.out.println(it.next());
}
}
}
Saturday, 8 November 2014
How to Open Google Chrome browser using Selenium
First you need to download driver Server for chrome.Selenium WebDriver works very well with Mozilla Firefox because it has a built in driver server. But the same is not true Google Chrome.Google Chrome doesn’t have a built-in server so you will need a Chrome driver server for communicating your Selenium code to the browser. You can download the Chrome driver server from here.
Just download and unzip this file and add the path of that server file.I have added snapshot below.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String str[]){
//Now you have to setSet the system property and add chromedriver path into it.
//System.setProperty("webdriver.ie.driver","Chrmepath")
System.setProperty("webdriver.chrome.driver","D:\\gc\\ChromeDriver.exe");
WebDriver Drive = new ChromeDriver();
Drive.get("http://facebook.com");
}
}
This will open facebook login in your ChromeBrowser.
How to Open Internet Explorer browser using Selenium
How to open Browser in Internet Explorer
After Running this You will get a error if you haven't set System Properties For Internet Explorer.
For Resolving this you need to download Internet Explorer driver Excecutable on your system.Why you need This??InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol.You need to install the driver servers on your browser. The driver server manages the calls between the browsers and the Selenium wire protocol.Download DriverServer from Here 
Download this according to to operating system.For 32-bit Click on 32.For 64 Click on 64bit....Now Next step is to set SystemProperty.And launch your ie browser.Just you need to give the path where you download that IEDriver.exe.Don't Run this exe file.Just give that path.
Code for Internet Explorer
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class LaunchIntrntBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","YourIEpath");
System.setProperty("webdriver.ie.driver","D:\\frustate\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://facebook.com");
}
}
This will launch Internet Browser browser successfully.
How to open Firefox Browser using selenium
How To launch Firefox Browser in Selenium.
Step1:First configure jar file in your project(How to configure click here) Then write a small script which i have added below.
What is an alert/How to handle alert in selenium.
Alert is a common scenario for all the testers.For example if you are performing an action on a specific button like delete or save then you will get an alert box.
If you doing a registration on a website.Then you can get an alert box.This came for your confirmation.In this scenario I am going to tell you all when I clicked on delete button of my web application i get this alert box.Then i will tell How to handle this alert box.
Web Driver provides a more efficient manner to handle all these events through the Alert interface, using the following methods:
There are four methods to work with alertbox.
void dismiss();
void accept();
String getText();
void sendKeys(String keysToSend);
Case1:
How to click on cancel on alert Box?
If you want to click on cancel button then use void.dismiss();
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert = driver.switchTo().alert(); //Switch to alert pop-up
myAlert.dismiss();//click on cancel button
Case2:
How to click on ok on alert Box?
If you want to click on ok button then use void accept();
driver.findElement(By.id('id of Delete button')).click();
//click on delete button
Alert myAlert = driver.switchTo().alert(); //Switch to alert pop-up
myAlert.accept(); //click on ok button
Case3:
How to getText from alert Box?
If you want to getText from pop up.
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert= driver.switchTo().alert();//Switch to alert pop-up
System.out.println(myAlert.getText());
Case4:
How to enter keys in alert box and click on ok?
If you want to enter keys in alert box.
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert=driver.switchTo().alert();//Switch to alert pop-up
driver.switchTo().myAlert().sendKeys("Delete");//This will enter keys in Textbox
myAlert.accept();//click on ok button
If you doing a registration on a website.Then you can get an alert box.This came for your confirmation.In this scenario I am going to tell you all when I clicked on delete button of my web application i get this alert box.Then i will tell How to handle this alert box.
Web Driver provides a more efficient manner to handle all these events through the Alert interface, using the following methods:
There are four methods to work with alertbox.
void dismiss();
void accept();
String getText();
void sendKeys(String keysToSend);
Case1:
How to click on cancel on alert Box?
If you want to click on cancel button then use void.dismiss();
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert = driver.switchTo().alert(); //Switch to alert pop-up
myAlert.dismiss();//click on cancel button
Case2:
How to click on ok on alert Box?
If you want to click on ok button then use void accept();
driver.findElement(By.id('id of Delete button')).click();
//click on delete button
Alert myAlert = driver.switchTo().alert(); //Switch to alert pop-up
myAlert.accept(); //click on ok button
Case3:
How to getText from alert Box?
If you want to getText from pop up.
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert= driver.switchTo().alert();//Switch to alert pop-up
System.out.println(myAlert.getText());
Case4:
How to enter keys in alert box and click on ok?
If you want to enter keys in alert box.
//click on delete button
driver.findElement(By.id('id of Delete button')).click();
Alert myAlert=driver.switchTo().alert();//Switch to alert pop-up
driver.switchTo().myAlert().sendKeys("Delete");//This will enter keys in Textbox
myAlert.accept();//click on ok button
Friday, 7 November 2014
How to open Browser
How to open a browser??
1.WebDriver driver = new Firefox Driver();
driver.get("http://gmail.com");
or
2.WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://gmail.com");
Difference between driver.get("http://gmail.com") and driver.navigate().to("http://gmail.com");
1.driver.get();WebDriver will wait until the page has fully loaded (that is, the onload event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
2.driver.navigate to:
History and Location
Earlier, we covered navigating to a page using the get command (driver.get("http://www.example.com")) As you’ve seen, WebDriver has a number of smaller, task-focused interfaces, and navigation is a useful task. Because loading a page is such a fundamental requirement, the method to do this lives on the main WebDriver interface, but it’s simply a synonym to:driver.navigate().to("http://gmail.com");To reiterate: navigate().to() and get() do exactly the same thing.
The navigate interface also exposes the ability to move backwards and forwards in your browser’s history:driver.navigate().forward(); driver.navigate().back();
1.WebDriver driver = new Firefox Driver();
driver.get("http://gmail.com");
or
2.WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://gmail.com");
Difference between driver.get("http://gmail.com") and driver.navigate().to("http://gmail.com");
1.driver.get();WebDriver will wait until the page has fully loaded (that is, the onload event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
2.driver.navigate to:
History and Location
Earlier, we covered navigating to a page using the get command (driver.get("http://www.example.com")) As you’ve seen, WebDriver has a number of smaller, task-focused interfaces, and navigation is a useful task. Because loading a page is such a fundamental requirement, the method to do this lives on the main WebDriver interface, but it’s simply a synonym to:driver.navigate().to("http://gmail.com");To reiterate: navigate().to() and get() do exactly the same thing.
The navigate interface also exposes the ability to move backwards and forwards in your browser’s history:driver.navigate().forward(); driver.navigate().back();
Subscribe to:
Posts (Atom)




















