在nightwatch.js中启用localStorage/webStorage

rok*_*tok 9 selenium nightwatch.js

我正在尝试测试依赖localStorage的应用程序.当我手动与浏览器交互时,一切正常.但是,在nightwatch.js请求localStorage时,我得到一个null响应而不是所需的字符串.这适用于Chrome和Firefox.

我已经尝试过通过分配,使localStore在夜巡JSON "webStorageEnabled" : truedesiredCapabilities这样的:

{
  "src_folders" : ["tests/functional/tests"],
  "output_folder" : "tests/functional/reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : true,
    "server_path" : "/Library/WebDevelopment/selenium-server/selenium-server-standalone-2.45.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/usr/local/lib/node_modules/chromedriver/lib/chromedriver/chromedriver",
      "webdriver.ie.driver" : ""
    }  
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "webStorageEnabled" : true,
        "databaseEnabled" : true,
        "applicationCacheEnabled" : true,
        "nativeEvents" : true,
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    } 
}
Run Code Online (Sandbox Code Playgroud)

localStorage应该使用时的工作nightwatch.js

dei*_*ito 2

在我的测试中,使用localstorage,需要使用“execute”命令在浏览器中注入javascript并与浏览器localstorage交互

it.only('expectation', function (client) {

    client.url('www.someurl.com').execute(function(data) {
        try {
            // statements
            localStorage.pepe = 1
            console.log('local', localStorage)
        } catch(e) {
            // statements
            console.log(e);
        }
        return true;
    }, [], function(result) {
    });
    client.pause(0);
});
Run Code Online (Sandbox Code Playgroud)