6

I have a scenario to run different versions of chrome in windows (for now let us consider only two). I have found the following way to run an instance of chrome:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy)
driver = webdriver.Chrome(
    chrome_options=chrome_options
)

I have default chrome and another version (located in Downloads directory). How do I run any desired version?

EDIT:

I have some blogs written here and here. Hope this helps someone.

Nabin
  • 11,216
  • 8
  • 63
  • 98
  • 1
    Please refer this -https://stackoverflow.com/questions/3785991/can-i-run-multiple-versions-of-google-chrome-on-the-same-machine-mac-or-window – demouser123 Jul 02 '17 at 05:54
  • 1
    It seems there's a `binary` option in the [ChromeOptions object](https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-chromeOptions-object) that configures the path to a Chrome binary. Though this seems to be related to local Chrome instances only. This option seems to make no sense when running against a hub or remote standalone server since multiple version to path mappings should be configured _at the ChromeDriver side_ (that is passed to the _selenium server_) and the ChromeOptions should provide a `version` config (or alike) to instruct the server to choose the binary. – try-catch-finally Jul 02 '17 at 16:47
  • This one has step by step help https://e4example.blogspot.com/2017/07/run-different-version-of-chrome-using.html – Nabin Jul 06 '17 at 14:44
  • BrowserStack of Sauce Labs are also options here - provide which browser versions you want through capabilities. – alecxe Jul 07 '17 at 02:27
  • @alecxe Can you please provide me some links? – Nabin Jul 07 '17 at 02:29

1 Answers1

9

One way is to define the location in the capabilities with the Options class:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.binary_location = r'C:/chromium-48/chrome.exe'
driver = webdriver.Chrome(chrome_options=options)

or with DesiredCapabilities:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capa = DesiredCapabilities.CHROME;
capa['chromeOptions'] = {
  'binary': r'C:/chromium-48/chrome.exe',
  'args': []
}

driver = webdriver.Chrome(desired_capabilities=capa)

But if you are looking for a scalable solution, then you should setup a grid with the different versions:

  • Start the hub:
java -jar selenium-server-standalone-2.53.1.jar -role hub -host 0.0.0.0 -port 4444
  • Start a node for version 48:
java -jar selenium-server-standalone-2.53.1.jar 
 -role node 
 -hub http://localhost:4444/grid/register
 -browser platform=WINDOWS,browserName=chrome,version=48,chrome_binary="C:/chromium-48/chrome.exe"
  • Start a node for version 54:
java -jar selenium-server-standalone-2.53.1.jar 
 -role node 
 -hub http://localhost:4444/grid/register
 -browser platform=WINDOWS,browserName=chrome,version=54,chrome_binary="C:/chromium-54/chrome.exe"

You can then choose the version directly in the capabilities:

from selenium import webdriver
capa = {'browserName': 'chrome', 'version': '48', 'platform': 'ANY'}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=capa)
Florent B.
  • 41,537
  • 7
  • 86
  • 101