Proxy settings for webdriver-io is not working

139 views Asked by At

I am using the proxy setting as mentioned in the webdriver-io configuration as below export const config = {

    // ...
    capabilities: [{
        browserName: 'chrome',
        // ...
        proxy: {
            proxyType: "manual",
            httpProxy: "corporate.proxy:8080",
            socksUsername: "codeceptjs",
            socksPassword: "secret",
            noProxy: "127.0.0.1,localhost"
        },
        // ...
    }],
    // ...
}

With this when I execute my tests I get the below screen

enter image description here

If I remove the proxy settings from the config file, it will popup a dialog to enter the user name and password for proxy.

I could not get any help to solve this issue. Any one has faced this issue before? I am using webdriverio using Javascript.

1

There are 1 answers

0
Vijay Nag On

I finally got one solution that worked for me. That is the chrome extension way.

Follow the below steps: manifest.js file

{
    "version": "1.0.0",
    "manifest_version": 2,
    "name": "Chrome Proxy",
    "permissions": [
        "proxy",
        "tabs",
        "unlimitedStorage",
        "storage",
        "<all_urls>",
        "webRequest",
        "webRequestBlocking"
    ],
    "background": {
        "scripts": ["background.js"]
    },
    "minimum_chrome_version":"22.0.0"
}

background.js

var config = {
    mode: "fixed_servers",
    rules: {
      singleProxy: {
        scheme: "http",
        host: "proxy url",
        port: parseInt('80')
      },
      bypassList: ["https://bypasslist.com"]
    }
  };

chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "USERNAME",
            password: "PASSWORD"
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
        callbackFn,
        {urls: ["<all_urls>"]},
        ['blocking']
);

ZIP the above 2 files and place it in your webdriverio project. In the wdio config file

var path = require("path")
var fs = require('fs')
const extension = fs.readFileSync(__dirname + `/extension/extension.zip`)
const base64 = Buffer.from(extension).toString('base64');

exports.config = merge ( defaults.config, {
    capabilities: [{
      browserName: 'chrome',
      platformName:'LINUX',
      'goog:chromeOptions': {
        extensions: [base64]
    } 

    }]
})

With this, the browser will not ask for proxy username and password.