-
Notifications
You must be signed in to change notification settings - Fork 29
Using Queen with Selenium
Before you begin, run npm install -g queen to ensure you have the latest version of Queen.
Queen can use a Selenium Server to automatically spawn a set of browsers and keep watch on them, restarting them automatically if they become unresponsive. This tutorial walks you through the steps nescessary.
If you already have a server setup, you can skip this section.
This is the Selenium server software, we'll use it both for setting up the Hub and Node.
- Start the Hub by executing:
java -jar selenium-server-standalone-2.28.0.jar -role hub
This will start the Hub on port 4444. Make sure the Selenium jar is in the current folder for this command to work.
- Start the Node by executing:
java -jar selenium-server-standalone-2.28.0.jar -role node
Because we're using the default configuration, the node will be able to find and connect to the hub automatically.
We'll configure Queen to connect to the Hub we started through the use of a queenConfig.js file. This file does pretty much the same thing that the command-line options allow you to do, with the additional benefit of defining populators, such as Selenium.
Copy this to a file named queenConfig.js:
// queenConfig.js
module.exports = {
// By default Queen captures browsers on port 80, but this requires
// admin privilages on many operating systems, so for this example we'll
// configure queen to use port 9000
capture: ":9000",
// This configuration option takes an object, or an array of objects
// if we were using more than one type of populator (ex. Sauce)
populator: [
// Note that we're in an array, we could provide more populator configs
// if we wanted
{
type: "selenium",
// If your Selenium Server is hosted else where, change this value accordingly
config: { host: "localhost:4444" },
// This tells Queen to request a Firefox browser from the Hub once
// we connect to it. You may specify any webdriver capability in
// http://code.google.com/p/selenium/wiki/DesiredCapabilities
clients: [
{ browserName: "firefox" }
]
}
]
};You can now start Queen by executing queen when in the directory the queenConfig.js file.
Once started, Queen will automatically connect to the hub and request that it spawn a Firefox browser and point it at Queen's capture URL. Once captured, Queen will ensure that the browser remains in a healthy state. If the browser becomes unresponsive, Queen will ask the Hub to start a new one and kill the old one. You can see this in action by closing the Firefox window -- within a few seconds another one will pop up.
You can now use Queen as you would normally. If we wanted to run a test script, we could do so by executing: queen -r [QUEEN_REMOTE_SERVER_HOST] http://queenjs.com/server-example.js where [QUEEN_REMOTE_SERVER_HOST] is the address queen is listening to for remote connections (it's outputted to the log when queen starts as [Queen Remote Server] Accepting connections on [QUEEN_REMOTE_SERVER_HOST].
We've just scratched the surface of using Selenium with Queen. Here are some other things you can do:
- The objects in the clients array can have any of the options defined http://code.google.com/p/selenium/wiki/DesiredCapabilities
- You can define as many clients in the clients array as the Selenium Server can support
- You can add additional populator configs to the populator array, including multiple selenium servers. Queen will deal with each of them independently.
- Find out more about the configuration options for Selenium at the Grid2 documentation wiki.