當(dāng)Case在本地運(yùn)行成功,在Grid模式下運(yùn)行失敗時(shí),我們需要在Grid模式下進(jìn)行調(diào)試,同時(shí)登錄遠(yuǎn)程的node去查看運(yùn)行的情況。
Hub是隨機(jī)將case分配到某臺(tái)node上運(yùn)行的,怎樣知道當(dāng)前的case是運(yùn)行在哪臺(tái)node上呢?
可以通過(guò)這段代碼獲取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(); } } }
?
[Selenium]Grid模式下運(yùn)行時(shí)打印出當(dāng)前Case在哪臺(tái)node機(jī)器上運(yùn)行
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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