Skip to content

Commit 5bda9fe

Browse files
committed
headless_ie_selenium. Windows Explorer does not start up in the headless desktop anymore. #16
1 parent 2c9e64a commit 5bda9fe

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ Ruby, ...).
2323

2424
Binaries can be downloaded from https://github.com/kybu/headless-selenium-for-win/releases
2525

26+
# Firefox & Chrome
27+
28+
Selenium uses "drivers" to control web browsers. They are standalone
29+
executables driving browsers. `headless_ie_selenium.exe` by default looks
30+
for the IE driver in `PATH`, but it can be instructed to use other drivers
31+
as well. All command line arguments are forwarded to the driver, so the
32+
`HEADLESS_DRIVER` environment variable is used to specify the driver. Put
33+
the driver in one of the `PATH` directories.
34+
35+
Set the `HEADLESS_SERVER` environment variable to `geckodriver.exe` for
36+
headless Firefox.
37+
2638
# Internet Explorer
2739

2840
When using IE, please pay full attention to configure the driver correctly. All
@@ -128,8 +140,10 @@ only on rare occasions:
128140

129141
## headless_ie_selenium.exe
130142

131-
This executable runs IE Webdriver `IEDriverServer.exe` headlessly. It is meant to be used by Selenium Webdriver
132-
library instead of IE Webdriver.
143+
This executable runs IE Webdriver `IEDriverServer.exe` headlessly. It is
144+
meant to be used by Selenium Webdriver library instead of IE Webdriver.
145+
Other Selenium drivers can be used by specifying `HEADLESS_DRIVER`
146+
environment variable.
133147

134148
## desktop_utils.exe
135149

@@ -155,9 +169,10 @@ Command line options:
155169

156170
Tested on Win 7.
157171

158-
Supported browsers at the moment: IE.
172+
Supported browsers: IE, Firefox, Chrome.
159173

160-
Developed using VS 2013 Express, Boost 1.59
174+
Developed using VS 2013 Express, Boost 1.59 and a bit of system level
175+
programming skills.
161176

162177
# License
163178

desktop_utils/desktop_utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ string headlessCmd,
3333
switchToDesktop,
3434

3535
header = (bo::format(
36-
"Desktop utils v%1%.%2%.alpha1, Peter Vrabel (c) 2014-2017")
36+
"Desktop utils v%1%.%2%, Peter Vrabel (c) 2014-2017")
3737
% version[0] % version[1]).str();
3838
bool noExplorer = false;
3939

headless_ie_selenium/headless_ie_selenium.cpp

+10-31
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ string findSeleniumDriver(const string &driver) {
9494
return bo::to_utf8(buffer.get());
9595
}
9696

97-
Desktop::ProcessInTheJob explorerInfo, driverInfo;
97+
Desktop::ProcessInTheJob driverInfo;
9898
HANDLE jobHandle = 0;
9999
HDESK desktopHandle = 0;
100100

@@ -107,7 +107,7 @@ void cleanUp() {
107107

108108
auto topWindows = Desktop::allTopLevelWindows(desktopName);
109109
LOGD << "Top level windows in the headless desktop: " << topWindows.size();
110-
110+
111111
for (HWND w : topWindows) {
112112
LOGT << (bo::format("Quitting the '%1%' top level window.") % w).str();
113113

@@ -119,8 +119,6 @@ void cleanUp() {
119119
LOGD << "Top level windows after sending the quit msg: "
120120
<< Desktop::allTopLevelWindows(desktopName).size();
121121

122-
Process::wait(explorerInfo.processInfo.hProcess);
123-
124122
if (jobHandle) {
125123
LOGD << "Going to close the job object.";
126124
CloseHandle(jobHandle);
@@ -180,41 +178,22 @@ int _tmain(int argc, _TCHAR* argv[])
180178
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrlHandler, TRUE);
181179

182180
desktopHandle = Desktop::create(desktopName);
183-
explorerInfo = Desktop::createProcessInTheJob(
181+
182+
driverInfo = Desktop::createProcessInTheJob(
184183
desktopName,
185-
"c:\\Windows\\explorer.exe");
184+
selDriverPath,
185+
cmdLine);
186186

187-
if (explorerInfo.status == explorerInfo.COULD_NOT_ASSIGN_JOB) {
187+
if (driverInfo.status == driverInfo.COULD_NOT_ASSIGN_JOB) {
188188
LOGW << "WARN: Could not use Windows job objects! "
189189
"That means the cleaning-up procedure might not be reliable.";
190-
ResumeThread(explorerInfo.processInfo.hThread);
190+
ResumeThread(driverInfo.processInfo.hThread);
191191
}
192-
CloseHandle(explorerInfo.processInfo.hThread);
193-
jobHandle = explorerInfo.jobHandle;
194-
195-
Sleep(2000);
196-
197-
if (explorerInfo.status == explorerInfo.COULD_NOT_ASSIGN_JOB) {
198-
auto pi = Desktop::createProcess(
199-
desktopName,
200-
selDriverPath,
201-
cmdLine);
202-
203-
driverInfo = Desktop::ProcessInTheJob(
204-
Desktop::ProcessInTheJob::COULD_NOT_ASSIGN_JOB,
205-
0,
206-
pi);
207-
}
208-
else
209-
driverInfo = Desktop::createProcessInTheJob(
210-
desktopName,
211-
selDriverPath,
212-
cmdLine,
213-
jobHandle);
192+
jobHandle = driverInfo.jobHandle;
214193

215194
CloseHandle(driverInfo.processInfo.hThread);
216-
217195
Process::wait(driverInfo.processInfo.hProcess);
196+
CloseHandle(driverInfo.processInfo.hProcess);
218197

219198
cleanUp();
220199
}

0 commit comments

Comments
 (0)