nightwatch.js internet explorer

让人想犯罪 __ 提交于 2020-01-05 21:05:03

问题


I'm using nightwatch for testing my javascript application. I need to be able to run cross-browser tests on local machine. Chrome and Firefox are OK, but when running test on IE, I got an error:

Running:  google.com
    TypeError: undefined is not a function
    at pass (C:\Users\Dávid\AppData\Roaming\npm\node_modules\nightwatch\lib\api\
assertions\urlContains.js:23:18)
    at Object.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\night
watch\lib\core\assertion.js:94:23)
    at HttpRequest.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\
nightwatch\lib\index.js:299:20)
    at HttpRequest.emit (events.js:110:17)
    at HttpRequest.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modules\
nightwatch\lib\index.js:346:15)
    at HttpRequest.emit (events.js:118:17)
    at IncomingMessage.<anonymous> (C:\Users\Dávid\AppData\Roaming\npm\node_modu
les\nightwatch\lib\http\request.js:150:16)
    at IncomingMessage.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

IEDriverServer is in version 2.45.0 as used selenium is. I'm using x64 version on 64b Windows 8.1. And I've already done the registry thing for IE11.

Test file:

module.exports = {
    'google.com': function(browser){
        return browser
            .url('www.google.com')
            .pause(5000)
            .assert.urlContains('google')
            .end();
    }
}

nightwatch.json:

{
    "src_folders" : ["./tests/e2e"],
    "output_folder" : "./tests/reports",
    "custom_assertions_path" : "",
    "globals_path" : "",
    "live_output" : false,
    "parallel_process_delay" : 10,
    "disable_colors": false,

    "selenium" : {
        "start_process" : true,
        "server_path" : "./bin/selenium-server-standalone-2.45.0.jar",
        "log_path" : "",
        "host" : "127.0.0.1",
        "port" : 4444,
        "cli_args" : {
        "webdriver.chrome.driver" : "",
        "webdriver.ie.driver" : "./bin/IEDriverServer.exe",
        "webdriver.firefox.profile" : ""
    }
},

"test_settings" : {
    "default" : {
        "launch_url" : "http://localhost:3001",
        "selenium_host" : "127.0.0.1",
        "selenium_port" : 4444,
        "silent" : true,
        "disable_colors": false,
        "screenshots" : {
            "enabled" : false,
            "path" : ""
        },
        "desiredCapabilities" : {
            "browserName" : "firefox",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    },
    "chrome": {
        "desiredCapabilities" : {
            "browserName" : "chrome",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    },
    "ie": {
        "desiredCapabilities": {
            "browserName" : "internet explorer",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    }
}

run command:

nightwatch --env ie

It fails on this line:

.assert.urlContains('google')

For all help thanks in advance.


回答1:


I see you've got a solution, but having been through this myself, I thought I'd leave this here for future people.

Selenium docs say Internet Explorer requires specific configuration

  • IEDriverServer needs to be in the path. My experience has been that using %PATH% is surprisingly flaky, and I either:

    • set webdriver.ie.driver to a path in the cli_args of nightwatch.json
    • start the Selenium Server by hand with java -jar selenium-server-standalone-2.47.1.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe
  • Protected Mode in IE (Tools > Internet Options > Security) needs to be the same for all zones (as you've found!). I often test locally and on VMs, so I enabled it for Local and Trusted, rather than disable it for the Internet zone.

  • Set zoom to 100% (although, you know, why wouldn't it be?)

  • For IE10+, Enhanced Protected Mode needs to be disabled (Tools > Internet Options > Advanced > Security). Pretty sure this is disabled by default on client versions of Windows, but enabled on server versions.

  • For IE11+, do a reghack to facilitate the connection between the selenium server and the browser instance. In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE add a DWORD for iexplore.exe and set it to 0. If you're running 64-bit windows, that path becomes HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

One extra from my experience:

  • If you're on 64-bit windows, don't be tempted by the 64-bit IEDriverServer. It's slow. "Slower than the old lady in front of you at the ATM" slow.



回答2:


I've solved this issue by disabling IE protected mode for all zones and also by lowering the security to lowest possible level for all zones as well.




回答3:


I tried your test and it works fine on my laptop with Nightwatch v0.6.13. Which version of Nighwatch do you use ? (npm list nightwatch -g)



来源:https://stackoverflow.com/questions/30681263/nightwatch-js-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!