15

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?

jwa
  • 2,960
  • 2
  • 19
  • 48

8 Answers8

23

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.

RocketRaccoon
  • 2,356
  • 1
  • 17
  • 28
5

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

swiniak
  • 67
  • 1
  • Is there a particular version of Chrome you know works within Session 0? If I can simply downgrade, then this would be an option. – jwa Oct 20 '14 at 13:54
  • 1
    With versions of Chrome before 38 all works as windows-service fine. Since version 38 - my windows service with selenium does not work. Downgrading Chrome solved problem for me – razon Oct 30 '14 at 09:50
  • 1
    I can confirm what @razon is saying. Chrome 37 is last known version working when run under service. – Stanislav Berkov Jul 08 '15 at 11:26
  • 1
    It's been a while since the last comment on this. Do later versions of chrome still not work? – Paul Perrick Jan 24 '16 at 00:19
5

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.

djangofan
  • 25,461
  • 54
  • 171
  • 262
  • Agreed :( You can start the hub as a service using nssm but if the node is started as a service you will not be able to 'see' the browser. Might not be an issue for some people but it is for me. So the node runs as a batch file. To start automatic add it into the 'start up' folder or create a task scheduler which is more tricky. – oden Apr 06 '16 at 11:49
  • FWIW I've been using Selenium Grid with the hub and the nodes running as a Windows Service using WinSW https://github.com/winsw/winsw. Have been doing this since 2014 for 2 different teams. Chrome still runs just headlessly rather than in GUI mode. I've tried every combination of permission for the Windows Service, but it never launches as a GUI. – Steven Erat Dec 09 '20 at 21:36
3

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:

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.

SDET
  • 1,100
  • 8
  • 4
0

Yeah, you should use NSSM. Important is, that you add your windows account in the "Log on" tab, or any other valid account. If you run your node with the "Local System account" option, you will get the session 0 problem. With a normal user session, the nodes run smoothly invisible in the background :)

Sst
  • 59
  • 1
  • 2
0

we don't use selenium GRID, we were disappointed with its stability. We use a "Jenkins Grid", that is jenkins slaves nodes on various servers.

The slaves are services with the interact with desktop flag. They run as services with NSSM, and the SERVICE_INTERACTIVE_PROCESS flag. Making sure that NoInteractiveProcess is set to 1 (cf https://docs.microsoft.com/en-us/windows/desktop/services/interactive-services).

We don't have the fancy features of the grid (that is balancing according the browser types slots). Instead, we have Jenkins balancing the test jobs using a slave node or another. Initially we did not use the interact with desktop flag, having browsers to run without "real" display, but the behavior was not very stable (especially with resize commands). Hope this helps.

vlabatut
  • 118
  • 8
-1

As I explained on this thread, I found that using a small paid tool FireDaemon Pro saved me a lot of time from trying to configure NSSM and other free tools.

It works well in the background, and restarts Selenium along with the server, which was my main requirement for running Selenium Standalone Server as a Windows Service.

XavierAM
  • 1,067
  • 9
  • 18
-2

This free tool would probably do it: http://yajsw.sourceforge.net/

For that to work, you need a wrapper.conf file and a script to run the YAJSW wrapper. I takes time to read the documentation, but it is a free solution.

I wrote an example shared here, that installs JBoss7 as a Windows service.

Of course, you can simplify my example by a lot.

djangofan
  • 25,461
  • 54
  • 171
  • 262
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – dippas Dec 11 '20 at 17:26
  • Sure thing, I will update but other answers in this thread have the same issue. – djangofan Dec 11 '20 at 17:51