Skip to content

Commit a9d5f3a

Browse files
committed
- Readme updated.
- Some minor improvements.
1 parent e852274 commit a9d5f3a

12 files changed

+114
-61
lines changed

README.md

+75-45
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
headless-selenium-for-win
2-
=========================
1+
# Headless Selenium for Windows
32

43
It is quite inconvenient that a browser window pops up when running Selenium
54
tests. It might cause tests to fail because such window needs to hold user
6-
focus. That is the case with IE at least.
5+
input focus. That is the case with IE at least.
76

87
In Linux world, this is solved by running browsers in a virtual frame-buffer.
98
Similar approach can be taken on Windows platform as well.
@@ -15,6 +14,9 @@ to Linux desktop environments.
1514
This application uses virtual desktops to run web browsers in so that they
1615
do not disturb the main user desktop.
1716

17+
It can be used by any language supported by Selenium Webdriver (Java, C#,
18+
Ruby, ...).
19+
1820
# Download
1921

2022
Binaries can be downloaded from https://github.com/kybu/headless-selenium-for-win/releases
@@ -23,59 +25,61 @@ Binaries can be downloaded from https://github.com/kybu/headless-selenium-for-wi
2325

2426
When using IE, please pay full attention to configure the driver correctly. All
2527
necessary details can be found at https://code.google.com/p/selenium/wiki/InternetExplorerDriver
26-
in the 'Required Configuration' section.
28+
in the 'Required Configuration' section and at http://heliumhq.com/docs/internet_explorer
2729

2830
## Setup
2931

30-
Selenium uses a standalone executable called 'IEDriverServer.exe' to drive the IE browser window.
32+
Selenium uses a standalone executable called `IEDriverServer.exe` to drive the IE browser window.
3133
Selenium has to be instructed to use the 'headless_ie_selenium.exe' executable to run tests
3234
headlessly.
3335

34-
'headless_ie_selenium.exe' created a virtual desktop and runs 'IEDriverServer.exe' inside of it.
36+
`headless_ie_selenium.exe` creates a virtual desktop and runs `IEDriverServer.exe` inside of it.
3537
Any command line parameters are passed on to the IE driver.
3638

37-
'IEDriverServer.exe' has to be stored in the searchable path.
39+
`IEDriverServer.exe` has to be stored in the searchable path.
3840

3941
## Basic Ruby example
4042

4143
Following example uses www.google.com search to retrieve weather in London.
4244

43-
require 'selenium-webdriver'
44-
45-
Dir.chdir(File.dirname $0)
46-
47-
# Find the Headless IE binary.
48-
headlessBinary =
49-
if File.exists?('../Debug/headless_ie_selenium.exe')
50-
'../Debug/headless_ie_selenium.exe'
51-
elsif File.exists?('../Release/headless_ie_selenium.exe')
52-
'../Release/headless_ie_selenium.exe'
53-
else
54-
raise 'Cound not find headless_ie_selenium.exe!'
55-
end
56-
57-
puts "Headless IE binary found at: #{headlessBinary}"
58-
59-
# The most important part!
60-
Selenium::WebDriver::IE.driver_path = headlessBinary
61-
62-
driver = Selenium::WebDriver.for :ie
63-
driver.get 'https://www.google.com'
64-
65-
sleep 2
66-
67-
searchInput = driver.find_element :name => 'q'
68-
69-
searchInput.send_keys "london weather"
70-
searchInput.submit
71-
72-
sleep 2
73-
74-
weather = driver.find_element :id => 'wob_wc'
75-
76-
puts weather.text
77-
78-
driver.quit
45+
```ruby
46+
require 'selenium-webdriver'
47+
48+
Dir.chdir(File.dirname $0)
49+
50+
# Find the Headless IE binary.
51+
headlessBinary =
52+
if File.exists?('../Debug/headless_ie_selenium.exe')
53+
'../Debug/headless_ie_selenium.exe'
54+
elsif File.exists?('../Release/headless_ie_selenium.exe')
55+
'../Release/headless_ie_selenium.exe'
56+
else
57+
raise 'Cound not find headless_ie_selenium.exe!'
58+
end
59+
60+
puts "Headless IE binary found at: #{headlessBinary}"
61+
62+
# The most important part!
63+
Selenium::WebDriver::IE.driver_path = headlessBinary
64+
65+
driver = Selenium::WebDriver.for :ie
66+
driver.get 'https://www.google.com'
67+
68+
sleep 2
69+
70+
searchInput = driver.find_element :name => 'q'
71+
72+
searchInput.send_keys "london weather"
73+
searchInput.submit
74+
75+
sleep 2
76+
77+
weather = driver.find_element :id => 'wob_wc'
78+
79+
puts weather.text
80+
81+
driver.quit
82+
```
7983

8084
Output might be something like this. 'Sunny Weather' can be retrieved
8185
only on rare occasions:
@@ -108,15 +112,41 @@ only on rare occasions:
108112
22°14°
109113
Tue
110114
22°13°
111-
115+
116+
# Executables
117+
118+
'Headless Selenium for Windows' comes with these two binaries: `desktop_utils.exe` and `headless_ie_selenium.exe`
119+
120+
## headless_ie_selenium.exe
121+
122+
This executable runs IE Webdriver `IEDriverServer.exe` headlessly. It is meant to be used by Selenium Webdriver
123+
library instead of IE Webdriver.
124+
125+
## desktop_utils.exe
126+
127+
Generic Windows virtual desktop utility. It can run applications in virtual desktops, etc ...
128+
129+
Command line options:
130+
131+
Desktop utils v1.1, Peter Vrabel (c) 2014:
132+
-h [ --help ] Feeling desperate?
133+
-r [ --run ] arg Command to run headlessly.
134+
-n [ --desktop ] arg Set the headless desktop name. Used with '--run'.
135+
Optional, default = HeadlessDesktop
136+
-l [ --list ] List available desktops of current Window
137+
station.
138+
-s [ --switch-to ] arg Switch to a desktop. Takes a desktop name from
139+
the list of desktops.
140+
-t [ --switch-to-default ] Switch to the default desktop. Can be used if you
141+
are being stranded.
112142

113143
# Technical details
114144

115145
Tested on Win 7.
116146

117147
Supported browsers at the moment: IE.
118148

119-
Written using VS 2013 Express, Boost 1.56.
149+
Developed using VS 2013 Express, Boost 1.56, Mercurial with the GIT bridge.
120150

121151
# License
122152

common.props

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
<ClCompile>
88
<AdditionalIncludeDirectories>$(BOOST_ROOT)</AdditionalIncludeDirectories>
99
<MultiProcessorCompilation>true</MultiProcessorCompilation>
10-
<Optimization>Full</Optimization>
10+
<Optimization>Disabled</Optimization>
1111
<IntrinsicFunctions>true</IntrinsicFunctions>
1212
<StringPooling>true</StringPooling>
1313
<MinimalRebuild>false</MinimalRebuild>
1414
<AdditionalOptions>/Zm300 %(AdditionalOptions)</AdditionalOptions>
15+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
16+
<CompileAsManaged>false</CompileAsManaged>
17+
<WholeProgramOptimization>true</WholeProgramOptimization>
1518
</ClCompile>
1619
<Link>
1720
<AdditionalLibraryDirectories>$(BOOST_ROOT)/stage/lib</AdditionalLibraryDirectories>

desktop_utils/desktop.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU General Public License for more details.
1414
#
1515
# You should have received a copy of the GNU General Public License
16-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
16+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1717

1818
#include "stdafx.h"
1919

desktop_utils/desktop.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# GNU General Public License for more details.
1616
#
1717
# You should have received a copy of the GNU General Public License
18-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
18+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1919

2020

2121
#include "stdafx.h"

desktop_utils/desktop_utils.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU General Public License for more details.
1414
#
1515
# You should have received a copy of the GNU General Public License
16-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
16+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1717

1818
//
1919
// Following http://utf8everywhere.org/ convention.
@@ -87,7 +87,7 @@ ParseStatus parseCommandLine(int argc, _TCHAR *argv[]) {
8787
if (!vm.count("run"))
8888
throw runtime_error("--run option must be specified!");
8989
}
90-
catch (po::unknown_option &e) {
90+
catch (po::error &e) {
9191
LOGF << e.what();
9292

9393
return ParseStatus::FAILED;
@@ -96,8 +96,26 @@ ParseStatus parseCommandLine(int argc, _TCHAR *argv[]) {
9696
return ParseStatus::OK;
9797
}
9898

99+
void setupLogger() {
100+
using namespace boost::log;
101+
102+
add_console_log(
103+
cout,
104+
keywords::format = "%Message%");
105+
106+
#ifdef _DEBUG
107+
core::get()->set_filter(
108+
trivial::severity >= trivial::trace);
109+
#else
110+
core::get()->set_filter(
111+
trivial::severity >= trivial::info);
112+
#endif
113+
}
114+
99115
int _tmain(int argc, _TCHAR* argv[]) {
100116
try {
117+
setupLogger();
118+
101119
switch (parseCommandLine(argc, argv)) {
102120
case ParseStatus::FAILED:
103121
return 1;

desktop_utils/desktop_utils.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</ImportGroup>
4444
<PropertyGroup Label="UserMacros" />
4545
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
46-
<LinkIncremental>true</LinkIncremental>
46+
<LinkIncremental>false</LinkIncremental>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
4949
<LinkIncremental>false</LinkIncremental>
@@ -58,6 +58,7 @@
5858
<Link>
5959
<SubSystem>Console</SubSystem>
6060
<GenerateDebugInformation>true</GenerateDebugInformation>
61+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
6162
</Link>
6263
</ItemDefinitionGroup>
6364
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

desktop_utils/process.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU General Public License for more details.
1414
#
1515
# You should have received a copy of the GNU General Public License
16-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
16+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1717

1818

1919
#include "stdafx.h"

desktop_utils/process.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# GNU General Public License for more details.
1616
#
1717
# You should have received a copy of the GNU General Public License
18-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
18+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1919

2020

2121
#include "stdafx.h"

headless_ie_selenium/headless_ie_selenium.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU General Public License for more details.
1414
#
1515
# You should have received a copy of the GNU General Public License
16-
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
16+
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */
1717

1818

1919
#include "stdafx.h"

headless_ie_selenium/headless_ie_selenium.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</ImportGroup>
4343
<PropertyGroup Label="UserMacros" />
4444
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
45-
<LinkIncremental>true</LinkIncremental>
45+
<LinkIncremental>false</LinkIncremental>
4646
</PropertyGroup>
4747
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
4848
<LinkIncremental>false</LinkIncremental>
@@ -58,6 +58,7 @@
5858
<SubSystem>Console</SubSystem>
5959
<GenerateDebugInformation>true</GenerateDebugInformation>
6060
<AdditionalDependencies>libboost_program_options-vc120-mt-gd-1_56.lib;Rstrtmgr.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
61+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
6162
</Link>
6263
</ItemDefinitionGroup>
6364
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

ruby_example/ruby_example.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# GNU General Public License for more details.
1414
#
1515
# You should have received a copy of the GNU General Public License
16-
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
16+
# along with 'Headless Selenium for Win'. If not, see <http://www.gnu.org/licenses/>.
1717

1818

1919
require 'selenium-webdriver'
@@ -52,4 +52,4 @@
5252

5353
puts weather.text
5454

55-
driver.quit
55+
driver.close

version.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define FILEVER 1,0,0,0
2-
#define PRODUCTVER 1,0,0,0
3-
#define STRFILEVER "1, 0\0"
4-
#define STRPRODUCTVER "1, 0\0"
1+
#define FILEVER 1,1,0,0
2+
#define PRODUCTVER 1,1,0,0
3+
#define STRFILEVER "1, 1\0"
4+
#define STRPRODUCTVER "1, 1\0"

0 commit comments

Comments
 (0)