Instantly share code, notes, and snippets.

anonymous /determineNodeIP.php
Created Aug 30, 2016

Embed
What would you like to do?
Get IP of selenium node the test is running on (example, written in PHP with Mink, but it can be achieved for other webdriver bindings too)
/**
* Determine the IP of the selenium node the test is running on
*
* @return string|null Returns IP as string or null if was not successful
*/
function determineNodeIP($session, $seleniumhost, $seleniumport)
{
/**
* @var $webdriver Selenium2Driver
*/
$webdriver = $session->getDriver()
$capabilities = $webdriver->getWebDriverSession()->capabilities();
$sessionid = $capabilities['webdriver.remote.sessionid'];
$json = file_get_contents(
'http://' . $seleniumhost . ':' . $seleniumport
. '/grid/api/testsession?session=' . $sessionid
);
$sessionInformation = json_decode($json, true);
if (false === isset($sessionInformation['proxyId'])) {
// Abort, the selenium host is a selenium standalone (expected: selenium grid)
return null;
}
$ip = $matches[0];
return $ip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment