當Case在本地運行成功,在Grid模式下運行失敗時,我們需要在Grid模式下進行調試,同時登錄遠程的node去查看運行的情況。
Hub是隨機將case分配到某臺node上運行的,怎樣知道當前的case是運行在哪臺node上呢?
可以通過這段代碼獲取node的信息:
public void getComputerNameOfNode(WebDriver driver){ String hub = "SZAUTOTEST1"; int port = 4444; HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); String sessionUrl = "http://" + hub + ":" + port+ "/grid/api/testsession?session="+((RemoteWebDriver) driver).getSessionId(); HttpPost httpPost = new HttpPost(sessionUrl); System.out.println("Http post request is : "+httpPost.getRequestLine()); try{ //Execute HTTP request HttpResponse httpResponse = closeableHttpClient.execute(httpPost); //Get HTTP response HttpEntity entity = httpResponse.getEntity(); //Response status System.out.println("HTTP status:" + httpResponse.getStatusLine()); //Check if response is null if (entity != null) { System.out.println("Content encoding:" + entity.getContentEncoding()); String jsonString = EntityUtils.toString(entity); System.out.println("Response content:" + jsonString); JSONObject jsonObject = JSONObject.fromObject(jsonString); String proxyID=jsonObject.getString("proxyId"); String node = (proxyID.split("http://")[1].split(":")[0]); System.out.println("The case is running on this node :" + node); } } catch(IOException e){ e.printStackTrace(); } finally{ try{ closeableHttpClient.close(); } catch(IOException e){ e.printStackTrace(); } } }
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
