使用量角器网络驱动程序进行 Safari 历史记录导航的未知错误

Unknown Error on Safari history Navigation using Protractor -webdrivers

本文关键字:记录 历史 导航 错误 未知 Safari 量角器 网络 驱动程序      更新时间:2023-09-26

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

    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')
      })

    });

这是 safari Selenium Webdriver 中的一个开放问题(自 2012 年 4 月以来):

  • [SafariDriver] 无法在浏览器历史记录中向前或向后导航。

而且,正如您在源代码中看到的那样,有一个硬编码的存根不允许浏览浏览器的历史记录(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...');
};

这是非常明显的解决方法,但可能对未来的读者有用:

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')
      });