2014-12-02 126 views
1

我想只是測試歷史和背部使用muliple瀏覽器作爲測試按鈕和這個錯誤被拋出:未知錯誤-webdrivers

UnknownError: Yikes! Safari history navigation does not work. We can go forward or back, but once we do, we can no longer communicate with the page... (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 19 milliseconds 
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03' 
System info: host: 'SFM1SKF1G3L.local', ip: '10.16.100.172', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.3', java.version: '1.8.0_05' 
Driver info: org.openqa.selenium.safari.SafariDriver 
Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=7.0.3, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}] 
Session ID: null 

這個測試工作在Chrome和Firefox但不是Safari瀏覽器:

it("should open find a clinic page", function(){ 

     browser.driver.sleep(2000); 
     browser.ignoreSynchronization = true; 

     var string = 'clinic'; 
     var main = '.search-large-text'; 
     var link = element(by.cssContainingText('.submenu li a', string)); 


     expect(link.getText()).toEqual(string); 

     link.click().then(function() { 

     browser.driver.sleep(3000); 
     var title = element(by.cssContainingText(main, string)); 
     expect(title.getText()).toBe(string); 
     }); 

     browser.navigate().back().then(function(){ 
     browser.driver.sleep(3000); 
     expect(browser.driver.getTitle()).toBe('Target : Expect More Pay Less') 
     }) 


    }); 

回答

2

這是很明顯的解決方法,但也許會爲未來的讀者有用:

var prevUrl = browser.getCurrentUrl(); 
link.click().then(function() { 

     browser.driver.sleep(3000); 
     var title = element(by.cssContainingText(main, string)); 
     expect(title.getText()).toBe(string); 
     }); 
browser.navigate().to(prevUrl).then(function(){ 
     browser.driver.sleep(3000); 
     expect(browser.driver.getTitle()).toBe('Target : Expect More Pay Less') 
     }); 
3

這是在Safari中硒的webdriver開放(自2012年4月)的問題:

而且,正如你可以在the source code看到的,是不會讓通過瀏覽器的歷史導航(這back()正在做)的硬編碼存根:

/** 
* Stub that reports an error that navigating through the browser history does 
* not work for the SafariDriver. 
*/ 
safaridriver.inject.commands.unsupportedHistoryNavigation = function() { 
    throw Error('Yikes! Safari history navigation does not work. We can ' + 
     'go forward or back, but once we do, we can no longer ' + 
     'communicate with the page...'); 
}; 
+0

Alecex如何地獄你知道這麼多關於硒/量角器笑 – 2014-12-02 11:58:00

+0

至少錯誤消息爲c rystal明確:/ – glepretre 2014-12-03 18:42:16