Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
sri.zampani
Posts : 1
Join date : 2012-12-12

Browser opening many times when running the scripts Empty 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;
}




}
avatar
AutobotsAssemble
Posts : 2
Join date : 2012-12-18

Browser opening many times when running the scripts Empty 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.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum