@@ -54,22 +54,20 @@ public ExecuteTrack(boolean isHeadless,
54
54
}
55
55
56
56
/**
57
- * Registers the execute track listener, used to communicate with the ExecuteTrack thread
57
+ * Init the driver for the selected browser.
58
58
*
59
- * @param listener the listener
59
+ * @param chrome_selected True to select Chrome or False to select Firefox
60
+ * @param port the port to be used
61
+ * @param driver_path the absolute path to the driver executable to be used
62
+ * @return the driver object
60
63
*/
61
- public void registerExecuteTrackListener (ExecuteTrackListener listener ) {
62
- this .listener = listener ;
63
- }
64
-
65
- /**
66
- * Runs the session track
67
- */
68
- @ Override
69
- public void run () {
70
- WebDriver driver ;
71
- int TIMEOUT = 10 ;
64
+ public static WebDriver init_driver (
65
+ boolean chrome_selected ,
66
+ String port ,
67
+ String driver_path ,
68
+ boolean headless ) {
72
69
70
+ WebDriver driver = null ;
73
71
if (chrome_selected ) {
74
72
ChromeOptions options = new ChromeOptions ();
75
73
options .addArguments ("ignore-certificate-errors" );
@@ -80,14 +78,13 @@ public void run() {
80
78
proxy .setHttpProxy ("localhost:" + port );
81
79
proxy .setSslProxy ("localhost:" + port );
82
80
options .setCapability (CapabilityType .PROXY , proxy );
83
- // options.setHeadless(isHeadless );
81
+ if ( headless ) options .addArguments ( "--headless" );
84
82
85
83
System .setProperty ("webdriver.chrome.driver" , driver_path );
86
84
try {
87
85
driver = new ChromeDriver (options );
88
86
} catch (SessionNotCreatedException e ) {
89
87
e .printStackTrace ();
90
- return ;
91
88
}
92
89
93
90
} else {
@@ -98,17 +95,38 @@ public void run() {
98
95
proxy .setHttpProxy ("localhost:" + port );
99
96
proxy .setSslProxy ("localhost:" + port );
100
97
options .setCapability (CapabilityType .PROXY , proxy );
101
- // options.setHeadless(isHeadless );
98
+ if ( headless ) options .addArguments ( "--headless" );
102
99
103
100
System .setProperty ("webdriver.gecko.driver" , driver_path );
104
101
try {
105
102
driver = new FirefoxDriver (options );
106
103
} catch (SessionNotCreatedException e ) {
107
104
e .printStackTrace ();
108
- return ;
109
105
}
110
106
}
111
107
108
+ return driver ;
109
+ }
110
+
111
+ /**
112
+ * Registers the execute track listener, used to communicate with the ExecuteTrack thread
113
+ *
114
+ * @param listener the listener
115
+ */
116
+ public void registerExecuteTrackListener (ExecuteTrackListener listener ) {
117
+ this .listener = listener ;
118
+ }
119
+
120
+ /**
121
+ * Runs the session track
122
+ */
123
+ @ Override
124
+ public void run () {
125
+ WebDriver driver ;
126
+ int TIMEOUT = 10 ;
127
+
128
+ driver = init_driver (chrome_selected , port , driver_path , false );
129
+
112
130
WebElement currentElement = null ;
113
131
int act_window_index = 0 ;
114
132
0 commit comments