0

我尝试通过 webdriver-manager 和量角器开始测试。

验证版本:Google Chrome 73.0.3683.86 ChromeDriver 73.0.3683.68

启动 webdriver-managerwebdriver-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;
4

3 回答 3

1

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

"chromeOptions": {
                    "args": ['--no-sandbox','--disable-dev-shm-usage'],
于 2019-03-30T16:57:14.933 回答
0

请确保您有

127.0.0.1 localhost

在您的 /etc/hosts 文件中。

要检查它,你应该去终端并运行

sudo vi /etc/hosts

输入您的用户密码并粘贴

127.0.0.1 localhost 

到一个空行。

此外,请确保您已安装 ChromeDriver - 或您打算使用的浏览器的驱动程序 - 并且您的程序知道 ChromeDriver 的路径。

您可以按照此处说明的步骤https://www.browserstack.com/guide/run-selenium-tests-using-selenium-chromedriver

于 2021-12-16T13:48:12.177 回答
0

删除seleniumAddress:您的配置并添加以下配置。

exports.config = {
      directConnect: true,
}

添加dirctConnect=true时不需要单独启动 webdriver。

希望对你有帮助

于 2019-03-28T07:27:13.723 回答