`
shijunjuan
  • 浏览: 45322 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

用Selenium Grid运行测试时获取Node地址

阅读更多

我们用Selenium Grid来运行测试。然而,在我们的测试失败时,我们想知道测试是运行在哪个Node机器上面。但是Selenium API并没有办法简单获取这个值。所以我需要发送请求给Grid来查看当前Session所在的Node地址。

 

 

try {
			HttpHost host = new HttpHost(hub, port);
			DefaultHttpClient client = new DefaultHttpClient();
			String sessionUrl = "http://" + hub + ":" + port
					+ "/grid/api/testsession?session=";
			URL session = new URL(sessionUrl
					+ ((RemoteWebDriver) driver).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]);
			System.out.println("WebDriver running in node:"+node);
			Logging.log("WebDriver running in node:"+node);
		} catch (Exception ex) {
		}
 

 

分享到:
评论
1 楼 shijunjuan 2013-12-31  
貌似Selenium最新版本已经可以通过exception查看node 地址了。

相关推荐

Global site tag (gtag.js) - Google Analytics