use of org.openqa.selenium.chrome.ChromeOptions in project irida by phac-nml.
the class IntegrationUITestListener method startWebDriver.
/**
* Start the web driver.
*/
public static void startWebDriver() {
ChromeOptions options = new ChromeOptions();
/*
* Run chrome in no sandbox mode. Only use this option for running tests
* in docker containers.
*/
String noSandbox = System.getProperty("irida.it.nosandbox");
if (noSandbox != null && noSandbox.equals("true")) {
logger.warn("Running Chrome in no sandbox mode");
options.addArguments("--no-sandbox");
}
// Run chrome in headless mode
String headless = System.getProperty("irida.it.headless");
if (headless != null && headless.equals("true")) {
logger.info("Running Chome in headless mode");
options.addArguments("headless");
} else {
logger.info("Running Chome in no headless (normal) mode");
}
options.addArguments("window-size=1400x900");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(DRIVER_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS);
}
use of org.openqa.selenium.chrome.ChromeOptions in project browsermator by pcalkins.
the class RunAllTests method RunAllActions.
public void RunAllActions(SeleniumTestTool STAppFrame, SeleniumTestToolData STAppData, String TargetBrowser, String OSType) {
STAppData.TimeOfRun = LocalDateTime.now();
File thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
switch(TargetBrowser) {
case "Firefox-Marionette":
if ("Windows".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win32"+File.separator+"geckodriver.exe");
}
if ("Windows32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win32"+File.separator+"geckodriver.exe");
}
if ("Windows64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win64" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-win64"+File.separator+"geckodriver.exe");
}
if ("Mac".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-osx" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-osx"+File.separator+"geckodriver");
}
if ("Linux-32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux32" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-linux32"+File.separator+"geckodriver");
}
if ("Linux-64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux64" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", "lib"+File.separator+"geckodriver-linux64"+File.separator+"geckodriver");
}
if (firefox_path != null) {
System.setProperty("webdriver.firefox.bin", firefox_path);
}
try {
// FirefoxProfile profile = new FirefoxProfile();
// DesiredCapabilities cap = DesiredCapabilities.firefox();
// cap.setJavascriptEnabled(true);
// cap.setCapability("marionette", false);
// profile.setPreference("dom.max_script_run_time", 1);
driver = new FirefoxDriver();
// driver = new MarionetteDriver();
} catch (Exception ex) {
System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString());
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch Marionette driver:" + ex.toString(), false, 0, 0);
}
break;
case "Firefox":
if ("Windows".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
}
if ("Windows32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win32" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
}
if ("Windows64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-win64" + File.separator + "geckodriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-win64"+File.separator+"geckodriver.exe");
}
if ("Mac".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-osx" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-osx"+File.separator+"geckodriver");
}
if ("Linux-32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux32" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver",BMPATH+File.separator+ "lib"+File.separator+"geckodriver-linux32"+File.separator+"geckodriver");
}
if ("Linux-64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "geckodriver-linux64" + File.separator + "geckodriver");
setPermissions(thisDriver);
System.setProperty("webdriver.gecko.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.gecko.driver", BMPATH+File.separator+"lib"+File.separator+"geckodriver-linux64"+File.separator+"geckodriver");
}
if (firefox_path != null) {
System.setProperty("webdriver.firefox.bin", firefox_path);
}
try {
// DesiredCapabilities cap = DesiredCapabilities.firefox();
// cap.setJavascriptEnabled(false);
// FirefoxProfile profile = new FirefoxProfile();
// DesiredCapabilities cap = DesiredCapabilities.firefox();
// cap.setJavascriptEnabled(true);
// cap.setCapability("marionette", true);
// profile.setPreference("dom.max_script_run_time", 30);
driver = new FirefoxDriver();
// driver = new MarionetteDriver();
} catch (Exception ex) {
System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: " + ex.toString());
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Marionette driver: " + ex.toString(), false, 0, 0);
}
break;
case "Silent Mode (HTMLUnit)":
driver = new HtmlUnitDriver();
break;
case "Internet Explorer-32":
thisDriver = new File(WEBDRIVERSDIR + "iedriverserver_win32" + File.separator + "IEDriverServer.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.ie.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.ie.driver", BMPATH+File.separator+"lib"+File.separator+"iedriverserver_win32"+File.separator+"IEDriverServer.exe");
try {
driver = new InternetExplorerDriver();
} catch (Exception ex) {
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch IEdriver:" + ex.toString(), false, 0, 0);
}
break;
case "Internet Explorer-64":
thisDriver = new File(WEBDRIVERSDIR + "iedriverserver_win64" + File.separator + "IEDriverServer.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.ie.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.ie.driver",BMPATH+File.separator+ "lib"+File.separator+"iedriverserver_win64"+File.separator+"IEDriverServer.exe");
try {
driver = new InternetExplorerDriver();
} catch (Exception ex) {
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch IEdriver: " + ex.toString(), false, 0, 0);
}
break;
case "Chrome":
// legacy support
ChromeOptions options = new ChromeOptions();
if (chrome_main_path != null) {
options.setBinary(chrome_main_path);
}
if ("Windows".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
}
if ("Windows32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
}
if ("Windows64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_win32"+File.separator+"chromedriver.exe");
}
if ("Mac".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_mac64" + File.separator + "chromedriver");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_mac64"+File.separator+"chromedriver");
}
if ("Linux-32".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux32" + File.separator + "chromedriver");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver",BMPATH+File.separator+ "lib"+File.separator+"chromedriver_linux32"+File.separator+"chromedriver");
}
if ("Linux-64".equals(OSType)) {
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_linux64" + File.separator + "chromedriver");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.chrome.driver", BMPATH+File.separator+"lib"+File.separator+"chromedriver_linux64"+File.separator+"chromedriver");
}
try {
driver = new ChromeDriver(options);
} catch (Exception ex) {
System.out.println("Problem launching Chromedriver: " + ex.toString());
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Chromedriver." + ex.toString(), false, 0, 0);
}
break;
case "Chrome 49":
ChromeOptions options49 = new ChromeOptions();
if (chrome_path != null) {
options49.setBinary(chrome_path);
}
thisDriver = new File(WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver-winxp.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.chrome.driver", thisDriver.getAbsolutePath());
try {
driver = new ChromeDriver(options49);
} catch (Exception ex) {
System.out.println("Problem launching Chromedriver 49: " + ex.toString());
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Chrome 49 driver." + ex.toString(), false, 0, 0);
}
break;
case "Edge":
thisDriver = new File(WEBDRIVERSDIR + "edgedriver" + File.separator + "MicrosoftWebDriver.exe");
setPermissions(thisDriver);
System.setProperty("webdriver.edge.driver", thisDriver.getAbsolutePath());
// System.setProperty("webdriver.edge.driver", BMPATH+File.separator+"lib"+File.separator+"edgedriver"+File.separator+"MicrosoftWebDriver.exe");
try {
driver = new EdgeDriver();
} catch (Exception ex) {
System.out.println("Problem launching EdgeDriver: " + ex.toString());
Prompter fallbackprompt = new Prompter("Driver Error", "Could not launch the Edge Driver. " + ex.toString(), false, 0, 0);
}
break;
}
int WaitTime = 0;
WaitTime = STAppData.getWaitTime();
// timeouts still buggy.. removed
// int Timeout = SiteTest.getTimeout();
// int Timeout = 5;
// driver.manage().timeouts().implicitlyWait(Timeout, TimeUnit.SECONDS);
// driver.manage().timeouts().pageLoadTimeout(Timeout, TimeUnit.SECONDS);
// driver.manage().timeouts().setScriptTimeout(Timeout, TimeUnit.SECONDS);
int totalpause = WaitTime * 1000;
int thisbugindex = 0;
for (Procedure thisbug : STAppData.BugArray) {
String bugtitle = STAppData.BugArray.get(thisbugindex).getBugTitle();
if (RUNWITHGUI) {
LoudCall<Void, String> procMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(bugtitle);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(procMethod) {
@Override
protected void process(List<String> chunks) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}).execute();
STAppFrame.BugViewArray.get(thisbugindex).JButtonRunTest.setText("Running...");
}
int bug_INT = thisbugindex + 1;
String bug_ID = Integer.toString(bug_INT);
int action_INT = 0;
String action_ID = "";
if (!"Dataloop".equals(thisbug.Type)) {
action_INT = 0;
for (Action ThisAction : thisbug.ActionsList) {
if (STAppData.cancelled) {
publish(thisbugindex);
break;
}
waitWhenPaused();
action_INT++;
action_ID = Integer.toString(action_INT);
if (!ThisAction.Locked) {
if (RUNWITHGUI) {
String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(action_title);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(actMethod) {
@Override
protected void process(List<String> chunks) {
if (chunks.size() > 0) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}
}).execute();
}
if (totalpause > 0) {
try {
Thread.sleep(totalpause);
} catch (Exception ex) {
System.out.println("Exception when sleeping: " + ex.toString());
ThisAction.Pass = false;
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
publish(thisbugindex);
}
break;
}
}
String varfieldname = "";
if (ThisAction.Variable2.contains("[stored_varname-start]") || ThisAction.Variable1.contains("[stored_varname-start]")) {
if (ThisAction.Variable2.contains("[stored_varname-start]")) {
varfieldname = ThisAction.Variable1;
// indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
// assuming name of "[stored_varname-start]" and "[stored_varname-end]"
String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
String fieldname = split_testfield_end[0].substring(22);
ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
ThisAction.RunAction(driver);
ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
} else {
if (ThisAction.Variable1.contains("[stored_varname-start]")) {
varfieldname = ThisAction.Variable1;
// indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
// assuming name of "[stored_varname-start]" and "[stored_varname-end]"
String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
String fieldname = split_testfield_end[0].substring(22);
ThisAction.Variable1 = STAppData.GetStoredVariableValue(fieldname);
ThisAction.RunAction(driver);
ThisAction.Variable1 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
}
}
} else {
if ("Pause with Continue Button".equals(ThisAction.Type)) {
int nothing = ThisAction.RunAction(driver, "Actions Paused...", STAppData, 0, 0);
} else {
ThisAction.RunAction(driver);
}
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
}
}
if (!"".equals(ThisAction.tostore_varvalue)) {
STAppData.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
}
if (ThisAction.tostore_varlist.size() > 0) {
STAppData.VarLists.put(ThisAction.Variable2, ThisAction.tostore_varlist);
}
if (STAppData.getIncludeScreenshots()) {
try {
File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
full_scrn.deleteOnExit();
ThisAction.ScreenshotBase64 = "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>";
} catch (Exception ex) {
ThisAction.ScreenshotBase64 = "Screenshot Failed";
// System.out.println("Exception creating screenshot: " + ex.toString());
}
} else {
ThisAction.ScreenshotBase64 = "";
}
} else {
ThisAction.ScreenshotBase64 = "";
ThisAction.Pass = true;
}
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
}
}
int actionspassed = 0;
for (Action thisaction : thisbug.ActionsList) {
Boolean passvalue = thisaction.Pass;
if (passvalue) {
actionspassed++;
}
}
int sizeof = thisbug.ActionsList.size();
if (actionspassed == sizeof) {
thisbug.Pass = true;
} else {
thisbug.Pass = false;
}
} else {
int number_of_rows = 0;
if ("urllist".equals(thisbug.DataLoopSource)) {
if (thisbug.getLimit() > 0 || thisbug.getRandom()) {
thisbug.setURListRunTimeData(STAppData.RandomizeAndLimitURLList(thisbug.URLListName, thisbug.getLimit(), thisbug.getRandom()), thisbug.URLListName);
} else {
thisbug.setURListRunTimeData(STAppData.VarLists.get(thisbug.URLListName), thisbug.URLListName);
}
number_of_rows = thisbug.URLListRunTimeEntries.size();
if (RUNWITHGUI) {
if (number_of_rows > 0) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.setJTableSourceToURLList(thisbug.URLListRunTimeEntries, thisbug.URLListName);
}
}
} else {
if ("file".equals(thisbug.DataLoopSource)) {
if (thisbug.getLimit() > 0 || thisbug.getRandom()) {
if (STAppData.getDataSetByFileName(thisbug.DataFile).size() > 0) {
List<String[]> randomList = STAppData.RandomizeAndLimitFileList(STAppData.getDataSetByFileName(thisbug.DataFile), thisbug.getLimit(), thisbug.getRandom());
thisbug.setRunTimeFileSet(randomList);
}
} else {
thisbug.setRunTimeFileSet(STAppData.getDataSetByFileName(thisbug.DataFile));
}
number_of_rows = thisbug.RunTimeFileSet.size();
}
}
for (Action ThisAction : thisbug.ActionsList) {
ThisAction.InitializeLoopTestVars(number_of_rows);
}
for (int x = 0; x < number_of_rows; x++) {
int changex = -1;
action_INT = 0;
for (Action ThisAction : thisbug.ActionsList) {
if (STAppData.cancelled) {
publish(thisbugindex);
break;
}
waitWhenPaused();
action_INT++;
action_ID = Integer.toString(action_INT) + "-" + Integer.toString(x);
String original_value1 = ThisAction.Variable1;
String original_value2 = ThisAction.Variable2;
if (!ThisAction.Locked) {
DataLoopVarParser var1Parser = new DataLoopVarParser(ThisAction.Variable1);
DataLoopVarParser var2Parser = new DataLoopVarParser(ThisAction.Variable2);
if (var1Parser.hasDataLoopVar == false && var2Parser.hasDataLoopVar == false) {
if ("Pause with Continue Button".equals(ThisAction.Type)) {
String pause_message = "Paused at record " + (x + 1) + " of " + number_of_rows;
changex = ThisAction.RunAction(driver, pause_message, STAppData, x, number_of_rows);
ThisAction.loop_pass_values.set(x, ThisAction.Pass);
ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
if (STAppData.getIncludeScreenshots()) {
ThisAction.loop_ScreenshotsBase64.set(x, "<img id = \"Screenshot" + bug_ID + "-" + action_ID + "\" class = \"report_screenshots\" style = \"display: none;\" src=\"\"></img>");
} else {
ThisAction.loop_ScreenshotsBase64.set(x, "");
}
} else {
try {
if (totalpause > 0) {
try {
Thread.sleep(totalpause);
} catch (Exception ex) {
System.out.println("Exception when sleeping: " + ex.toString());
ThisAction.Pass = false;
publish(thisbugindex);
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.Pass);
}
break;
}
}
String varfieldname = "";
if (ThisAction.Variable2.contains("[stored_varname-start]") || ThisAction.Variable1.contains("[stored_varname-start]")) {
if (ThisAction.Variable2.contains("[stored_varname-start]")) {
varfieldname = ThisAction.Variable1;
// indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
// assuming name of "[stored_varname-start]" and "[stored_varname-end]"
String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
String fieldname = split_testfield_end[0].substring(22);
ThisAction.Variable2 = STAppData.GetStoredVariableValue(fieldname);
String action_title3 = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
if (RUNWITHGUI) {
LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(action_title3);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(actMethod) {
@Override
protected void process(List<String> chunks) {
if (chunks.size() > 0) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}
}).execute();
}
ThisAction.RunAction(driver);
ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
} else {
if (ThisAction.Variable1.contains("[stored_varname-start]")) {
varfieldname = ThisAction.Variable1;
// indexof_end_tag = varfieldname.indexOf("[stored_varname_end]")-1;
// assuming name of "[stored_varname-start]" and "[stored_varname-end]"
String[] split_testfield_end = varfieldname.split("\\[stored_varname\\-end\\]");
String fieldname = split_testfield_end[0].substring(22);
ThisAction.Variable1 = STAppData.GetStoredVariableValue(fieldname);
if (RUNWITHGUI) {
String action_title2 = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(action_title2);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(actMethod) {
@Override
protected void process(List<String> chunks) {
if (chunks.size() > 0) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}
}).execute();
}
ThisAction.RunAction(driver);
ThisAction.Variable1 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
}
}
} else {
if (RUNWITHGUI) {
String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(action_title);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(actMethod) {
@Override
protected void process(List<String> chunks) {
if (chunks.size() > 0) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}
}).execute();
}
ThisAction.RunAction(driver);
}
if (!"".equals(ThisAction.tostore_varvalue)) {
STAppData.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
}
ThisAction.loop_pass_values.set(x, ThisAction.Pass);
ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
} catch (Exception ex) {
ThisAction.loop_pass_values.set(x, false);
ThisAction.loop_time_of_test.set(x, LocalDateTime.now());
if (RUNWITHGUI) {
publish(thisbugindex);
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
}
break;
}
if (STAppData.getIncludeScreenshots()) {
try {
File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
full_scrn.deleteOnExit();
ThisAction.loop_ScreenshotsBase64.set(x, "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>");
} catch (Exception ex) {
ThisAction.loop_ScreenshotsBase64.set(x, "Screenshot Failed");
// System.out.println("Exception creating screenshot: " + ex.toString());
}
} else {
ThisAction.loop_ScreenshotsBase64.set(x, "");
}
}
} else {
String concat_variable = "";
String concat_variable2 = "";
if ("urllist".equals(thisbug.DataLoopSource)) {
concat_variable = var1Parser.GetFullValueFromURLList(x, thisbug.URLListRunTimeEntries);
}
if ("file".equals(thisbug.DataLoopSource)) {
concat_variable = var1Parser.GetFullValueFromFile(x, thisbug.RunTimeFileSet);
}
if (var1Parser.hasDataLoopVar) {
ThisAction.Variable1 = concat_variable;
if ("".equals(ThisAction.Variable1)) {
ThisAction.Variable1 = " ";
}
}
if ("urllist".equals(thisbug.DataLoopSource)) {
concat_variable2 = var2Parser.GetFullValueFromURLList(x, thisbug.URLListRunTimeEntries);
}
if ("file".equals(thisbug.DataLoopSource)) {
concat_variable2 = var2Parser.GetFullValueFromFile(x, thisbug.RunTimeFileSet);
}
if (var2Parser.hasDataLoopVar) {
ThisAction.Variable2 = concat_variable2;
if ("".equals(ThisAction.Variable2)) {
ThisAction.Variable2 = " ";
}
}
try {
if (totalpause > 0) {
try {
Thread.sleep(totalpause);
} catch (Exception ex) {
System.out.println("Exception when sleeping: " + ex.toString());
ThisAction.Pass = false;
if (RUNWITHGUI) {
publish(thisbugindex);
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
}
break;
}
}
if (RUNWITHGUI) {
String action_title = ThisAction.Type + ": " + ThisAction.Variable1 + " " + ThisAction.Variable2;
LoudCall<Void, String> actMethod = new LoudCall<Void, String>() {
@Override
public Void call() throws Exception {
shoutOut(action_title);
Thread.sleep(100);
return null;
}
};
(new ListenerTask<Void, String>(actMethod) {
@Override
protected void process(List<String> chunks) {
if (chunks.size() > 0) {
STAppFrame.setJTextFieldProgress(chunks.get(chunks.size() - 1));
}
}
}).execute();
}
ThisAction.RunAction(driver);
ThisAction.Variable1 = original_value1;
ThisAction.Variable2 = original_value2;
ThisAction.loop_pass_values.set(x, ThisAction.Pass);
ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
if (STAppData.getIncludeScreenshots()) {
try {
File full_scrn = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
full_scrn.deleteOnExit();
ThisAction.loop_ScreenshotsBase64.set(x, "<img src=\"file:///" + full_scrn.getAbsolutePath() + "\" id = \"Screenshot" + bug_ID + "-" + action_ID + "\" style = \"display: none;\" class = \"report_screenshots\"></img>");
} catch (Exception ex) {
ThisAction.loop_ScreenshotsBase64.set(x, "Screenshot Failed");
// System.out.println("Exception creating screenshot: " + ex.toString());
}
} else {
ThisAction.loop_ScreenshotsBase64.set(x, "");
}
} catch (Exception ex) {
ThisAction.Variable1 = original_value1;
ThisAction.Variable2 = original_value2;
ThisAction.loop_pass_values.set(x, false);
ThisAction.loop_time_of_test.set(x, LocalDateTime.now());
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
publish(thisbugindex);
}
break;
}
}
} else {
ThisAction.Pass = true;
ThisAction.loop_pass_values.set(x, ThisAction.Pass);
ThisAction.loop_time_of_test.set(x, ThisAction.TimeOfTest);
}
if (RUNWITHGUI) {
ProcedureView thisbugview = STAppFrame.BugViewArray.get(thisbugindex);
thisbugview.ActionsViewList.get(ThisAction.index).setPassState(ThisAction.loop_pass_values.get(x));
}
}
if (changex != x) {
if (changex == -1) {
} else {
x = changex - 1;
}
}
}
// check if all actions passed
int actions_passed = 0;
for (Action ThisAction : thisbug.ActionsList) {
ThisAction.Pass = false;
int loop_actions_passed = 0;
if (ThisAction.loop_pass_values.size() > 0) {
for (Boolean passvalue : ThisAction.loop_pass_values) {
if (passvalue) {
loop_actions_passed++;
}
}
}
if (loop_actions_passed == ThisAction.loop_pass_values.size()) {
ThisAction.Pass = true;
}
if (ThisAction.Pass) {
actions_passed++;
}
}
int sizeof = thisbug.ActionsList.size();
if (actions_passed == sizeof) {
thisbug.Pass = true;
} else {
thisbug.Pass = false;
}
}
publish(thisbugindex);
thisbugindex++;
}
if (STAppData.getPromptToClose() && driver != null) {
PromptToClose thisContinuePrompt = new PromptToClose(STAppData.short_filename + " - Prompt to close webdriver", "Close webdriver/browser?");
thisContinuePrompt.addjButtonRunAgainActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
RunAgain = true;
thisContinuePrompt.dispose();
boolean closecaught = false;
try {
if (driver != null) {
driver.close();
}
} catch (Exception e) {
closecaught = true;
System.out.println(e.toString());
try {
driver.quit();
} catch (Exception exce) {
System.out.println("Exception quitting" + exce.toString());
}
}
if (closecaught) {
} else {
try {
driver.quit();
} catch (Exception ex) {
// don't worry it should close
}
}
}
});
thisContinuePrompt.addjButtonCloseActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
RunAgain = false;
thisContinuePrompt.dispose();
}
});
while (thisContinuePrompt.isVisible() == true) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
System.out.println("pause exception: " + e.toString());
}
}
if (RunAgain) {
RunAllActions(STAppFrame, STAppData, targetbrowser, OSType);
}
}
}
use of org.openqa.selenium.chrome.ChromeOptions in project structr by structr.
the class SeleniumTest method startDriver.
@Before
public void startDriver() {
switch(activeBrowser) {
case FIREFOX:
System.setProperty("webdriver.gecko.driver", getBrowserDriverLocation(activeBrowser));
final FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
driver = new FirefoxDriver(firefoxOptions);
break;
case CHROME:
System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(activeBrowser));
System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
driver = new ChromeDriver(chromeOptions);
break;
case NONE:
// Don't create a driver in main thread, useful for parallel testing
break;
}
}
use of org.openqa.selenium.chrome.ChromeOptions in project structr by structr.
the class ParallelLoginTest method testParallelLogin.
@Test
public void testParallelLogin() {
// Wait for the backend to finish initialization
try {
Thread.sleep(10000L);
} catch (InterruptedException ex) {
}
createAdminUser();
final int numberOfRequests = 1000;
final int numberOfParallelThreads = 8;
final int waitForSec = 60;
final ExecutorService service = Executors.newFixedThreadPool(numberOfParallelThreads);
final List<Future<Exception>> results = new ArrayList<>();
for (int i = 0; i < numberOfRequests; i++) {
Future<Exception> result = service.submit(() -> {
// System.out.println(SimpleDateFormat.getDateInstance().format(new Date()) + " Login attempt from thread " + Thread.currentThread().toString());
logger.info("Login attempt from thread " + Thread.currentThread().toString());
final String menuEntry = "Pages";
System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(SupportedBrowsers.CHROME));
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
long t0 = System.currentTimeMillis();
// Wait for successful login
loginAsAdmin(menuEntry, driver, waitForSec);
long t1 = System.currentTimeMillis();
logger.info("Successful login after " + (t1 - t0) + " ms with thread " + Thread.currentThread().toString());
} catch (Exception ex) {
logger.error("Error in nested test in thread " + Thread.currentThread().toString(), ex);
return ex;
} finally {
driver.quit();
}
return null;
});
results.add(result);
}
int r = 0;
for (final Future<Exception> result : results) {
try {
long t0 = System.currentTimeMillis();
Exception res = result.get();
long t1 = System.currentTimeMillis();
r++;
if (res != null) {
logger.error(r + ": Got " + res + " from future after " + (t1 - t0) + " ms");
assertNull(result.get());
break;
}
} catch (final InterruptedException | ExecutionException ex) {
logger.error("Error while checking result of nested test", ex);
}
}
service.shutdown();
try {
// Typically, one login is done in under about 2 seconds, so we assume non-parallel execution and add the waiting time
Thread.sleep(1000L);
// Thread.sleep((numberOfRequests * 2000) + (waitForSec*1000));
} catch (InterruptedException ex) {
}
}
use of org.openqa.selenium.chrome.ChromeOptions in project chrome_page_performance_sqlite_java by sergueik.
the class ChromePagePerformanceUtilTest method beforeClass.
@SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() throws IOException {
getOsName();
System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : "/var/run/chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("enableNetwork", "true");
options.setExperimentalOption("prefs", chromePrefs);
for (String option : (new String[] { "allow-running-insecure-content", "allow-insecure-localhost", "enable-local-file-accesses", "disable-notifications", /* "start-maximized" , */
"browser.download.folderList=2", "--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf", String.format("browser.download.dir=%s", downloadFilepath) /* "user-data-dir=/path/to/your/custom/profile" , */
})) {
options.addArguments(option);
}
// options for headless
if (headless) {
// headless option arguments
for (String option : (osName.toLowerCase().startsWith("windows")) ? new String[] { "headless", "disable-gpu", "disable-plugins", "window-size=1200x600", "window-position=-9999,0" } : new String[] { "headless", "disable-gpu", "remote-debugging-port=9222", "window-size=1200x600" }) {
options.addArguments(option);
}
// on Windows need ChromeDriver 2.31 / Chrome 60 to support headless
// With earlier versions of chromedriver: chrome not reachable...
// https://developers.google.com/web/updates/2017/04/headless-chrome
// https://stackoverflow.com/questions/43880619/headless-chrome-and-selenium-on-windows
}
//
if (useChromeLogging) {
LoggingPreferences loggingPreferences = new LoggingPreferences();
loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
}
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new ChromeDriver(capabilities);
assertThat(driver, notNullValue());
}
Aggregations