• +43 660 1453541
  • contact@germaniumhq.com

Creating WebDriver Browser Instances With Germanium's open_browser()


Creating WebDriver Browser Instances With Germanium’s open_browser()

If you want to open a WebDriver browser instance using Selenium, you need a few steps. The binary driver available is required to be in the PATH, and you need to create a specific configuration object, depending on the browser type, to get the browser instance. In Germanium it’s only open_browser("chrome"). Since Germanium is Selenium, how is that working?

Germanium has a set of drivers that are bundled with it in a special package, named imaginatively germaniumdrivers. germaniumdrivers packages the binary drivers inside, and when a browser is requested, it unpacks the drivers, and makes them available to the path.

The gist of it all is a function called ensure_driver(browser). This unpacks the driver into a temp folder, and changes the os.path for the current process. The function returns the path to the unpacked binary, if for some reason you’re ever curious where it gets unpacked.

This is super cool, since now we have the ability to add or remove browsers directly from the environment, so our integration testing becomes a breeze. Instead of having:

open_browser('chrome')
go_to('http://....')

we have instead:

open_browser(os.environ.get('TEST_BROWSER', 'chrome'))
go_to('http://....')

Thus if no environment variable is set, we go with chrome, else to test it on a different browser becomes simply exporting an environment variable before execution. With no binary drivers download ever required for the test environment.

Testing on chrome:

python test.py

Testing on firefox? No need to touch the code:

export TEST_BROWSER=firefox
python test.py

Enjoy your integration tests :)