首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确调用Nightwatch.runTests?

如何正确调用Nightwatch.runTests?
EN

Stack Overflow用户
提问于 2020-06-29 17:37:17
回答 1查看 501关注 0票数 0

当我从代码中调用Nightwatch.runTests方法时,我得到一个错误:

代码语言:javascript
复制
/ Connecting to 127.0.0.1 on port 4444...
    POST  /wd/hub/session - ECONNREFUSED
‼ Error connecting to 127.0.0.1 on port 4444.
_________________________________________________

   Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4444". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".    
       at Socket.socketErrorListener (_http_client.js:407:9)
       at emitErrorNT (internal/streams/destroy.js:84:8)
       at processTicksAndRejections (internal/process/task_queues.js:80:21)

文档herehere指出该方法接受两个参数: testSource和settings。作为testSource,我指定了包含测试的文件夹的路径。对于设置,我指定一个等同于nightwatch.json文件内容的json对象。如错误所述,参数"start_process“设置为true。

下面是要重现的代码:

代码语言:javascript
复制
const Nightwatch = require('nightwatch');
const seleniumServer = require('selenium-server-standalone-jar');
const chromedriver = require('chromedriver');

const settings = {
    src_folders: ['tests'],
    output_folder: 'reports',
    detailed_output: true,
    live_output: true,
    selenium: {
        start_process: false,
        "server_path": seleniumServer.path,
        "log_path": "logs",
        "host": "127.0.0.1",
        "port": 4444,
        "cli_args": {
            "trustAllSSLCertificates": true,
            "webdriver.chrome.driver": chromedriver.path
        }
    },
    test_settings: {
        default: {
            silent: true,
            disable_error_log: false,
            screenshots: {
                enabled: false,
                path: 'screenshots',
                on_failure: true
            },
        },
        chrome: {
            desiredCapabilities: {
                browserName: 'chrome',
                javascriptEnabled: true,
                acceptSslCerts: true,
                chromeOptions: {
                    w3c: false
                }
            }
        }
    }
};

Nightwatch.runTests('tests', settings).then(function() {
    // Tests finished
}).catch(function(err) {
    // An error occurred
});

在我的项目中,我使用了"nightwatch":"^ 1.3.6“和"selenium-server-standalone-jar":"^ 3.141.59”。

我还根据自动生成的文件“nightwatch.conf.js”的结构更改了设置对象:

代码语言:javascript
复制
const settings = {
    src_folders: ['tests'],
    output_folder: 'reports',
    detailed_output: true,
    live_output: true,

    test_settings: {
        default: {
            disable_error_log: false,
            launch_url: 'https://nightwatchjs.org',

            screenshots: {
                enabled: false,
                path: 'screens',
                on_failure: true
            },

            desiredCapabilities: {
                browserName: 'chrome'
            },

            webdriver: {
                start_process: true,
                server_path: chromedriver.path
            }
        },

        chrome: {
            desiredCapabilities: {
                browserName: 'chrome',
                chromeOptions: {
                    args: []
                }
            },

            webdriver: {
                start_process: true,
                port: 9515,
                server_path: chromedriver.path,
                cli_args: []
            }
        },

        selenium: {
            selenium: {
                start_process: true,
                port: 4444,
                server_path: seleniumServer.path,
                cli_args: {
                    'webdriver.chrome.driver': chromedriver.path
                }
            }
        },

        'selenium.chrome': {
            extends: 'selenium',
            desiredCapabilities: {
                browserName: 'chrome',
                chromeOptions: {
                    w3c: true
                }
            }
        }
    }
};

但这并没有帮助,错误继续出现。

如果有人能帮助解决这个问题,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2020-06-29 17:45:11

你需要设置start_process: true,而不是start_process: false,你需要有效地设置w3c: true而不是w3c: false

代码语言:javascript
复制
const settings = {
    src_folders: ['tests'],
    output_folder: 'reports',
    detailed_output: true,
    live_output: true,
    selenium: {
        start_process: true,
        .
        .
        "cli_args": {
            "trustAllSSLCertificates": true,
            "webdriver.chrome.driver": chromedriver.path
        }

代码语言:javascript
复制
chrome: {
    desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        chromeOptions: {
            w3c: true
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62635280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档