'TOX can't find the browser binary

I met a strange issue - I'm running Selenium tests with Tox on local machine (Windows 10) and it can't find the browser binary unless I pass all env variables to it. So it works when I do this:

[testenv]
passenv = *

By default Tox should pass Path but as I see Chrome (and other browsers) are not added to Path when they are installed, at least my machine doesn't have this in Path. I found that those are kept in Registry (https://docs.microsoft.com/en-gb/windows/win32/shell/app-registration) but how should this work correctly? I couldn't find manually which env variable has the needed browser path so I tried using "*" and it worked. Please advise what's the correct option here (maybe there's some hidden env variable?) so the code will work on any machine with needed browsers installed. Tox docs seem not having this info(

UPD: for Chrome I found out that passing the PROGRAMW6432 env variable solves the issue.

UPD2: debugging showed that tox used "x86" architecture for PROCESSOR_ARCHITEW6432 env variable and Firefox didn't work with tox until I passed the PROCESSOR_ARCHITEW6432 env variable. So passing both PROCESSOR_ARCHITEW6432 and PROGRAMW6432 allows running tests for Chrome, FF and Edge browsers on my machine without issues.

However it still looks like a workaround and I'd like to find out what's the correct way of dealing with it) It looks like (but I'm not sure yet) tox can't access the registry on my machine. Selenium has logic to find the browser executable path in registry if the path is not provided but it still can't find it. So maybe there's a way to allow viewing the registry on the machine?



Solution 1:[1]

Wow I hit this exact same bug!

This only happens in the tox environment so reproducing this is a pain. It turns out if I manually set the environmental variable PROGRAMW6432 then everything works.

Here's the fix:

import os
import sys
if sys.platform == "win32":
    os.environ.update(
        {
            "PROGRAMW6432": "C:\\Program Files",
        }
    )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S.B