Selenium is a great way to automate your browser testing.
Recently we had a customer write in asking about how to test browser extensions with Selenium.
After some research and a few changes mainly for message size, we have it working.
Since we are using webdriver.Remote you need to get the extension to our servers. You do that by including the extension in the chrome options or the firefox profile. In both cases the binary extension ends up being sent along in the capabilities in base64 encoding.
For Chrome your extension will be a crx file. See the code below on how to get the file included in the capabilities object.
In this example we create a ChromeOptions object then change it to a capabilities object. We are doing this to get at the chromeOptions field.
from selenium.webdriver.chrome.options import Options as ChromeOptions
chrome_options = ChromeOptions()
caps = chrome_options.to_capabilities()
caps[“chromeOptions”] = get_chrome_options(“my_extension.crx”)
For Firefox there is a similar sort of setup. You create a FirefoxProfile but end up only using the encoded version.
profile = webdriver.FirefoxProfile()
caps[“firefox_profile”] = get_firefox_profile(“my_extension.xpi”)
Feel free to take the code and change it up to suit your needs.