Skip to content

Commit

Permalink
Merge pull request #17 from mattebit/main
Browse files Browse the repository at this point in the history
feat: added verification when selecting new driver
  • Loading branch information
mattebit authored Oct 10, 2024
2 parents e7dfece + 1f28f26 commit 41bc054
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 21 deletions.
21 changes: 21 additions & 0 deletions tool/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 35 additions & 17 deletions tool/src/main/java/migt/ExecuteTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@ public ExecuteTrack(boolean isHeadless,
}

/**
* Registers the execute track listener, used to communicate with the ExecuteTrack thread
* Init the driver for the selected browser.
*
* @param listener the listener
* @param chrome_selected True to select Chrome or False to select Firefox
* @param port the port to be used
* @param driver_path the absolute path to the driver executable to be used
* @return the driver object
*/
public void registerExecuteTrackListener(ExecuteTrackListener listener) {
this.listener = listener;
}

/**
* Runs the session track
*/
@Override
public void run() {
WebDriver driver;
int TIMEOUT = 10;
public static WebDriver init_driver(
boolean chrome_selected,
String port,
String driver_path,
boolean headless) {

WebDriver driver = null;
if (chrome_selected) {
ChromeOptions options = new ChromeOptions();
options.addArguments("ignore-certificate-errors");
Expand All @@ -80,14 +78,13 @@ public void run() {
proxy.setHttpProxy("localhost:" + port);
proxy.setSslProxy("localhost:" + port);
options.setCapability(CapabilityType.PROXY, proxy);
//options.setHeadless(isHeadless);
if (headless) options.addArguments("--headless");

System.setProperty("webdriver.chrome.driver", driver_path);
try {
driver = new ChromeDriver(options);
} catch (SessionNotCreatedException e) {
e.printStackTrace();
return;
}

} else {
Expand All @@ -98,17 +95,38 @@ public void run() {
proxy.setHttpProxy("localhost:" + port);
proxy.setSslProxy("localhost:" + port);
options.setCapability(CapabilityType.PROXY, proxy);
//options.setHeadless(isHeadless);
if (headless) options.addArguments("--headless");

System.setProperty("webdriver.gecko.driver", driver_path);
try {
driver = new FirefoxDriver(options);
} catch (SessionNotCreatedException e) {
e.printStackTrace();
return;
}
}

return driver;
}

/**
* Registers the execute track listener, used to communicate with the ExecuteTrack thread
*
* @param listener the listener
*/
public void registerExecuteTrackListener(ExecuteTrackListener listener) {
this.listener = listener;
}

/**
* Runs the session track
*/
@Override
public void run() {
WebDriver driver;
int TIMEOUT = 10;

driver = init_driver(chrome_selected, port, driver_path, false);

WebElement currentElement = null;
int act_window_index = 0;

Expand Down
31 changes: 27 additions & 4 deletions tool/src/main/java/migt/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.WebDriver;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
Expand Down Expand Up @@ -215,6 +216,24 @@ public void init() {
txt_err_debug_tab = new JTextArea();
}

public boolean is_driver_path_valid() {
WebDriver driver = ExecuteTrack.init_driver(
!btnselectChrome.isEnabled(),
Integer.toString(DEFAULT_PORT),
DRIVER_PATH,
true);

boolean res = driver != null;
if (!res) {
System.out.println("The selenium driver executable is not working");
} else {
driver.quit();
}

driver = null; // Free up
return res;
}

/**
* Set a redirect of the stdout and stderr to the txtboxes in the debug tab of the GUI
*/
Expand Down Expand Up @@ -869,10 +888,14 @@ private void setup_tab_butons() {
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = driverSelector.getSelectedFile();
DRIVER_PATH = file.getPath();
editConfigFile("last_driver_path", DRIVER_PATH);
lbldriver.setText("Driver Selected");
btndriverSelector.setBackground(Color.GREEN);
btnTestTrack.setEnabled(true);
if (is_driver_path_valid()) {
editConfigFile("last_driver_path", DRIVER_PATH);
lbldriver.setText("Driver Selected");
btndriverSelector.setBackground(Color.GREEN);
btnTestTrack.setEnabled(true);
} else {
lbldriver.setText("Driver:selected executable seems to not work, check logs");
}
} else if ((returnVal == JFileChooser.ERROR) || (returnVal == JFileChooser.ERROR_OPTION)) {
lbldriver.setText("Driver:error during file selection");
System.out.println("error during file selection");
Expand Down

0 comments on commit 41bc054

Please sign in to comment.