Skip to content

Commit

Permalink
- Readme updated.
Browse files Browse the repository at this point in the history
- Some minor improvements.
  • Loading branch information
kybu committed Sep 10, 2014
1 parent e852274 commit a9d5f3a
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 61 deletions.
120 changes: 75 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
headless-selenium-for-win
=========================
# Headless Selenium for Windows

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

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

It can be used by any language supported by Selenium Webdriver (Java, C#,
Ruby, ...).

# Download

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

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

## Setup

Selenium uses a standalone executable called 'IEDriverServer.exe' to drive the IE browser window.
Selenium uses a standalone executable called `IEDriverServer.exe` to drive the IE browser window.
Selenium has to be instructed to use the 'headless_ie_selenium.exe' executable to run tests
headlessly.

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

'IEDriverServer.exe' has to be stored in the searchable path.
`IEDriverServer.exe` has to be stored in the searchable path.

## Basic Ruby example

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

require 'selenium-webdriver'

Dir.chdir(File.dirname $0)

# Find the Headless IE binary.
headlessBinary =
if File.exists?('../Debug/headless_ie_selenium.exe')
'../Debug/headless_ie_selenium.exe'
elsif File.exists?('../Release/headless_ie_selenium.exe')
'../Release/headless_ie_selenium.exe'
else
raise 'Cound not find headless_ie_selenium.exe!'
end

puts "Headless IE binary found at: #{headlessBinary}"

# The most important part!
Selenium::WebDriver::IE.driver_path = headlessBinary

driver = Selenium::WebDriver.for :ie
driver.get 'https://www.google.com'

sleep 2

searchInput = driver.find_element :name => 'q'

searchInput.send_keys "london weather"
searchInput.submit

sleep 2

weather = driver.find_element :id => 'wob_wc'

puts weather.text

driver.quit
```ruby
require 'selenium-webdriver'

Dir.chdir(File.dirname $0)

# Find the Headless IE binary.
headlessBinary =
if File.exists?('../Debug/headless_ie_selenium.exe')
'../Debug/headless_ie_selenium.exe'
elsif File.exists?('../Release/headless_ie_selenium.exe')
'../Release/headless_ie_selenium.exe'
else
raise 'Cound not find headless_ie_selenium.exe!'
end

puts "Headless IE binary found at: #{headlessBinary}"

# The most important part!
Selenium::WebDriver::IE.driver_path = headlessBinary

driver = Selenium::WebDriver.for :ie
driver.get 'https://www.google.com'

sleep 2

searchInput = driver.find_element :name => 'q'

searchInput.send_keys "london weather"
searchInput.submit

sleep 2

weather = driver.find_element :id => 'wob_wc'

puts weather.text

driver.quit
```

Output might be something like this. 'Sunny Weather' can be retrieved
only on rare occasions:
Expand Down Expand Up @@ -108,15 +112,41 @@ only on rare occasions:
22°14°
Tue
22°13°


# Executables

'Headless Selenium for Windows' comes with these two binaries: `desktop_utils.exe` and `headless_ie_selenium.exe`

## headless_ie_selenium.exe

This executable runs IE Webdriver `IEDriverServer.exe` headlessly. It is meant to be used by Selenium Webdriver
library instead of IE Webdriver.

## desktop_utils.exe

Generic Windows virtual desktop utility. It can run applications in virtual desktops, etc ...

Command line options:

Desktop utils v1.1, Peter Vrabel (c) 2014:
-h [ --help ] Feeling desperate?
-r [ --run ] arg Command to run headlessly.
-n [ --desktop ] arg Set the headless desktop name. Used with '--run'.
Optional, default = HeadlessDesktop
-l [ --list ] List available desktops of current Window
station.
-s [ --switch-to ] arg Switch to a desktop. Takes a desktop name from
the list of desktops.
-t [ --switch-to-default ] Switch to the default desktop. Can be used if you
are being stranded.

# Technical details

Tested on Win 7.

Supported browsers at the moment: IE.

Written using VS 2013 Express, Boost 1.56.
Developed using VS 2013 Express, Boost 1.56, Mercurial with the GIT bridge.

# License

Expand Down
5 changes: 4 additions & 1 deletion common.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
<ClCompile>
<AdditionalIncludeDirectories>$(BOOST_ROOT)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<Optimization>Full</Optimization>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<StringPooling>true</StringPooling>
<MinimalRebuild>false</MinimalRebuild>
<AdditionalOptions>/Zm300 %(AdditionalOptions)</AdditionalOptions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAsManaged>false</CompileAsManaged>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(BOOST_ROOT)/stage/lib</AdditionalLibraryDirectories>
Expand Down
2 changes: 1 addition & 1 deletion desktop_utils/desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */

#include "stdafx.h"

Expand Down
2 changes: 1 addition & 1 deletion desktop_utils/desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */


#include "stdafx.h"
Expand Down
22 changes: 20 additions & 2 deletions desktop_utils/desktop_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */

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

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

void setupLogger() {
using namespace boost::log;

add_console_log(
cout,
keywords::format = "%Message%");

#ifdef _DEBUG
core::get()->set_filter(
trivial::severity >= trivial::trace);
#else
core::get()->set_filter(
trivial::severity >= trivial::info);
#endif
}

int _tmain(int argc, _TCHAR* argv[]) {
try {
setupLogger();

switch (parseCommandLine(argc, argv)) {
case ParseStatus::FAILED:
return 1;
Expand Down
3 changes: 2 additions & 1 deletion desktop_utils/desktop_utils.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand All @@ -58,6 +58,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down
2 changes: 1 addition & 1 deletion desktop_utils/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */


#include "stdafx.h"
Expand Down
2 changes: 1 addition & 1 deletion desktop_utils/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */


#include "stdafx.h"
Expand Down
2 changes: 1 addition & 1 deletion headless_ie_selenium/headless_ie_selenium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.If not, see <http://www.gnu.org/licenses/>. */
# along with 'Headless Selenium for Win'.If not, see <http://www.gnu.org/licenses/>. */


#include "stdafx.h"
Expand Down
3 changes: 2 additions & 1 deletion headless_ie_selenium/headless_ie_selenium.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
Expand All @@ -58,6 +58,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<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>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down
4 changes: 2 additions & 2 deletions ruby_example/ruby_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
# along with 'Headless Selenium for Win'. If not, see <http://www.gnu.org/licenses/>.


require 'selenium-webdriver'
Expand Down Expand Up @@ -52,4 +52,4 @@

puts weather.text

driver.quit
driver.close
8 changes: 4 additions & 4 deletions version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define FILEVER 1,0,0,0
#define PRODUCTVER 1,0,0,0
#define STRFILEVER "1, 0\0"
#define STRPRODUCTVER "1, 0\0"
#define FILEVER 1,1,0,0
#define PRODUCTVER 1,1,0,0
#define STRFILEVER "1, 1\0"
#define STRPRODUCTVER "1, 1\0"

0 comments on commit a9d5f3a

Please sign in to comment.