Way to add driver options to capabilities in Java?

38 views
Skip to first unread message

Robin

unread,
Jan 14, 2017, 12:40:05 AM1/14/17
to webdriver
I am trying to convert a method to Java which adds DriverOptions and Desired Capabilities to ICapabilities.  The method is currently written in C#.  
Below are snippets of the C# code.   What is causing me issues is the options.ToCapabilities(), which doesn't exist in Java.  
Anyone have suggestions as to how to approach this conversion to Java?  
We are using Java 8 and Selenium 3.0.1

Thanks in advance!

.....
            ICapabilities browserCap;
            DesiredCapabilities browserBaseCap;

            if (options == null)
            {
                switch (browserType)
                {
                 ....proprietary code here...cannot include...

                 default:
                        throw new ArgumentException("The " + browserType.ToString() + " browser is not currently supported on the Grid network. 
                 }

                browserBaseCap.IsJavaScriptEnabled = true;
                browserCap = browserBaseCap;
            }
            else
            {
                browserCap = options.ToCapabilities();
            }
            return browserCap;

darrell grainger

unread,
Jan 15, 2017, 4:18:47 PM1/15/17
to webdriver
In Java you want to do something like:

DesiredCapabilities dc = new DesiredCapabilities();
dc.setJavascriptEnabled(true);
return dc; 

then if you want to instantiate an instance of say ChromeDriver you would use:

WebDriver driver = new ChromeDriver(dc);
Reply all
Reply to author
Forward
0 new messages