Safari历史记录上的未知错误使用Protractor -webdrivers进行导航

时间:2014-12-02 02:38:02

标签: javascript angularjs selenium safari protractor

我正在尝试使用多个浏览器作为测试来测试历史记录和后退按钮,并且会抛出此错误:

    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 个答案:

答案 0 :(得分:3)

这是safari selenium 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...');
};

答案 1 :(得分: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')
      });