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();
}
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();
}
else if (System.getProperty("browser").trim().toLowerCase().equals("ff") &&(System.getProperty("
os.name").toLowerCase().contains("mac"))){
driver = new FirefoxDriver();
}
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();
}
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);
}
else{
System.out.println("UnSupported Browser");
}