DarthOpto
DarthOpto

Reputation: 1652

Using GeckoDriverManager().install() to run tests in Firefox

I have the following code to run tests in various browsers. Chrome of course works correctly on the machine I am wanting to run these tests on, however, Firefox, IE, and Edge do not. Is this the right way to go about this? I would prefer not to have to have a file I have to download and change every couple of months when the browsers update.

    def __init__(self, browser: str = TESTING_BROWSER, home: str = BASE_URL):
    """Hooray for inits."""
    if browser.lower() == "ie":
        webdriver.Ie.__init__(self, IEDriverManager().install())
    elif browser.lower() == 'edge':
        webdriver.Edge().__init__(self, EdgeDriverManager().install())
    elif browser.lower() == "firefox":
        webdriver.Firefox.__init__(self, GeckoDriverManager().install())
    else:
        chrome_options = Options()
        if os.environ.get('RUN_HEADLESS') == 'True':
            chrome_options.add_argument('--headless')
            chrome_options.add_argument("--disable-extensions")
            chrome_options.add_argument("--disable-gpu")
            webdriver.Chrome.__init__(self, ChromeDriverManager().install(), chrome_options=chrome_options)
        else:
            webdriver.Chrome.__init__(self, ChromeDriverManager().install())

As a side note when I try and run Firefox, I am getting the following error:

NotADirectoryError: [Errno 20] Not a directory: '/Users/me/.wdm/geckodriver/v0.24.0/macos/geckodriver'

I have tried adding executable_path=path to geckodriver and that is not working either.

Upvotes: 3

Views: 4883

Answers (1)

DarthOpto
DarthOpto

Reputation: 1652

So RTD wins again:

webdriver.Firefox.__init__(self, executable_path=GeckoDriverManager().install())

For those interested, the documentation to webdriver_manager is here

Upvotes: 2

Related Questions