2017-05-18 39 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接口規範的一部分,您應該仍然可以使用它。