WWW-Mechanize-PhantomJS
view release on metacpan or search on metacpan
lib/WWW/Mechanize/PhantomJS/ghostdriver/hub_register.js view on Meta::CPAN
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* generate node configuration for this node */
var nodeconf = function(ip, port, hub, proxy, version, remoteHost) {
var ref$, hubHost, hubPort;
ref$ = hub.match(/([\w\d\.]+):(\d+)/);
hubHost = ref$[1];
hubPort = +ref$[2]; //< ensure it's of type "number"
var platform;
if(ghostdriver && ghostdriver.system){
platform = ghostdriver.system.os.name.toUpperCase();
}
else{
// The prior behavior was to just assume Linux.
// Worst case scenario, we get the status quo, but
// this block is really just a guard condition anyway
platform = "LINUX";
}
var returnHost = "http://" + ip + ":" + port;
if (remoteHost) {
returnHost = remoteHost;
}
return {
capabilities: [{
browserName: "phantomjs",
version: version,
platform: platform,
maxInstances: 1,
seleniumProtocol: "WebDriver"
}],
configuration: {
hub: hub,
hubHost: hubHost,
hubPort: hubPort,
host: ip,
port: port,
proxy: proxy,
// Note that multiple webdriver sessions or instances within a single
// Ghostdriver process will interact in unexpected and undesirable ways.
maxSession: 1,
register: true,
registerCycle: 5000,
role: "wd",
url: "http://" + ip + ":" + port,
remoteHost: returnHost
}
};
},
_log = require("./logger.js").create("HUB Register");
module.exports = {
register: function(ip, port, hub, proxy, version, remoteHost) {
var page;
try {
page = require('webpage').create();
port = +port; //< ensure it's of type "number"
if(!hub.match(/\/$/)) {
hub += '/';
}
/* Register with selenium grid server */
page.open(hub + 'grid/register', {
operation: 'post',
data: JSON.stringify(nodeconf(ip, port, hub, proxy, version, remoteHost)),
headers: {
'Content-Type': 'application/json'
}
}, function(status) {
if(status !== 'success') {
_log.error("register", "Unable to contact grid " + hub + ": " + status);
phantom.exit(1);
}
if(page.framePlainText !== "ok") {
_log.error("register", "Problem registering with grid " + hub + ": " + page.content);
phantom.exit(1);
}
_log.info("register", "Registered with grid hub: " + hub + " (" + page.framePlainText + ")");
});
} catch (e) {
throw new Error("Could not register to Selenium Grid Hub: " + hub);
}
}
};
( run in 2.086 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )