造成这种Selenium错误的原因是什么?

时间:2018-04-18 20:54:52

标签: javascript selenium nightwatch.js

使用NightwatchJS和Selenium我试图断言滚动位置在浏览器中是正确的。这是我在守夜人中的命令:

assertScrollPosition(testValue) {
            this.api.execute(() => {
                const offsetValue = window.pageYOffset;
                return offsetValue;
            }, [], (result) => {
                console.log(result);
                this.assert.equal(
                    testValue,
                    result.value,
                );
            });
        },

当我第一次开始使用此测试时,一切都正常运行。我不知道发生了什么变化,但result对象现在返回错误:

{ status: -1,
  value:
   { additionalInformation: '\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8), userDataDir=/var/folders/vq/zbcy3_q54lx8hmw4fxf1yjmr0000gn/T/.org.chromium.Chromium.ixmTka}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.117, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]\nSession ID: 56606c23e68c130649c1efa3573c3122',
     localizedMessage: 'unknown error: cov_1qa0joknhz is not defined\n  (Session info: chrome=66.0.3359.117)\n  (Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 9 milliseconds\nBuild info: version: \'2.53.0\', revision: \'35ae25b\', time: \'2016-03-15 17:00:58\'\nSystem info: host: \'MYHOST\', ip: \'192.168.1.239\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.11.6\', java.version: \'1.8.0_121\'\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8), userDataDir=/var/folders/vq/zbcy3_q54lx8hmw4fxf1yjmr0000gn/T/.org.chromium.Chromium.ixmTka}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.117, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]\nSession ID: 56606c23e68c130649c1efa3573c3122',
     supportUrl: null,
     systemInformation: 'System info: host: \'MYHOST\', ip: \'192.168.1.239\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.11.6\', java.version: \'1.8.0_121\'',
     cause: null,
     suppressed: [],
     message: 'unknown error: cov_1qa0joknhz is not defined\n  (Session info: chrome=66.0.3359.117)\n  (Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 9 milliseconds\nBuild info: version: \'2.53.0\', revision: \'35ae25b\', time: \'2016-03-15 17:00:58\'\nSystem info: host: \'MYHOST\', ip: \'192.168.1.239\', os.name: \'Mac OS X\', os.arch: \'x86_64\', os.version: \'10.11.6\', java.version: \'1.8.0_121\'\nDriver info: org.openqa.selenium.chrome.ChromeDriver\nCapabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8), userDataDir=/var/folders/vq/zbcy3_q54lx8hmw4fxf1yjmr0000gn/T/.org.chromium.Chromium.ixmTka}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.117, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]\nSession ID: 56606c23e68c130649c1efa3573c3122',
     hCode: 154590761,
     class: 'org.openqa.selenium.WebDriverException',
     buildInformation:
      { buildTime: '2016-03-15 17:00:58',
        buildRevision: '35ae25b',
        releaseLabel: '2.53.0',
        hCode: 2055848537,
        class: 'org.openqa.selenium.internal.BuildInfo' } },
  errorStatus: 13,
  error: 'An unknown server-side error occurred while processing the command.' }

1 个答案:

答案 0 :(得分:1)

变量cov_1qa0joknhz未在浏览器的上下文中定义。这个变量很可能是像伊斯坦布尔这样的覆盖工具注入的。要解决此问题,请将代码注入字符串:

this.api.execute("return window.pageYOffset;", ...