- sri.zampani
- Posts : 1
Join date : 2012-12-12
Browser opening many times when running the scripts
Wed Dec 12, 2012 12:21 am
Hi all,
i am running test cases using the eclipse framework, using webdriver the error i am getting is the browser is opening many times.......i am not able to figure out where is the problem....below is the code of my KEYWORDS.......and also data is not getting input in the browser when opened
KEYWORDS:
===========
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
public class Keywords {
public static Xls_Reader xls = new Xls_Reader(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\xls\\Test Suite1.xlsx");
static Keywords keywords=null;
public Properties CONFIG=null;
public Properties OR=null;
public WebDriver driver=null;
private Keywords(){
System.out.println("Initializing Keywords");
try {
CONFIG = new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\config\\config.properties");
CONFIG.load(fs);
OR = new Properties();
fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\config\\OR.properties");
OR.load(fs);
} catch (Exception e) {
e.printStackTrace();
}
}
public void executeKeywords(String testName,Hashtable data){
System.out.println("Executing - "+testName);
String keywords=null;
String objectKey=null;
String dataColVal=null;
for(int rNum=2;rNum<=xls.getRowCount("Test Steps");rNum++){
if(testName.equals(xls.getCellData("Test Steps", "TCID", rNum))){
keywords=xls.getCellData("Test Steps", "Keywords", rNum);
objectKey=xls.getCellData("Test Steps", "Object", rNum);
dataColVal=xls.getCellData("Test Steps", "Data", rNum);
String result=null;
http://System.out.println(keywords +" -- "+objectKey+" -- "+ dataColVal);
if(keywords.equals("OpenBrowser"))
result=OpenBrowser(dataColVal);
else if (keywords.equals("Click"))
result=Click(objectKey);
else if (keywords.equals("Navigate"))
result=Navigate(dataColVal);
else if (keywords.equals("VerifyText"))
result=VerifyText();
else if (keywords.equals("Input"))
result=Input(objectKey,data.get(dataColVal));
System.out.println(result);
if(!result.equals("Pass")){
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String fileName=testName+"_"+keywords+".jpg";
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//screenshots//"+fileName));
} catch (IOException e) {
System.out.println("****ERR****");
e.printStackTrace();
}
Assert.assertTrue(false, result);
}
}
}
}
public String OpenBrowser(String browserType){
System.out.println("Executing OpenBrowser");
if(CONFIG.getProperty(browserType).equals("Mozilla"))
driver= new FirefoxDriver();
else if(CONFIG.getProperty(browserType).equals("Chrome")){
System.setProperty("webdriver.chrome.driver", "C:\\Users\\sri.zampani\\Downloads\\chromedriver_win_23.0.1240.0\\chromedriver.exe");
driver= new ChromeDriver();
}
else if(CONFIG.getProperty(browserType).equals("IE"))
driver= new InternetExplorerDriver();
return "Pass";
}
public String Navigate(String URLKey){
System.out.println("Executing Navigate");
try{
driver.get(CONFIG.getProperty(URLKey));
}catch(Exception e){
return "Fail - not able to be Navigate";
}
return "Pass";
}
public String VerifyText(){
System.out.println("Executing VerifyText");
return "Pass";
}
public String Input(String xpathKey,String data){
System.out.println("Executing Input");
try{
driver.findElement(By.xpath(OR.getProperty(xpathKey))).sendKeys(data);
}catch(Exception e){
return "Fail - not able to enter data in input box -"+xpathKey;
}
return "Pass";
}
public String Click(String xpathKey){
System.out.println("Executing Click");
try{
driver.findElement(By.xpath(OR.getProperty(xpathKey))).click();
}catch(Exception e){
return "Fail - not able to Click -"+xpathKey;
}
return "Pass";
}
//************Singleton function*************//
public static Keywords getKeywordsInstance(){
if(keywords == null){
keywords = new Keywords();
}
return keywords;
}
}
i am running test cases using the eclipse framework, using webdriver the error i am getting is the browser is opening many times.......i am not able to figure out where is the problem....below is the code of my KEYWORDS.......and also data is not getting input in the browser when opened
KEYWORDS:
===========
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
public class Keywords {
public static Xls_Reader xls = new Xls_Reader(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\xls\\Test Suite1.xlsx");
static Keywords keywords=null;
public Properties CONFIG=null;
public Properties OR=null;
public WebDriver driver=null;
private Keywords(){
System.out.println("Initializing Keywords");
try {
CONFIG = new Properties();
FileInputStream fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\config\\config.properties");
CONFIG.load(fs);
OR = new Properties();
fs = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\qtpselenium\\hybrid\\config\\OR.properties");
OR.load(fs);
} catch (Exception e) {
e.printStackTrace();
}
}
public void executeKeywords(String testName,Hashtable
System.out.println("Executing - "+testName);
String keywords=null;
String objectKey=null;
String dataColVal=null;
for(int rNum=2;rNum<=xls.getRowCount("Test Steps");rNum++){
if(testName.equals(xls.getCellData("Test Steps", "TCID", rNum))){
keywords=xls.getCellData("Test Steps", "Keywords", rNum);
objectKey=xls.getCellData("Test Steps", "Object", rNum);
dataColVal=xls.getCellData("Test Steps", "Data", rNum);
String result=null;
http://System.out.println(keywords +" -- "+objectKey+" -- "+ dataColVal);
if(keywords.equals("OpenBrowser"))
result=OpenBrowser(dataColVal);
else if (keywords.equals("Click"))
result=Click(objectKey);
else if (keywords.equals("Navigate"))
result=Navigate(dataColVal);
else if (keywords.equals("VerifyText"))
result=VerifyText();
else if (keywords.equals("Input"))
result=Input(objectKey,data.get(dataColVal));
System.out.println(result);
if(!result.equals("Pass")){
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String fileName=testName+"_"+keywords+".jpg";
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//screenshots//"+fileName));
} catch (IOException e) {
System.out.println("****ERR****");
e.printStackTrace();
}
Assert.assertTrue(false, result);
}
}
}
}
public String OpenBrowser(String browserType){
System.out.println("Executing OpenBrowser");
if(CONFIG.getProperty(browserType).equals("Mozilla"))
driver= new FirefoxDriver();
else if(CONFIG.getProperty(browserType).equals("Chrome")){
System.setProperty("webdriver.chrome.driver", "C:\\Users\\sri.zampani\\Downloads\\chromedriver_win_23.0.1240.0\\chromedriver.exe");
driver= new ChromeDriver();
}
else if(CONFIG.getProperty(browserType).equals("IE"))
driver= new InternetExplorerDriver();
return "Pass";
}
public String Navigate(String URLKey){
System.out.println("Executing Navigate");
try{
driver.get(CONFIG.getProperty(URLKey));
}catch(Exception e){
return "Fail - not able to be Navigate";
}
return "Pass";
}
public String VerifyText(){
System.out.println("Executing VerifyText");
return "Pass";
}
public String Input(String xpathKey,String data){
System.out.println("Executing Input");
try{
driver.findElement(By.xpath(OR.getProperty(xpathKey))).sendKeys(data);
}catch(Exception e){
return "Fail - not able to enter data in input box -"+xpathKey;
}
return "Pass";
}
public String Click(String xpathKey){
System.out.println("Executing Click");
try{
driver.findElement(By.xpath(OR.getProperty(xpathKey))).click();
}catch(Exception e){
return "Fail - not able to Click -"+xpathKey;
}
return "Pass";
}
//************Singleton function*************//
public static Keywords getKeywordsInstance(){
if(keywords == null){
keywords = new Keywords();
}
return keywords;
}
}
- AutobotsAssemble
- Posts : 2
Join date : 2012-12-18
Re: Browser opening many times when running the scripts
Tue Dec 18, 2012 6:16 am
Hi, I'm not sure I understand your question - are you saying you want all actions to work on the same browser window, and instead they are operating on different browser windows? If that's the case there is probably something wrong with your singleton implementation. Ensure all variables that should be static are.
- How to run the selenium scripts in already opened firefox browser.
- Calender is not running in Scripts
- Selenium WebDriver - Scripts are not running through Jenkins where as working fine locally - Mac OS
- While Recording in Selenium IDE, another browser is not opening
- Multiple tabs opening using single browser
Permissions in this forum:
You cannot reply to topics in this forum