ChromeDriverFactory.transferChromeOptionsFromSystemProperties method splits args wrong.
I want to open page with A,B user-agent in Google Chrome browser.
I set chromeoptions.args environment variable like this:
String userAgentValue = "A,B";
System.setProperty("chromeoptions.args", "--user-agent=" + userAgentValue);
Then browser opens page with user-agent=A headers. Part after comma was missed.
@Test
public void userAgentWithCommas() {
Configuration.browser = "chrome";
String userAgentValue = "A,B";
System.setProperty("chromeoptions.args", "--user-agent=" + userAgentValue);
open("https://google.com");
open("https://google.com");
}
at the moment comma is a separator between different options like in
--user-agent=abc,--maximize-window=true etc.
that is the reason why it is ignored.
Unfortunately User-Agent could use almost every other separator as well as in
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
We can only use ASCII symbols because we may want to use it from command line like in
-Dchromeoption.args=....
So, we probably should handle "" for this cases for your example
--user-agent="A,B",anotherOption=....
Selenide should drop the "" when giving the params over to WebDriver. Not very complicated but not a one-liner :)
Can you make a PR for us with the solution? :)
You can assign this issue to me and I will fix it ASAP)
Your example to test with would be
System.setProperty("chromeoptions.args", "--user-agent=" +"\"" + userAgentValue + "\"");
I think the fix is probably something along the lines of:
ChromeDriverFactory.java:
private ChromeOptions transferChromeOptionsFromSystemProperties(ChromeOptions currentChromeOptions) {
...
List<String> args = Splitter.on(Pattern.compile(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")).split(chromeSwitches);
options.addArguments(options);
...
}
options.addArguments(__) takes varargs or list
@vinogradoff Could you provide me permissions for code committing?
You should work in a branch, everybody can commit in a branch. The it will
be review and merged
Viele Grüße
Alexei Vinogradov
On 26. Februar 2018 at 21:37:43, Dmitry Romashov ([email protected])
wrote:
@vinogradoff https://github.com/vinogradoff Could you provide me
permissions for code committing?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/codeborne/selenide/issues/697#issuecomment-368641574,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGQ4YM1ArIxOEPQeJnc12JfHxQnqzl1Gks5tYxX-gaJpZM4SN7TP
.
You have my permission...
@fyrewall77 @FrameBassman ideally add a util method e.g. "splitStringTakingCareOfQuotes(Char/String separator)" (separator=',')
and write enough unit tests for it like
abc,"ab,bc",abc ->abc ab,bc abc
abc,"ab\",bc",abc -> abc ab",bc abc
abc,\"ab,bc\",abc -> abc "ab bc" abc
I suggest to escape all important commas in arguments via backslash (\) character
Is the same for FF or Chrome only?
@rosolko @asolntsev @vinogradoff is this solved with #883 ? #836 got closed
Yes, solved by #883
Most helpful comment
You can assign this issue to me and I will fix it ASAP)