2017-05-18 38 views
0

我正在使用JAVA和Selenium WebDriver测试自动化脚本, 我的测试运行在云环境(crossbrowsertesting.com)上。 有一个功能可以拍摄浏览器窗口的快照, 当我使用RemoteWebDriver时,这行代码可以正常工作,但需要用WebDriver替换它,因为原因不是打包得到windowHandles。 但我得到下面的错误现在,说明 “的方法getSessionId()是未定义的类型的webdriver”JSONOBject哈希未找到

snapshotHash=myTest.takeSnapshot(driver.getSessionId().toString()); 

// takeSnapshot方法:

public String takeSnapshot(String seleniumTestId) throws UnirestException { 
     System.out.println("Screen Shots Taken."); 

     /* 
     * Takes a snapshot of the screen for the specified test. 
     * The output of this function can be used as a parameter for setDescription() 
     */ 
     HttpResponse<JsonNode> response = Unirest.post("http://crossbrowsertesting.com/api/v3/selenium/{seleniumTestId}/snapshots") 
       .basicAuth(username, api_key) 
       .routeParam("seleniumTestId", seleniumTestId) 
       .asJson(); 
     // grab out the snapshot "hash" from the response 
     snapshotHash = (String) response.getBody().getObject().get("hash"); 

     return snapshotHash; 
    } 

回答

0

我不明白为什么你需要使用“WebDriver”来代替“RemoteWebDriver”? “RemoteWebDriver”是所有网络驱动程序实现的母体,它应该足以处理任何远程网格环境。我不明白你为什么需要切换到使用“WebDriver”引用,它是“RemoteWebDriver”实现的接口之一。 getSessionId()不是任何接口规范的一部分,但它是RemoteWebDriver提供的直接实现。

getWindowHandles()WebDriver接口规范的一部分,您应该仍然可以使用它。