'Get node IP address for a single session id in selenium4 grid
We are moving from selenium 3 grid to selenium 4 grid(with hub & node setup). We need to be able to fetch IP address of node on which the current session is being executed on(session id is fetched from driver.getSessionId())
For selenium3 grid, we got this info from <hub url>/grid/api/testsession?session=<sessionId>
I cannot find an equivalent endpoint for selenium 4 grid. I could find graphql query parameters but it fetches details for ALL the sessions. I need to find session details only for ONE session id.
Any help?
Solution 1:[1]
Note: Based on how the question is formulated I assume we are talking about node URI, which it's not always precise IP address of it. Having the URI it shouldn't be difficult to find the real ip, if indeed needed. Taking this into account...
GraphQL endpoint is the place to go. You can narrow the results by querying for specific sessionID (which you can get from webdriver as you pointed out).
cUrl example:
curl -X POST -H "Content-Type: application/json" --data '{"query":"{ session (id: \"<session-id>\") { id, capabilities, startTime, uri, nodeId, nodeUri, sessionDurationMillis, slot { id, stereotype, lastStarted } } } "}' -s <LINK_TO_GRAPHQL_ENDPOINT>
Prototype in node.js:
const { Builder } = require('selenium-webdriver');
const axios = require('axios').default;
async function main() {
let driver = await new Builder()
.usingServer('http://localhost:4444')
.forBrowser('chrome')
.build();
try {
await driver.get('https://www.cogitovirus.com/');
const title = await driver.getTitle();
console.log(`Sanity check. Title is: ${title}`);
const sessionId = (await driver.getSession()).getId()
console.log(`Session id: ${sessionId}`)
const res = await axios.post('http://localhost:4444/graphql', {
query: `{ session (id: \"${sessionId}\") { id, uri, nodeId, nodeUri} }`
});
console.log(res.data)
} catch (err) {
console.log(err)
} finally {
await driver.quit()
}
}
main()
Prints out:
Sanity check. Title is: cogitovirus.com
Session id: ce19fd89269af93327655537a1b65330
{
data: {
session: {
id: 'ce19fd89269af93327655537a1b65330',
uri: 'http://172.18.0.3:5555',
nodeId: 'ea5414e7-ac40-4744-aea5-8ff6faeeb8e2',
nodeUri: 'http://172.18.0.3:5555'
}
}
}
Tested using a quick setup of selenium grid docker
Grid GraphQL documentation
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |