Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARQ-2037 Added a support of additional browser capabilities for Chrome #65

Closed
wants to merge 3 commits into from

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Sep 2, 2016

With this commit, it should be possible to set all possible chrome options into
a chromeDriver through arquillian.xml file. All the options you can find
here: https://sites.google.com/a/chromium.org/chromedriver/capabilities
All the options are set into ChromeOptions class:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html
which means that the parameter names tightly depend on names of the set/add
methods.
It is expected that the name of a parameter consist of:
"chrome" + (name of set/add method of ChromeOption class without first three chars)
whole string in camelcase.
eg for option args there should be:
<property name="chromeArguments">--your-cool --arguments</property>
If the value can be an array or list of strings/files, then specify all of
them in one string separated by space. (This is also applied for
extensions as well as for encoded extensions.)
In the case of experimental options it is a little bit different. As there
is expected a set of dictionaries, the most suitable way is using JSON
format - eg:
<property name="chromeExperimentalOption">{"perfLoggingPrefs": { "traceCategories": ",blink.console,disabled-by-default-devtools.timeline,benchmark" }, "prefs": {"download.default_directory": "/usr/local/path/to/download/directory"} }</property>
(can be in multiline format )

If you are still struglling with passing required options through
arquillian.xml, you can use a parameter chromePrintOptions with a value
true:
<property name="chromePrintOptions">true</property>
This ensures that Drone prints whole content of ChromeOptions in a JSON
format on a standard output.

This change is Reviewable

With this, it should be possible to set all possible chrome options into
a chromeDriver through arquillian.xml file. All the options you can find
here: https://sites.google.com/a/chromium.org/chromedriver/capabilities
All the options are set into ChromeOptions class:
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html
which means that the parameter names tightly depend on names of the set/add
methods.
It is expected that the name of a parameter consist of:
"chrome" + (name of set/add method of ChromeOption class without first three chars)
whole string in camelcase.
eg for option args there should be:
<property name="chromeArguments">--your-cool --arguments</property>
If the value can be an array or list of strings/files, then specify all of
them in one string separated by space. (This is also applied for
extensions as well as for encoded extensions.)
In the case of experimental options it is a little bit different. As there
is expected a set of dictionaries, the most suitable way is using JSON
format - eg:
<property name="chromeExperimentalOption">{"perfLoggingPrefs": {
"traceCategories":
",blink.console,disabled-by-default-devtools.timeline,benchmark"
 }, "prefs": {"download.default_directory":
"/usr/local/path/to/download/directory"} }</property>
(can be in multiline format )

If you are still struglling with passing required options through
arquillian.xml, you can use a parameter chromePrintOptions with a value
"true":
<property name="chromePrintOptions">true</property>
This ensures that Drone prints whole content of ChromeOptions in a JSON
format on a standard output.
@MatousJobanek
Copy link
Contributor Author

This is a fix for #64

@TadeasKriz
Copy link
Member

Review status: 0 of 7 files reviewed at latest revision, 9 unresolved discussions.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/factory/CapabilitiesMapper.java, line 173 [r1] (raw file):

    private static <T> T booleanNumberStringOrFile(Class<T> clazz, String value) {
        return (T) (!String.class.equals(clazz) ?

This method is really cluttered and confusing. Wouldn't it be better to not use nesting/ternary operators? I.e.:

if (File.class.equals(clazz)) {
    return new File(value)
}
if (Integer.class.equals(clazz)) {
    return Integer.valueOf(value)
}

// the same for other types

return null

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/factory/ChromeDriverFactory.java, line 116 [r1] (raw file):

        if (Validate.nonEmpty(printChromeOptions) && Boolean.valueOf(printChromeOptions.trim())){
            try {
                System.out.println("======== Chrome options =========");

Shouldn't some logger be used instead of writing directly to out?


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/factory/ChromeDriverFactory.java, line 120 [r1] (raw file):

                System.out.println("===== End of Chrome options =====");
            } catch (IOException e) {
                e.printStackTrace();

Who is throwing the IOException here? Is it really possible to ignore it and is it wise to print the stack trace?


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 58 [r1] (raw file):

    }

    public static String trimMultiline(String toTrim) {

This whole method looks like it was taken from some disassembled Java code.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 60 [r1] (raw file):

    public static String trimMultiline(String toTrim) {
        StringBuilder builder = new StringBuilder(toTrim.length());
        String[] var2 = toTrim.split("\\s+");

More descriptive variable names would help in this method.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 60 [r1] (raw file):

    public static String trimMultiline(String toTrim) {
        StringBuilder builder = new StringBuilder(toTrim.length());
        String[] var2 = toTrim.split("\\s+");

Correct me if I'm wrong, but doesn't this split by every whitespace, removing the need to do .trim()? Also I though this method is trimming spaces on every line. So if it trims each space-separated part, I suggest renaming the method.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 63 [r1] (raw file):

        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {

Why not iterate using for (String token : var2) { .. }?


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 65 [r1] (raw file):

        for(int var4 = 0; var4 < var3; ++var4) {
            String token = var2[var4];
            if(token != null && !"".equals(token.trim())) {

I'm not sure about the performance of .trim method, but it might be better to extract it to a variable.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 70 [r1] (raw file):

        }

        return builder.toString().trim();

Isn't this trim unnecessary?


Comments from Reviewable

@MatousJobanek
Copy link
Contributor Author

Review status: 0 of 7 files reviewed at latest revision, 9 unresolved discussions.


drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/factory/ChromeDriverFactory.java, line 120 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

Who is throwing the IOException here? Is it really possible to ignore it and is it wise to print the stack trace?

The IOException is thrown by chromeOptions.toJson(). So I think that it is possible to ignore it and regarding printing stacktrace - I put it there to let user know when something bad happened

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 58 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

This whole method looks like it was taken from some disassembled Java code.

Yeah, I've stolen it from the arquillian-core project: https://github.com/arquillian/arquillian-core/blob/master/container/impl-base/src/main/java/org/jboss/arquillian/container/impl/MultilineTrimmer.java I've copy-pasted it from decompiled java code in IDE (just wanted to try it if and how it works), so this is the reason why the whole method looks so weird. And after implementing the main code itself I completely forgot to replace it by normal code. Yeah, I'm stupid... I'll fix it

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 60 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

Correct me if I'm wrong, but doesn't this split by every whitespace, removing the need to do .trim()? Also I though this method is trimming spaces on every line. So if it trims each space-separated part, I suggest renaming the method.

I think that from the original code: https://github.com/arquillian/arquillian-core/blob/master/container/impl-base/src/main/java/org/jboss/arquillian/container/impl/MultilineTrimmer.java it is more clear what it really does.

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 63 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

Why not iterate using for (String token : var2) { .. }?

Sorry for this method - as I wrote above - it is my big fault that I forgot to replace it by normal code.

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 65 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

I'm not sure about the performance of .trim method, but it might be better to extract it to a variable.

Do you have any statistic/reference/article about it?

drone-webdriver/src/main/java/org/jboss/arquillian/drone/webdriver/utils/StringUtils.java, line 70 [r1] (raw file):

Previously, TadeasKriz (Tadeas Kriz) wrote…

Isn't this trim unnecessary?

Yes it is - the trim is for the last string that is appended with a white space after it.

Comments from Reviewable

@MatousJobanek
Copy link
Contributor Author

@TadeasKriz thanks a lot for your review and sorry for my stupidity that I forgot to replace the confusing copy-pasted methods.

@MatousJobanek
Copy link
Contributor Author

Landed in a1d3e46

@michalvanco
Copy link

Thanks @MatousJobanek for implementing this support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants