我使用 Selenium 2 和 Grid 中的 RemoteWebDriver 将测试划分到多个虚拟机上。假设我有两台 Linux 机器,在测试中我指定了在 Linux 机器上运行的功能,但我无法确定正在使用这两台机器中的哪一台。有什么办法可以弄清楚吗?像 driver.getServerIp() 或者其他什么?原因是,在我的 Selenium 测试代码中,我想在运行测试的 Linux 机器的控制台上启动 bash 脚本。因此我必须知道测试在哪台机器上运行。
多谢你们!
我的java技能不是最好的,这段代码需要一些清理,但这对我有用。
HttpHost host = new HttpHost(yourHubIP, yourHubPort);
DefaultHttpClient client = new DefaultHttpClient();
URL testSessionApi = new URL("http://" + yourHubIP + ":" + yourHubPort + "/grid/api/testsession?session=" + driver.getSessionId());
BasicHttpEntityEnclosingRequest r = new
BasicHttpEntityEnclosingRequest("POST", testSessionApi.toExternalForm());
HttpResponse response = client.execute(host,r);
JSONObject object = (JSONObject)new JSONParser().parse(EntityUtils.toString(response.getEntity()));
String proxyID = object.get("proxyId"));
Run Code Online (Sandbox Code Playgroud)
proxyID 包含节点的 IP。
归档时间: |
|
查看次数: |
5594 次 |
最近记录: |