Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Selenium Server & ChromeDriver as a Windows Service

So that we may perform front-to-back web UI testing, we are using Selenium and ChromeDriver to automate page loads / interaction as part of our testing pack.

This is behaving as expected during developer testing (on a developer's local machine), but we are struggling to perform these checks as part of our continuous integration build.

Our server plant is *NIX based, and all of our CI infrastructure runs on these machines. So that we may test Chrome under Windows (our delivery mechanism), we have configured a Selenium Grid. When the CI tests run, they access the grid, in order to locate a Windows node to run the tests on.

We have had a Windows desktop provisioned solely for the purpose of running these test. This contains our standard enterprise build of Windows 7. This machine will be periodically rebooted in-line with the IT department's update policy.

In an effort to ensure the Selenium server is always running, we have added the Selenium Server (running in "node" mode) as a Windows service. The selenium Server is configured to start-up ChromeDriver to invoke the simulated user-interaction.

However, when running the tests from CI they fail due to timeout. Our working theory is, the system user that is running the service cannot create interactive windows. A web search has raised reference to the "Session 0" problem, but with little to no constructive advice on how to move forward.

Starting the Selenium Server process manually from an interactive session is not a viable solution, as this is leading to brittle tests - which are failing due to an infrastructure problem, rather than a genuine test regression.


How can we have an instance of Selenium Server started via a Windows Service whenever the system reboots, that is capable of launching Chrome instances?

like image 628
jwa Avatar asked Oct 20 '14 08:10

jwa


People also ask

How do I start Selenium server locally?

To install and start the standalone Selenium Server manually, use the webdriver-manager command line tool, which comes with Protractor. Run the update command: webdriver-manager update This will install the server and ChromeDriver. Run the start command: webdriver-manager start This will start the server.

What is a selenium server?

What is a Selenium Standalone server? Selenium Standalone server is a java jar file used to start the Selenium server. It is a smart proxy server that allows Selenium tests to route commands to remote web browser instances. The aim is to provide an easy way to run tests in parallel on multiple machines.

How can I tell if selenium server is running?

Or You can also check with http://localhost:4444/selenium-server/driver/?cmd=getLogMessages If serveris runnning then it will show 'ok' in browser.

Does selenium need a server?

The Selenium Server is needed in order to run Remote Selenium WebDriver (Grid). To use the Selenium Server in a Grid configuration see the documentation. This is required if you want to make use of the latest and greatest features of the WebDriver InternetExplorerDriver.

How do I work with selenium standalone server?

Working with the Standalone Server. The server will always run on the machine with the browser you want to test. The server can be used either from the command line or through code configuration. Once you have downloaded selenium-server-standalone- {VERSION}.jar , place it on the computer with the browser you want to test.

Can I run Selenium IDE tests on any browser?

You can now run all of your Selenium IDE tests on any browser, in parallel, and on a Grid without needing to write any code.

How do I install selenium on Windows?

Installing Selenium Server Download Selenium Server version 2.x from the SeleniumHQ and move the JAR-file to "C:selenium". Open the command prompt as administrator in extracted NSSM directory and execute the following commands to install the service:

Can selenium run without a GUI/windows?

Selenium runs web browser which needs GUI/Windows to display its window. But some web browsers can also run without displaying window - they can run headless. For Firefox should be similar code. There was also Selenium's webdrive PhantomJS which worked headless but it is not developed any more.


4 Answers

It could be easily done with NSSM. Installation of services looks like these:

nssm install seleniumhub java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role hub -hubConfig C:\selenium\hub.json
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\node.json

It provides easily way to remove service if needed:

nssm remove seleniumnode confirm

Add destination to nssm to your PATH variable and run from console as admin


UPDATE April 2021

NSSM is not supported for more than 3 years. So please consider other options like winsw or any other. WinSW does the same job as NSSM and allows to keep run configuration in xml.

like image 134
RocketRaccoon Avatar answered Sep 27 '22 13:09

RocketRaccoon


Right now you can't help it - it used to work fine in session 0 but for the past few days after chrome update only works for interactive sessions.

Related bugs:

https://code.google.com/p/selenium/issues/detail?id=8029 https://code.google.com/p/chromium/issues/detail?id=422218

like image 44
swiniak Avatar answered Sep 27 '22 13:09

swiniak


You cannot run Selenium Grid as a windows service ever since Windows Vista. Microsoft calls it "Session 0 Isolation". You could do it in Windows 2000 or XP but since the time that Vista came out, Microsoft no longer will let Grid interact with the desktop (or any other UI programs for that matter). Regardless of the fact that you still see that "interact with desktop" checkbox, it is a red herring. So, you MUST run Selenium Grid in the foreground on that server in order for it to get access to the session. If it is running Windows Server, you could in theory have multiple sessions and leave Grid running in the foreground on one of the non-zero user sessions.

like image 6
djangofan Avatar answered Sep 26 '22 13:09

djangofan


My preferred solution to this problem (and my default choice for running Selenium Grid as a service) is to use a simple tool called AlwaysUp. It has a free 30 day trial to try it out.

What to do:

  • Download AlwaysUp
  • Configure AlwaysUp to start the Selenium Grid node on startup
  • Configure AlwaysUp to run the Selenium node as a specific user (not the default System user)

This way the the node will run as a service, survive machine restarts and work with the latest version Chrome.

If the user account you use to login to the machine is different from the user account you specify to run the node as a service then you will not see the browsers pop up on the desktop as they are running in a different user session. The end result is that it is almost identical to running as a normal service but gets round the Session 0 issue.

like image 3
SDET Avatar answered Sep 25 '22 13:09

SDET