Selenium 2 Grid - 了解您的测试正在使用哪个节点

发布于 2024-11-27 05:20:22 字数 100 浏览 1 评论 0原文

是否可以知道 selenium grid hub 分配给您的测试的是哪个节点?我的测试需要与节点机器上的其他服务进行通信,以便执行 selenium 不支持的配置。

标记

Is it possible to know which node the selenium grid hub assigned to your test? My tests need to talk to other services on the node machine in order to perform configurations which are not supported by selenium.

Mark

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

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

发布评论

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

评论(2

月亮坠入山谷 2024-12-04 05:20:22

一般来说,您不应该依赖于知道您的测试在哪台机器上运行。 Grid 2 提供了一系列回调侦听器,您可以实现它们来提供机器配置。但是,如果您确实想查看测试正在哪个节点上运行,您可以使用其中一个 API 调用。两个端点都可以在中心找到:

http://localhost:4444/grid/api/proxy

http://localhost:4444/grid/api/testsession

都尚未记录。但如果你查看源代码,就很容易看出它们是如何工作的。您想要查看 ProxyStatusServlet 和 TestSessionStatusServlet。

Generally you shouldn't rely on knowing what machine your test is running on. Grid 2 provides a series of callback listeners that you could implement to provide machine configuration. But, if you really want to see what node a test is running on, you could use one of the API calls. Both endpoints can be found on the hub:

http://localhost:4444/grid/api/proxy

http://localhost:4444/grid/api/testsession

Neither are documented yet. But if you view the source, it's straightforward to see how they work. You want to look at the ProxyStatusServlet and TestSessionStatusServlet.

春庭雪 2024-12-04 05:20:22
String hub = "grid_server_host"; //IP or hostname of GRID

int port = 4444; // port no.

HttpHost host = new HttpHost(hub,port);

DefaultHttpClient client = new DefaultHttpClient();

String url =  host + "/grid/api/testsession?session=";

URL session = new URL(url + ((RemoteWebDriver) webdriver).getSessionId());

BasicHttpEntityEnclosingRequest req;

req = new BasicHttpEntityEnclosingRequest("POST", session.toExternalForm());

org.apache.http.HttpResponse response  = client.execute(host,req);

JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity()));   

String proxyID = (String) object.get("proxyId");

String node = (proxyID.split("//")[1].split(":")[0]);
String hub = "grid_server_host"; //IP or hostname of GRID

int port = 4444; // port no.

HttpHost host = new HttpHost(hub,port);

DefaultHttpClient client = new DefaultHttpClient();

String url =  host + "/grid/api/testsession?session=";

URL session = new URL(url + ((RemoteWebDriver) webdriver).getSessionId());

BasicHttpEntityEnclosingRequest req;

req = new BasicHttpEntityEnclosingRequest("POST", session.toExternalForm());

org.apache.http.HttpResponse response  = client.execute(host,req);

JSONObject object = new JSONObject(EntityUtils.toString(response.getEntity()));   

String proxyID = (String) object.get("proxyId");

String node = (proxyID.split("//")[1].split(":")[0]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文