Skip to content
ozanturgut edited this page Jan 22, 2013 · 15 revisions

This document will go over the major use cases of Queen, by the end of it you should be ready to use Queen with all of its full feature-set.

If you haven't already, read the README get an overview and examples of the concepts used in this page.

To use Queen, you'll need Node.js 0.8 or higher.

Technical Brief

There are two distinct way Queen operates. As a HTTP server which captures browsers, and as a TCP server for applications to execute code on captured browsers. The second server is optional if you're only using Queen locally, but Queen is intended to be used as browser pool for your entire organization to execute code on.

"The Easy Way" and "The Right Way"

The easiest way to test and play around with Queen is to start the Queen and run a script in one step by executing something like queen your-script.js, and then connecting a browser. However, this is very inefficient because it means we have to start a new Queen Server for each script we want to run.

A more efficient way of using Queen is to start a stand-alone server whose sole purpose is to collect browsers and run scripts on them when asked to, and then we can establish a connection to this server to run our script. Here's how:

  1. Execute: queen -h localhost:9101 -c localhost:9200

    • -h localhost:9101 tells Queen to capture browsers at http://localhost:9101. If we didn't give queen this option, it would capture browsers at [your ip address]:80. Queen will log out to the console which host it's capturing browsers when it starts.
    • -c localhost:9200 tells Queen to listen for TCP connections at localhost:9200, this is where other applications can connect to in order to run scripts on the browsers Queen has captured.
    • Since we didn't provide a filename, Queen won't try to run a script, it's now just acting as a pure server. Also note that if there is a queenConfig.js file in the directory queen is started in, Queen will use those options to initialize itself.
  2. Execute: queen -r localhost:9101 http://queenjs.com/server-example.js

    • -r localhost:9101 tells Queen to run in "remote" mode and connect to a Queen server running at localhost:9101, which is the Queen Server we started in step 1.
    • http://queenjs.com/server-example.js is the queen script we want to execute. It will ask the Queen server to run http://queenjs.com/client-example.js on captured browsers, Queen will then establish socketed communication between the server-example.js script running on your machine and the client-example.js scripts running on the browsers, allowing the scripts to communicate with each other. You can open and read these scripts to find out more about how they work.
  3. Point one or more browsers at http://localhost:9200

    • This allows Queen to "capture the browsers". Once it has successfully captured the browser, Queen will be able to push scripts to the browser for it to run. Since we already have a pending job, it will automatically push it to this browser. You should start seeing outputs on your console now.

Going from 18 MB to 250 KB

Queen weights in at around 18MB, not lightweight by JavaScript standards. Most of the "weight" in Queen, is the server portion, the one that captures browsers and lets other applications connect to it to run code on the captured browsers. If all were want to do is run scripts on an existing Queen server (like we did in step 2), we don't need all that weight.

queen-remote is a 250 KB package that allows you to connect to existing Queen servers to run your tests. Let's try the above example again, this time with queen-remote. You first need to install queen-remote by executing npm install queen-remote

  1. Execute: queen -h localhost:9101 -c localhost:9200
    • This step remains the same as in the previous example.
  2. Execute: queen-remote -h localhost:9101 http://queenjs.com/server-example.js
    • -h localhost:9101 tells Queen Remote to connect to the Queen Server hosted at localhost:9101, which is the Queen Server we started in step 1.
    • http://queenjs.com/server-example.js is the same file as from the previous example.
  3. Point one or more browsers at http://localhost:9200
    • This step remains the same as in the previous example.

There! The same results, with a much lighter package. As you may have realized, the size saving doesn't matter if you're running Queen on the same machine as the Queen Server. However, Queen is designed to be used as an internal server, allowing anyone in the network to run scripts on it, so the savings becomes worth while if others in your organization want to quickly download queen-remote to run scripts on the server.

Monitoring

With a Queen server running, go to the [CAPTURE_URL]/monitor/. In the above examples, this would be http://localhost:9200/monitor/. You should see something like this:

Automatic Population

The Queen Server can automatically populate itself with browsers (as in, start up browsers and point them at it self to capture them). It has three methods of doing so: through Selenium, BrowserStack, or Sauce Labs.

The best way to learn about automatic population is to run through the examples. The best one to start with is the Selenium once, since you can run that directly on your machine.

Download the repo, and view the "how-to-run-this-example.txt" files in the following folders:

Next Steps

Clone this wiki locally