MarkusBernhardt / robotframework-selenium2library-java

Java port of the Selenium 2 (WebDriver) Python library for Robot Framework
Apache License 2.0
46 stars 48 forks source link

Unable to open firefox when passing in desiredCapabilities and browserOptions arguments #66

Closed ali-feint closed 8 years ago

ali-feint commented 9 years ago

First of all, it seems that to pass in browser options, you must also pass in desiredCapabilities.

That should be OK, except when I pass in both desiredCapabilities and browserOptions arguments, the browser will not open

I have tried 2 different firefox versions, and a few variations of the arguments, but my current attempt looks like (blank version is valid according to docs):

Selenium2Library.Open Browser ${url} desiredCapabilities={"platform":"WINDOWS","browserName":"firefox","version":""} browserOptions={}

I always get the error: java.net.MalformedURLException: no protocol: NONE

I cannot see anywhere to pass in a protocol...

There isnt much documentation around this, and I have also tried the examples here (same result): https://repo1.maven.org/maven2/com/github/markusbernhardt/robotframework-selenium2library-java/1.4.0.6/robotframework-selenium2library-java-1.4.0.6-libdoc.html#Open%20Browser

asitishere commented 9 years ago

DesiredCapabilities desiredCapabilities = createDesiredCapabilities(browserName, desiredCapabilitiesString,browserOptions);

Please check the Browser .exe you pointing to and path set in your system. Sometime if firefox.exe or chrome.exe is not accessible if set path has error.

To make chrome work or IE work you have to download the driver exe and point in the Open Browser Keyword code.

Example:

        System.setProperty("webdriver.chrome.driver", "c:/chromedriver.exe");
        return new ChromeDriver(desiredCapabilities);

Its in File BrowserManagement.java and section:

protected WebDriver createLocalWebDriver(String browserName, DesiredCapabilities desiredCapabilities) {


}

Please suggest if anything specific you want to set in desiredCapabilities.

Regards Asit

Hi-Fi commented 9 years ago

I don's see how answer should help with first one.

First issue is some example, that it can be tried that functionality works.

Second thing is the error that are coming when trying to use desiredCapabilities/browserOptions locally (not through Selenium-server).

if there's browserOptions and desiredCapabilities added, test prints:

15:18:35.634 WARN Opening browser 'firefox' to base url 'about:blank' through remote server at 'NONE' failed
15:18:35.705 FAIL java.net.MalformedURLException: no protocol: NONE

If "null", "none" or "empty" is tried to put to remoteUrl explicitely, test thows just

java.lang.NullPointerException

ali-feint commented 9 years ago

Yes, that is the same behaviour I get also! When i call: Open Browser ${url} firefox ${NONE} ${NONE} {"platform":"","browserName":"firefox","version":"", "firefox_binary":"C:\\workspace\\iE2-Robot\\Firefox\\FirefoxPortable.exe"} {"preferences" : {"browser.download.dir" : "C:\\Robot_Download_TEMP", "browser.download.folderList" : 2 } }

The test fails with a: FAIL java.lang.NullPointerException

And I get the following exception in the std out:

[ERROR] Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.4:run (default) on project automated-testing: 1 critical test case failed. Check the logs for details. -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.4:run (default) on project automated-testing: 1 critical test case failed. Check the logs for details. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213) at org.apache.maven.cli.MavenCli.main(MavenCli.java:157) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoFailureException: 1 critical test case failed. Check the logs for details. at org.robotframework.mavenplugin.RobotFrameworkMojo.evaluateReturnCode(RobotFrameworkMojo.java:55) at org.robotframework.mavenplugin.AcceptanceTestMojo.subclassExecute(AcceptanceTestMojo.java:68) at org.robotframework.mavenplugin.AbstractMojoWithLoadedClasspath.execute(AbstractMojoWithLoadedClasspath.java:52) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 more

Could this be caused by running on Java 8? Something to do with the AspectJ version being used?

Hi-Fi commented 9 years ago

I made it work. There's an bug (I think) in code, but it's not bothering with example.

Following keyword works OK:

Run keyword if "${BROWSER}"=="firefox" Open Browser about:blank browserName=${BROWSER} remoteUrl=False desiredCapabilities={} browserOptions=${browserOptions}

So correct value for remoteUrl (if it's not set) is False; not false, not ${EMPTY}, not ${NONE}, not NONE, not None.

Logging still tells that it's connecting to remote server, but actually it's not.

ali-feint commented 9 years ago

Whoohoo! Yup, that works for me too - thanks Hi-Fi.

It doesnt work unless you specifically set remoteUrl=False. Omitting that parameter fails - which I think is a bug.

Hi-Fi commented 9 years ago

Fix in #75.

MarkusBernhardt commented 8 years ago

Hi Hi-Fi, I ported that from the Python version, but I believe in Python null and false are handled the same in an if-statement: def open_browser(self, url, browser='firefox', alias=None,remote_url=False, desired_capabilities=None,ff_profile_dir=None):

I belive the easiest fix is to set the defaults as in python:

That should do the trick and be compatible with the AnnotationLibrary default handling.

What do you think?

Hi-Fi commented 8 years ago

That sounds right. I think code is already working in PR with all of those possibilities?

MarkusBernhardt commented 8 years ago

The problem is I had a general misunderstanding of how the AnnotationLibrary handles default values. When you specify a default "NONE" you get the string "NONE" and not null, when the field is not filled. This error runs through the whole library.

This needs a major overhaul.

MarkusBernhardt commented 8 years ago

Will release 1.4.0.8 first

MarkusBernhardt commented 8 years ago

Changed the default from "NONE" to "False". As in python. Now it works. Fixed with 1.4.0.8

MRDcoder commented 7 years ago

@MarkusBernhardt @Hi-Fi @asitishere & @ali-feint : its not working for me, i am gettting argument mismatch exception i tried below url but not working Open Browser ${portal_url} browserName=ff remoteUrl=False desiredCapabilities=network.http.phishy-userpass-length:255,network.automatic-ntlm-auth.trusted-uris:com.dcoder

Please have a look and do the needful