zoukankan      html  css  js  c++  java
  • [Selenium] 在Grid模式下打印出当前Case是在哪台Node上运行

    AAAbstractFlow()

    public void getComputerNameOfNode(WebDriver driver){
    		String CIHub = Environment.getHub();
    		String hub = (CIHub.split("//")[1].split(":")[0]);
    		String port = (CIHub.split(":")[2].split("/")[0]);
    		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); 
    //		logger.info("Http post request is : "+httpPost.getRequestLine());
    		
    		try{
    			//Execute HTTP request
                HttpResponse httpResponse = closeableHttpClient.execute(httpPost);  
                //Get HTTP response
                HttpEntity entity = httpResponse.getEntity();  
                //Response status
    //            logger.info("HTTP status:" + httpResponse.getStatusLine());  
                //Check if response is null
                if (entity != null) {  
    //            	logger.info("Content encoding:" + entity.getContentEncoding()); 
                	String jsonString = EntityUtils.toString(entity);
    //            	logger.info("Response content:" + jsonString);
                	JSONObject jsonObject = JSONObject.fromObject(jsonString);
                	String proxyID=jsonObject.getString("proxyId");
                	String node = (proxyID.split("//")[1].split(":")[0]);
                	logger.info("The case is running on this node :" + node);
                }
    		}
    		catch(IOException e){
    			e.printStackTrace();  
    		}
    		finally{
    			try{
    				closeableHttpClient.close();  
    			}
    			catch(IOException e){
    				 e.printStackTrace();  
    			}
    		}
        }  
    

    AAAbstractTest()

    public class AAAbstractTest extends AbstractTest {
    	private static final Logger logger = Logger.getLogger(AAAbstractTest.class);
    	
    	@BeforeMethod(alwaysRun=true)
    	public void beforeTest(ITestContext context, Method method){
    		WebDriver driver = getDriver(method);
    		try{	
    			LoginFlow flow = new LoginFlow(getDriver(method));
    			if(Util.isUseGrid()){
    				flow.getComputerNameOfNode(driver);
    			}
    			UserBean userBean = getUser(method);
    			flow.login(userBean);
    			logger.info(method.getName());
    			
    			String loginUser = userBean.getName().toString() + "/" + userBean.getPwd().toString();
    			logger.info("Login user is : "+loginUser);
    		}
    		catch(Exception e){
    			logger.info("[AAAbstractTest--beforeTest]==" + method.getName());
    		}
    		
    	}
    	
    }
    

      

  • 相关阅读:
    gvim : invalid input string
    端口
    Sequence Overview
    vi的使用
    Ubuntu安装CodeBlocks相关问题总结
    中断
    Ubuntu Software Repository
    UVA 12299 RMQ with Shifts
    UVA 12293 Box Game
    POJ 3468 A Simple Problem with Integers (1)
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/5192926.html
Copyright © 2011-2022 走看看