Andrew Lien
Andrew Lien

Reputation: 23

Need to downgrade chromedriver for Protractor to match earlier Chrome version

I am currently trying to get some existing Protractor tests running properly for an app that I will be doing QA work for. However, it looks like I will need to use an earlier version of chromedriver to sync up with the version of Chrome I am using (71.x) but I am not sure how to get Protractor to use a different version as it always downloads v76. Why do I need to do this? Context below.

After pulling the code from the repository, I did an "npm install" in the "/e2e" directory according to the instructions left by the previous dev, as well as updating things through webdriver-manager using "webdriver-manager update." When running Selenium, I got the "Invalid or corrupt jar file" error that is apparently an issue with the 4.0.0-alpha-1 and alpha-2 versions, so I downgraded Selenium to the standalone version 3.141.59.

This worked until I realized that when running the tests, the app didn't recognize the browser as being Chrome and failed the tests (it requires Chrome to run) even though it was definitely running Chrome. So, I had to downgrade my local machine's version of Chrome down to match the chromedriver version that my update pulled - I believe it was running chromedriver v75 and I was running v76 on my local machine.

I was told by a QA colleague that I should be running Chrome v71.x since that is what we are using for our release pipeline. So, I uninstalled Chrome and got Chrome v71.x, making sure that auto-updating was disabled. This means I need to get the version of chromedriver that matches this, which appears to be v2.46 from the digging I did online.

Now, to my core issue. Every time I try to update things through webdriver-manager it always downloads the latest version of chromedriver (v76) and I don't know how to get Protractor to use an earlier version. I have downloaded chromedriver 2.46 manually - I am guessing I need to point it to this version somehow, but messing with the config json files has not yielded any luck for me and I haven't found a good answer online.

Any help is appreciated as I am still new to how all this works.

For reference, this is the type of error that pops up when I try to run my specs:

[08:25:41] E/launcher - SessionNotCreatedError: session not created: This 
version of ChromeDriver only supports Chrome version 76
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11- 
14T08:25:53'
System info: host: 'xxxxxxxx', ip: 'xxxxxxxx', os.name: 'Windows 
8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_40'
Driver info: driver.version: unknown

Upvotes: 2

Views: 9014

Answers (3)

rup
rup

Reputation: 141

So my need was to do this programmatically as part of our build process. We use Jenkins for our CI process.

This is what the relevant section of our Jenkinsfile looks like. The matching driver version is installed after the npm install using webdriver-manager update. The grep statement is capturing the first three fields of the browser version. This is needed to append to the chromedriver url to return the four field version of the matching driver.

...
  stages {
    stage('Install') {
      steps {
        sh 'google-chrome --version'
        sh 'npm --version'
        sh 'node --version'
        sh 'yes | npm i'
                script {
                    env.chromeVersion = sh (
                        script: "google-chrome --version | grep -Po 'Chrome \\K[^\\.](\\d+\\.){2}\\d+'",
                        returnStdout: true
                    ).trim()
                }
        echo "chromeVersion: ${env.chromeVersion}"
        script {
             env.chromeDriverVersion = sh (
                 script: "curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${env.chromeVersion}",
                 returnStdout: true
             ).trim()
         }
        echo "chromeDriverVersion: ${env.chromeDriverVersion}"
        sh ("./node_modules/webdriver-manager/bin/webdriver-manager update --versions.chrome ${env.chromeDriverVersion}")
      }
    }
...

The other critical piece was to update the test run to direct Protractor to not update the driver after it had been installed. This is the relevant part of our package.json

{
  "name": "ourProduct",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "e2e": "ng e2e --webdriverUpdate=false"
  },

Then later in our Jenkinsfile, we are running the tests.

...
    stage('Run Tests') {
      steps {
        sh 'npm run e2e'
      }
    }
...

Upvotes: 0

Dejo
Dejo

Reputation: 11

This is very often issue, I solve this by checking what is the version of my local chrome, and then I just update to that version in package.json and then do npm i. Updating webdriver-manager does not solve the problem for me, it downloads the proper chrome binary but doesnt use it. So "npm i" solves it for me.

Upvotes: 1

Shubham Jain
Shubham Jain

Reputation: 17593

Your npm module will have folder as webdriver-manager. Here all binary ex chromedriver will be present.

Location:

/node_modules/protractor/bin/webdriver-manager

Now do below steps

  • Do webdriver-manager update

  • Now goto that folder and delete the chromedriver binary as per your OS i.e chromedriver.exe(Windows) and replace with it downgrade version of same which you will download from here, make sure name of the exe should be same as before Click Here

Run your test now

OR

To download a specific version of (for example) chromedriver:

webdriver-manager update --versions.chrome 2.46

webdriver-manager start --versions.chrome 2.46

Upvotes: 5

Related Questions