-
Notifications
You must be signed in to change notification settings - Fork 30
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.
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 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. While
this is easy, it's inefficient. This means you have to stop and start a Queen Server whenever you
want to run a script.
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.
- 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.
-
- 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.
-
- 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.
You can use Queen in three ways
Install queen by executing npm install -g queen
in your command line.
Queen can be executed through the command line as queen [options] [filepath]
.
The only thing you cannot configure through the command line is populators, you'll need a
queenConfig.js file in order to define those.
When queen is started without a server-side script, it will act as a hub for remote clients to connect to and execute their server-side scripts. See the queen-remote project for more information on the remote client.
Queen can be require
'd in to your project as a module, allowing you to run queen programatically,
or extend it to suit your needs.