1
- headless-selenium-for-win
2
- =========================
1
+ # Headless Selenium for Windows
3
2
4
3
It is quite inconvenient that a browser window pops up when running Selenium
5
4
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.
7
6
8
7
In Linux world, this is solved by running browsers in a virtual frame-buffer.
9
8
Similar approach can be taken on Windows platform as well.
@@ -15,6 +14,9 @@ to Linux desktop environments.
15
14
This application uses virtual desktops to run web browsers in so that they
16
15
do not disturb the main user desktop.
17
16
17
+ It can be used by any language supported by Selenium Webdriver (Java, C#,
18
+ Ruby, ...).
19
+
18
20
# Download
19
21
20
22
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
23
25
24
26
When using IE, please pay full attention to configure the driver correctly. All
25
27
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
27
29
28
30
## Setup
29
31
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.
31
33
Selenium has to be instructed to use the 'headless_ie_selenium.exe' executable to run tests
32
34
headlessly.
33
35
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.
35
37
Any command line parameters are passed on to the IE driver.
36
38
37
- ' IEDriverServer.exe' has to be stored in the searchable path.
39
+ ` IEDriverServer.exe ` has to be stored in the searchable path.
38
40
39
41
## Basic Ruby example
40
42
41
43
Following example uses www.google.com search to retrieve weather in London.
42
44
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
+ ```
79
83
80
84
Output might be something like this. 'Sunny Weather' can be retrieved
81
85
only on rare occasions:
@@ -108,15 +112,41 @@ only on rare occasions:
108
112
22°14°
109
113
Tue
110
114
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.
112
142
113
143
# Technical details
114
144
115
145
Tested on Win 7.
116
146
117
147
Supported browsers at the moment: IE.
118
148
119
- Written using VS 2013 Express, Boost 1.56.
149
+ Developed using VS 2013 Express, Boost 1.56, Mercurial with the GIT bridge .
120
150
121
151
# License
122
152
0 commit comments