I am using node.js and selenium to build automated tests. So, when starting the script in one terminal, I use Commander to open another terminal and start selenium when I launch my automated tests. I do that like this when I want to do the testing with Safari:
if(myArgs.indexOf("LOCAL_SAF") != -1)
{ console.log('Starting selenium');
/* use Commander to open a shell script which opens a terminal and starts Selenium */
exec('open -a Terminal.app startSeleniumForSafari.sh',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
wait(2500);
console.log('Selenium should be started');
/* get the selenium webdriver executable for safari*/
safari = require('selenium-webdriver/safari');
browserUnderTest = new webdriver.Builder()
.forBrowser('safari')
.usingServer('http://localhost:4444/wd/hub')
.build();
}
/*
THIS IS NOT MY CODE. This came from
https://stackoverflow.com/questions/14226803/javascript-wait-5-seconds-before-executing-next-line
and was simple enough to understand, and suited my purposes.
*/
function wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
Rather then have a wait time and then print to the console that 'Selenium should be started', I'd like to somehow detect that it has indeed started, or if there is an error.
Is there a way to check the current status of the selenium server if it was launched in another terminal?
I know that calling http://localhost:4444/wd/hub/status will result in a response with JSON like {"state":"success","sessionId":null,"hCode":1982803459,"value":{"build":{"version":"2.52.0","revision":"4c2593c","time":"2016-02-11 19:06:42"},"os":{"name":"Mac OS X","arch":"x86_64","version":"10.12.6"},"java":{"version":"1.8.0_121"}},"class":"org.openqa.selenium.remote.Response","status":0}
But I know neither how to get that, nor what to do with it once gotten.