Unable to use protractor with chromedriver and sel

2019-06-14 11:07发布

问题:

Recently I updated my protractor, webdriver-manager, chromedriver, selenium-server.

After that I faced this problem: formerly we shared one protractor application in github with chromedriver and selenium-server in it. So others in my project can use it directly after downloaded this git project.

We don't have seleniumAddress and directConnect in our protractor configuration file. It means we launched tests with local driver.

But now update-config.json file was added to track chromedriver and selenium-server version and the paths in it were all absolute paths. We need to changed the paths after downloaded it.

So how can we use local driver without update-config.json file?

回答1:

There is a long explanation of how Protractor uses the update-config.json in this answer. The good news is you could avoid the update-config.json if you want to. I'll provide both examples for the local and directConnect since these are similar:

local without update-config.json

In lib/driverProviders/local.ts, the update-config.json could be avoided if you provide the paths to chromeDriver and the seleniumServerJar in your config file. If Protractor cannot find them, it will throw a BrowserError.

So your configuration file would look something like:

exports.config = {
  // launch locally when fields directConnect and seleniumAddress are not provided
  chromeDriver: '/path/to/chromedriver',
  seleniumServerJar: '/path/to/seleniumStandaloneServer.jar',
  specs: [ '/some/test.js' ],
  capabilities: {
    browserName: 'chrome'
  }
}

directConnect without update-config.json

Similarly, if you provide the chromeDriver path when using directConnect in your config, you could avoid using the update-config.json. The configuration file will look something like:

exports.config = {
  directConnect: true,
  chromeDriver: '/path/to/chromedriver',
  specs: [ '/some/test.js' ],
  capabilities: {
    browserName: 'chrome'
  }
}