2014-10-29 12 views
0

全部,當我投擲webdriver javascriptExecutor類型轉換錯誤字典

我想在我的webdriver項目中使用導航計時API。這是我試過,但它拋出錯誤

public static Dictionary<String, Object> getTimingAPI(){ 
 
\t \t try{ 
 
\t \t \t Dictionary<String, Object> dict = new Hashtable<String, Object>(); 
 
\t \t \t dict = (Dictionary<String ,Object>) ((JavascriptExecutor)driver)executeScript("var performance = window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance || {}; var timings = performance.timing || {};return timings;"); 
 
\t \t \t return dict; 
 
\t \t }catch (Exception e) { 
 
\t \t  System.err.println("Find browser timing : " + e); 
 
\t  } 
 
\t \t return null; 
 
\t }

錯誤: :

java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to java.util.Dictionary

我試圖轉換爲字符串,對象等,但總是拋出錯誤。我想知道什麼是這個Java腳本的返回對象。

感謝您的幫助。

+0

我已經解決了這個問題,通過改變JS返回個別時間並分配給對象,而不是返回所有的時間。 – bijumanvya 2014-10-30 05:42:15

回答

0

我已經解決了這個問題,通過改變JS來返回各個時間並分配給對象,而不是返回所有的時間。

Object start = (Object) ((JavascriptExecutor) NavigationHelper.getWebDriver()).executeScript("var performance = window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance || {}; var timings = performance.timing.navigationStart || {};return timings;");

0

這樣,它的工作原理。

Map(String,Object)map = new HashMap(String,Object)();

map =(Map(String,Object))((JavascriptExecutor)driver) .executeScript(JS_SCRIPT);