获取Selenium4网格中单个会话ID的节点IP地址

发布于 2025-01-24 11:39:50 字数 437 浏览 0 评论 0原文

我们正在从Selenium 3网格移动到Selenium 4网格(带有轮毂&节点设置)。我们需要能够获取当前会话正在执行的节点的IP地址(从driver.getSessionId()

selenium3 grid获取会话ID,我们从< Hub>///网格/api/testsession?session =< sessionId>

我找不到硒4网格的等效端点。我可以找到 graphql 查询参数,但它获取所有会议的详细信息。我只需要为一个会话ID找到会话详细信息。

有帮助吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2025-01-31 11:39:50

注释:根据如何提出问题,我假设我们在谈论node uri,这并不总是它的精确IP地址。拥有URI,如果确实需要,则不难找到真正的IP。考虑到这一点...

GraphQl端点是去的地方。您可以通过查询特定的sessionID来缩小结果(如您指出的那样,您可以从WebDriver获取)。

卷曲示例:

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>

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()

打印出:

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'
    }
  }
}

使用

grid graphql

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文