chromedriver仅允许本地连接

时间:2019-03-27 09:27:36

标签: protractor selenium-chromedriver webdriver-manager

我尝试通过webdriver-manager和protractor开始测试。

验证版本: 谷歌浏览器73.0.3683.86 ChromeDriver 73.0.3683.68

启动webdriver-manager webdriver-manager start 并开始量角器

我因量角器而出错

enviroment: test
[12:20:23] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[12:20:23] E/driverProvider - Error code: 135
[12:20:23] E/driverProvider - Error message: unknown error: Chrome failed to start: exited abnormally
[12:20:23] E/driverProvider - Error: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Linux 4.9.0-8-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 172 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'dev', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.0-8-amd64', java.version: '1.8.0_212'
Driver info: driver.version: unknown
    at Hosted.<anonymous> (/usr/lib/node_modules/protractor/built/driverProviders/driverProvider.js:69:23)
    at Generator.throw (<anonymous>)
    at rejected (/usr/lib/node_modules/protractor/built/driverProviders/driverProvider.js:5:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)
[12:20:23] E/launcher - Process exited with error code 135

和信息由webdriver-manager

12:19:38.934 INFO [ActiveSessionFactory.apply] - Capabilities are: {
  "browserName": "chrome",
  "count": 1
}
12:19:38.947 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 15966
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

项目文件夹中的protractor.conf.js(我在其中执行命令protractor --host https://MySite

let test_url = '';
let enviroment = process.env.NODE_ENV;
console.log('enviroment:', enviroment);
//console.log('process.env:', process.env);

let settings = {
        seleniumAddress: 'http://localhost:4444/wd/hub',
        //directConnect: true,
        specs: ['./e2e/todo-spec.js'],
        // Options to be passed to Jasmine-node.
        params: {
                host: 'http://localhost:3000'
        },
        capabilities: {
                browserName: 'chrome'
        },
        onPrepare: function() {
            // The require statement must be down here, since jasmine-reporters@1.0
            // needs jasmine to be in the global and protractor does not guarantee
            // this until inside the onPrepare function.
            var jasmineReporters = require('jasmine-reporters');
            jasmine.getEnv().addReporter(
                new jasmineReporters.JUnitXmlReporter('xmloutput', true, true)
            );
        },
        jasmineNodeOpts: {
                showColors: true,
                defaultTimeoutInterval: 30000
        }
}
if(process.env.hasOwnProperty('npm_config_host') && process.env.npm_config_host){
        settings.params.host = process.env.npm_config_host
}


exports.config = settings;

2 个答案:

答案 0 :(得分:0)

从您的配置中删除seleniumAddress:并添加以下内容。

exports.config = {
      directConnect: true,
}

添加dirctConnect=true时,无需分别启动Webdriver。

希望对您有帮助

答案 1 :(得分:0)

您可以在chromeOptions中尝试添加--no-sandbox--disable-dev-shm-usage,然后尝试运行测试吗?另外,请尝试降级浏览器版本,以查看代码是否按预期工作。

"chromeOptions": {
                    "args": ['--no-sandbox','--disable-dev-shm-usage'],