Run Script Multiple Times through TestNG-High Priority

172 views
Skip to first unread message

Santosh Hulisandra Srikanta

unread,
Sep 13, 2012, 2:59:37 PM9/13/12
to testng...@googlegroups.com
Hi All,

I want run the below script multiple times on TestNG below is sample code.
I want the script to execute one instance after other it works some times but some times it launches browser instances in parallel Please let me know how to handle this and make sure that 
script execution is sequential.

package com.falcon.settings;
import org.testng.annotations.*;
import com.slingmedia.automation.SeleniumConfig.FalconSettings;
import com.slingmedia.automation.SeleniumConfig.SeleniumConfig;
import com.slingmedia.falcon.Falcon_BrowserQuitAndRelaunch;

public class OOBFlow {

SeleniumConfig sel=new SeleniumConfig();
FalconSettings watch=new FalconSettings();
int iteration_count=0;

@BeforeClass
public void setEnvironment() throws Exception {
watch.loadProperty("C:\\Automation\\Falcon\\falcon.properties");
iteration_count=Integer.parseInt(System.getProperty("iteration_count").trim());
}

@BeforeTest
public void startBrowser() throws Exception {
watch.startSelenium();
}

@Test

public void launchFalcon()throws Exception{
watch.deleteAllCookie();
watch.launchFalcon();
}

@Test(dependsOnMethods = { "launchFalcon" })
public void selectCountry()throws Exception{
watch.countrySelection();
}

@Test(dependsOnMethods = { "selectCountry" })
public void loginToSlingAccounts()throws Exception{
watch.loginToAccounts();
}

@Test(dependsOnMethods = { "loginToSlingAccounts" })
public void connectToBoxFromDirectory()throws Exception{
watch.cancelFastConnect();
sel.waitForAction(2);
watch.connectToUnconfiguredBox();
}

@AfterTest
public void closeBrowser()throws Exception{

watch.resetSlingbox();
sel.waitForAction(10);
watch.StopSelenium();


}

@Factory
public Object[] createInstances() throws Exception {

OOBFlow falcon=new OOBFlow();
falcon.setEnvironment();
iteration_count=falcon.iteration_count;
System.out.println(iteration_count);
Object[] result = new Object[iteration_count];
for (int i = 0; i < iteration_count; i++) {
result[i] = new OOBFlow();
}
return result;
}

}


And below is the code which shows how i am invoking Selenium 
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Selenium selenium;
WebDriver driver; 
public void startSelenium() throws Exception {


if (System.getProperty("browser").trim().toLowerCase().equals("ie")){
System.setProperty("webdriver.ie.driver",System.getProperty("IeDriverPath").trim());
driver = new InternetExplorerDriver();
selenium = new WebDriverBackedSelenium(driver, "http://www.google.co.in");
}

else if (System.getProperty("browser").trim().toLowerCase().equals("ff") && (System.getProperty("os.name").toLowerCase().contains("window"))){

System.setProperty("webdriver.firefox.profile", "default");
driver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(driver, "http://www.google.co.in");
}

else if (System.getProperty("browser").trim().toLowerCase().equals("ff") &&(System.getProperty("os.name").toLowerCase().contains("mac"))){

driver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(driver, "http://www.google.co.in");
}

else if (System.getProperty("browser").trim().toLowerCase().equals("gc") && (System.getProperty("os.name").toLowerCase().contains("mac"))){

System.setProperty("webdriver.chrome.driver",System.getProperty("ChromeDriverPath").trim());
driver = new ChromeDriver();
selenium = new WebDriverBackedSelenium(driver, "http://www.google.co.in");
}

else if (System.getProperty("browser").trim().toLowerCase().equals("gc") && (System.getProperty("os.name").toLowerCase().contains("windows"))){

System.setProperty("webdriver.chrome.driver", System.getProperty("ChromeDriverPath").trim());
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir="+System.getProperty("user.home")+"\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(options);
selenium = new WebDriverBackedSelenium(driver, "http://www.google.co.in");
}

else{

System.out.println("UnSupported Browser");


Please do provide a Solution






--

/Santosh

Santosh Hulisandra Srikanta

unread,
Sep 14, 2012, 1:12:08 PM9/14/12
to testng...@googlegroups.com
Any one can help here ??/
--

/Santosh

Yevhen Bilevych

unread,
Sep 14, 2012, 5:08:25 PM9/14/12
to testng...@googlegroups.com
Santosh,

I guess that multiple browser windows you observe are not of tests running in parallel, but stale from previous failed tests. Please make sure webdriver gets surely destroyed after test.

Another issue might be that classes are run sequentially, but methods in classes in parallel. Could you please show your testng.xml?

Thanks,
Yevhen 

Sent from my BlackBerry® PlayBook™
www.blackberry.com


From: "Santosh Hulisandra Srikanta" <santos...@gmail.com>
To: "testng...@googlegroups.com" <testng...@googlegroups.com>
Sent: September 14, 2012 8:12 PM
Subject: [testng-users] Re: Run Script Multiple Times through TestNG-High Priority
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply all
Reply to author
Forward
0 new messages