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

executable path of browser converted to unix format and loses the drive name so tests and executable need to be on the same drive #3667

Closed
eviltester opened this Issue Mar 16, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@eviltester

eviltester commented Mar 16, 2017

Meta -

OS:
Windows 10

Selenium Version:
3.3.1

Browser:

Firefox

Browser Version:

I was using portable firefox version 47.0.1 but this isn't strictly relevant to the bug because the code does not get as far as starting the browser

Expected Behavior -

When I set the browser binary, I expected it to use the binary no matter which drive I ran my tests from - this was behaviour in previous versions of WebDriver below 3.3.0

        String firefox_binary_path = "C:\\webdrivers\\FirefoxPortable\\FirefoxPortable.exe";

        capabilities.setCapability("firefox_binary", firefox_binary_path);

Actual Behavior -

In 3.3.1 the FirefoxOptions has a method call asUnixPath which converts

C:\webdrivers\FirefoxPortable\FirefoxPortable.exe

to

/webdrivers/FirefoxPortable/FirefoxPortable.exe

And while the capability still has the full path. The .binaryPath field in FirefoxOptions does not have the drive in it.

Therefore, when FirefoxOptions uses the getBinaryOrNull method the binaryPath field is used and this does not have the path in it so the check for file existence only works if the tests are running on the same drive as the browser executable is located.

Steps to reproduce -

Run a test which configures the location of the browser location, but have the browser located on a different drive.

Workaround

Run the tests from the same drive the executable is stored on.

@lmtierney lmtierney added the C-java label Mar 16, 2017

krmahadevan added a commit to krmahadevan/selenium that referenced this issue Mar 19, 2017

Removing unnecessary binary path calculation in toString()
Closes SeleniumHQ#3667

We shouldn’t be triggering binary path validation
in a toString() because sometimes users pack a 
Windows path in a OS X/LINUX machine as firefox_binary
path and create a desired capabilities object.
@krmahadevan

This comment has been minimized.

Show comment
Hide comment
@krmahadevan

krmahadevan Mar 19, 2017

Contributor

This can be recreated using below sample

import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.net.URL;

public class FirefoxOptionsDebug {
    private RemoteWebDriver driver;
    private String firefox = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";

    @BeforeClass
    public void beforeClass() throws IOException {
        String grid = "192.168.241.131";

        DesiredCapabilities caps = DesiredCapabilities.firefox();
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(firefox);
        caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
        driver = new RemoteWebDriver(new URL(String.format("http://%s:4444/wd/hub", grid)), caps);
    }

    @Test
    public void testMethod() {
        driver.get("http://www.google.com");

    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }
}

Here's the error message that gets triggered when executed from OS X

java.lang.IllegalStateException: Specified firefox binary location does not exist or is not a real file: C:\Program Files (x86)\Mozilla Firefox\firefox.exe

	at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
	at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:46)
	at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:162)
	at org.openqa.selenium.firefox.FirefoxOptions.getBinaryOrNull(FirefoxOptions.java:202)
	at org.openqa.selenium.firefox.FirefoxOptions.toString(FirefoxOptions.java:590)
	at java.lang.String.valueOf(String.java:2994)
	at org.openqa.selenium.remote.DesiredCapabilities.shortenMapValues(DesiredCapabilities.java:279)
	at org.openqa.selenium.remote.DesiredCapabilities.toString(DesiredCapabilities.java:268)
	at com.google.common.base.Joiner.toString(Joiner.java:455)
	at com.google.common.base.Joiner$1.toString(Joiner.java:225)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:379)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:415)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:401)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:340)
	at com.google.common.collect.Maps.toStringImpl(Maps.java:3789)
	at com.google.common.collect.ImmutableMap.toString(ImmutableMap.java:823)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at org.openqa.selenium.remote.Command.toString(Command.java:53)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at org.openqa.selenium.remote.RemoteWebDriver.log(RemoteWebDriver.java:695)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
	at com.rationaleemotions.github.issue3667.FirefoxOptionsDebug.beforeClass(FirefoxOptionsDebug.java:27)
	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:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
	at org.testng.TestRunner.privateRun(TestRunner.java:756)
	at org.testng.TestRunner.run(TestRunner.java:610)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
	at org.testng.SuiteRunner.run(SuiteRunner.java:289)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
	at org.testng.TestNG.runSuites(TestNG.java:1133)
	at org.testng.TestNG.run(TestNG.java:1104)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)
	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:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)


Test ignored.

===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
Contributor

krmahadevan commented Mar 19, 2017

This can be recreated using below sample

import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.net.URL;

public class FirefoxOptionsDebug {
    private RemoteWebDriver driver;
    private String firefox = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";

    @BeforeClass
    public void beforeClass() throws IOException {
        String grid = "192.168.241.131";

        DesiredCapabilities caps = DesiredCapabilities.firefox();
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary(firefox);
        caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
        driver = new RemoteWebDriver(new URL(String.format("http://%s:4444/wd/hub", grid)), caps);
    }

    @Test
    public void testMethod() {
        driver.get("http://www.google.com");

    }

    @AfterClass
    public void afterClass() {
        driver.quit();
    }
}

Here's the error message that gets triggered when executed from OS X

java.lang.IllegalStateException: Specified firefox binary location does not exist or is not a real file: C:\Program Files (x86)\Mozilla Firefox\firefox.exe

	at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
	at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:46)
	at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:162)
	at org.openqa.selenium.firefox.FirefoxOptions.getBinaryOrNull(FirefoxOptions.java:202)
	at org.openqa.selenium.firefox.FirefoxOptions.toString(FirefoxOptions.java:590)
	at java.lang.String.valueOf(String.java:2994)
	at org.openqa.selenium.remote.DesiredCapabilities.shortenMapValues(DesiredCapabilities.java:279)
	at org.openqa.selenium.remote.DesiredCapabilities.toString(DesiredCapabilities.java:268)
	at com.google.common.base.Joiner.toString(Joiner.java:455)
	at com.google.common.base.Joiner$1.toString(Joiner.java:225)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:379)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:415)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:401)
	at com.google.common.base.Joiner$MapJoiner.appendTo(Joiner.java:340)
	at com.google.common.collect.Maps.toStringImpl(Maps.java:3789)
	at com.google.common.collect.ImmutableMap.toString(ImmutableMap.java:823)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at org.openqa.selenium.remote.Command.toString(Command.java:53)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
	at org.openqa.selenium.remote.RemoteWebDriver.log(RemoteWebDriver.java:695)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:618)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
	at com.rationaleemotions.github.issue3667.FirefoxOptionsDebug.beforeClass(FirefoxOptionsDebug.java:27)
	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:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
	at org.testng.TestRunner.privateRun(TestRunner.java:756)
	at org.testng.TestRunner.run(TestRunner.java:610)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
	at org.testng.SuiteRunner.run(SuiteRunner.java:289)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
	at org.testng.TestNG.runSuites(TestNG.java:1133)
	at org.testng.TestNG.run(TestNG.java:1104)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)
	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:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)


Test ignored.

===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
@krmahadevan

This comment has been minimized.

Show comment
Hide comment
@krmahadevan

krmahadevan Mar 19, 2017

Contributor

@lmtierney - Can you please help review #3679 ?

Contributor

krmahadevan commented Mar 19, 2017

@lmtierney - Can you please help review #3679 ?

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Apr 7, 2017

Member

Fixed and will be released in 3.4
The commit for reference is ed3e946

Member

barancev commented Apr 7, 2017

Fixed and will be released in 3.4
The commit for reference is ed3e946

@barancev barancev closed this Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment