aerokube / selenoid

Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
https://aerokube.com/selenoid/latest/
Apache License 2.0
2.6k stars 324 forks source link

Help needed on "Per-session Environment Variables: env" #492

Closed benzman81 closed 6 years ago

benzman81 commented 6 years ago

Hi,

until now we use selenoid images (chrome/ff) to test our webapp with locale EN. Now we also want to test it with locale DE. Your documentation states, that I can do this by passing a capability "env.

Adding the line capabilities.setCapability("env", new String[]{"LANG=de_DE.UTF-8", "LANGUAGE=de:den", "LC_ALL=de_DE.UTF-8"}); to our code, we receive the following error: org.openqa.selenium.WebDriverException: cannot create session firefox-60.0 on any hosts after 1 attempt(s), last host error was: Unable to find a matching set of capabilities

Are we missing something here?

Regards, Markus

vania-pooh commented 6 years ago

@benzman81 euh, Selenoid does not return such error: Unable to find a matching set of capabilities. You capability seems to be correct. Is it C# or Java?

vania-pooh commented 6 years ago

You can also try this approach: https://aerokube.com/selenoid/latest/#_specifying_capabilities_via_protocol_extensions

benzman81 commented 6 years ago

@vania-pooh its java

benzman81 commented 6 years ago

and its behind a ggr if that matters

benzman81 commented 6 years ago

Tried it now like this: Map<String, Object> opt = new HashMap<>(); // opt.put("screenResolution", "1280x1024x24"); opt.put("env", new String[]{"LANG=de_DE.UTF-8", "LANGUAGE=de:den", "LC_ALL=de_DE.UTF-8"}); capabilities.setCapability("selenoid:options", opt);

I don't get an error now, but the browser is still displaying everything in english. Setting the screen resolution works as expected.

vania-pooh commented 6 years ago

@benzman81 What is your Selenoid version? Please check whether it works with Chrome.

benzman81 commented 6 years ago

@vania-pooh chrome and ff do not set the language as expected with these settings.

We use the following images for our grid: aaerokube/selenoid:1.6.2 aerokube/selenoid-ui:1.6.1 aerokube/ggr:1.5.5 aerokube/ggr-ui:1.1.1

Our browser json:

{
    "chrome": {
        "default": "67.0",
        "versions": {
            "67.0": {
                "image": "selenoid/vnc:chrome_67.0",
                "port": "4444",
                "path": "/"
            }
        }
    },
    "firefox": {
        "default": "60.0",
        "versions": {
            "60.0": {
                "image": "selenoid/vnc:firefox_60.0",
                "port": "4444",
                "path": "/wd/hub"
            }
        }
    }
}
vania-pooh commented 6 years ago

@benzman81 could you set a breakpoint and check with docker inspect <container-id> that respective environment variables are set on browser container? I think variables are applied but language is not updated.

benzman81 commented 6 years ago

@vania-pooh result is added as file per browser, but I couldnt see the "LANG" settings. ff.txt chrome.txt

vania-pooh commented 6 years ago

@benzman81 just tried myself. Works like a charm with two notations. One with an array of strings:

caps.setCapability("env", new String[]{"LANG=de_DE.UTF-8", "LANGUAGE=de:den", "LC_ALL=de_DE.UTF-8"});

Another one with ArrayList:

        caps.setCapability("env", new ArrayList<String>(){
            {
                add("LANG=de_DE.UTF-8");
                add("LANGUAGE=de:den");
                add("LC_ALL=de_DE.UTF-8");
            }
        });

My Selenium Java client version is 3.8.0.

benzman81 commented 6 years ago

@vania-pooh ok, now more testing:

Using "selenoid:options" the language is not set for the browser but tests run of course failing to find text with correct locale.

Using "env" fully works with chrome (just tested ff before with this option) and tests run fine. But with firefox I still get the error: org.openqa.selenium.WebDriverException: cannot create session firefox-60.0 on any hosts after 1 attempt(s), last host error was: Unable to find a matching set of capabilities

benzman81 commented 6 years ago

Our Selenium Java version is 3.8.1.

vania-pooh commented 6 years ago

@benzman81 yes, does not work with Firefox. At least there is a bug with processing selenoid:options. Let's fix this and see whether it helps.

vania-pooh commented 6 years ago

@benzman81 should now work with aerokube/selenoid:latest. Only the 4th attempt to implement this was successful.

drundanibel commented 1 year ago

Hi,

same problem here, still with the firefox images currently provided on Docker Hub. I have tried almost every version image between 3.6 and 106.0. By the way, the current "latest" Firefox image doesn't want to start at all, not even from within Selenoid UI.

When I request the most recent Firefox version image like that:

curl \
    -H "Content-Type: application/json" \
    -X POST 'http://localhost:4444/wd/hub/session' \
    -d '{
            "desiredCapabilities": {
                "browserName": "firefox",
                "version": "106.0",
                "selenoid:options": {
                    "enableVNC": true,
                    "env": [
                        "LANG=de_DE.UTF-8",
                        "LANGUAGE=de:den",
                        "LC_ALL=de_DE.UTF-8"
                    ],
                    "sessionTimeout": "120s"
                }
            },
            "capabilities": {
                "alwaysMatch": {
                    "browserName": "firefox",
                    "browserVersion": "106.0",
                    "selenoid:options": {
                        "enableVNC": true,
                        "env": [
                            "LANG=de_DE.UTF-8",
                            "LANGUAGE=de:den",
                            "LC_ALL=de_DE.UTF-8"
                        ],
                        "sessionTimeout": "120s"
                    }
                },
                "firstMatch": [
                    {}
                ]
            }
        }'

... I get the Firefox UI with Englisch localization.

Same applies, when using a shorter env-config simply for German localization like "env": [ "LANG=de_DE.UTF-8" ].

In contrast, for Chrome and also Safari, both work. Moreover, for Chrome even "env": [ "LANG=de_DE" ] works.

So am I doing something wrong for Firefox or has the bug wormed its way into the Firefox images again?

vania-pooh commented 1 year ago

@drundanibel Firefox simply does not use this env variable. Instead you may need to set Firefox prefs explicitly:

FirefoxOptions options = new FirefoxOptions();
options.addPreference("intl.accept_languages", "de");
drundanibel commented 1 year ago

Thanks a lot, @vania-pooh! Since I needed the raw JSON string, I had to try out a few things, but this is how it actually works for me:

curl \
    -H "Content-Type: application/json" \
    -X POST 'http://localhost:4444/wd/hub/session' \
    -d '{
            "desiredCapabilities": {
                "browserName": "firefox",
                "version": "106.0",
                "moz:firefoxOptions": {
                    "prefs": {
                        "intl.accept_languages": "de"
                    }
                },
                "selenoid:options": {
                    "enableVNC": true,
                    "sessionTimeout": "120s"
                }
            },
            "capabilities": {
                "alwaysMatch": {
                    "browserName": "firefox",
                    "browserVersion": "106.0",
                    "moz:firefoxOptions": {
                        "prefs": {
                            "intl.accept_languages": "de"
                        }
                    },
                    "selenoid:options": {
                        "enableVNC": true,
                        "sessionTimeout": "120s"
                    }
                },
                "firstMatch": [
                    {}
                ]
            }
        }'
vania-pooh commented 1 year ago

@drundanibel yes, firefox prefs live under moz:firefoxOptions.