Is the Selenium Server up?

Both the Selenium RC and Selenium [Remote] WebDriver APIs require the Selenium server to be running on a machine that is going to be launching browsers. From a framework perspective this actually a more challenging task than you might think. Here is how Saunter handles it.

First it checks tries to connect to the host and port combination specified in your config. If the server lets it bind to the socket it is deemed to be up. It is simple and quick and good enough in most situations. At this point Saunter doesn’t care how the server got started just that it is up.

If it determines that it is not up, it checks it’s config to determine whether it is supposed to manage it. And this is also one of those ‘hard’ places. What is the server is on a remote machine? Or on a platform that doesn’t really allow for remote management (like Windows?) In those situations you should really look at an automation configuration management tool like Puppet (see Puppet and Selenium) to ensure the server is in the correct (up) state. And so you would tell Saunter not to manage the server.

If you are running the Selenium server on the same machine as Saunter, it will see if the Selenium server jar specified in the config exists. If it doesn’t, Saunter will fetch the current one and stash it in the machine’s temp directory (if it had not already in a previous run). Then it will start it.

Saunter starts to care about how the Selenium server was started after the run finishes. If it is supposed to manage the server itself it will check for a pid file in the machine’s temp directory and will then kill that process.

This is another one of those surprisingly tricky places. What if the machine crashed during a run or something else happened to cause the server to stop without removing the pid file? Well, if Saunter restarts it then everything is fine-and-dandy, but if you did it by hand you would end up with a stale pid being killed. Hopefully it isn’t a process that really matters. I’ve not personally had this situation happen as the restart is usually before the pid is recyled, but it is conceivable that it could so forewarned is, well, forewarned.

Here is a sample of the relevant bits to this post from Selenium section of py.saunter‘s saunter.ini.

manage_server: true
server_path: /path/to/selenium-server.jar
server_host: localhost
server_port: 4444

Comments 1

  1. Ryan wrote:

    Suppose I want to use Saunter with just local webdriver and without Selenium Server.

    I’m trying to get my feet wet with Saunter, but when I run my test I’m greeted with: “Selenium Server not running and py.saunter configured not to control it”

    Posted 02 Dec 2011 at 12:02 am

Post a Comment

Your email is never published nor shared. Required fields are marked *