java - 在路径中,java找不到 Firefox 二进制 确保已经安装 Firefox

  显示原文与译文双语对照的内容
149 2

在 selenium 网格中,我正在尝试执行一个简单的程序,我正在 Cannot find firefox binary in PATH 虽然我已经在代码中添加了二进制路径。
下面给出了我的代码和错误。 请你帮忙,谢谢。


代码


package Sample;


import java.net.MalformedURLException;


import java.net.URL;


import org.openqa.selenium.Platform;


import org.openqa.selenium.WebDriver;


import org.openqa.selenium.remote.DesiredCapabilities;


import org.openqa.selenium.remote.RemoteWebDriver;


import org.testng.annotations.Test;


import org.testng.annotations.BeforeTest;


import org.testng.annotations.AfterTest;


public class sample1 {


 WebDriver driver;


 String BaseURL,NodeURL;


@BeforeTest


 public void beforeTest() throws MalformedURLException {


 BaseURL="www.google.com";


 NodeURL="http://192.168.10.162:5566/wd/hub";


 DesiredCapabilities capa =DesiredCapabilities.firefox();


 capa.setBrowserName("firefox");


 capa.setCapability("binary","C:Userspraveenraj.dAppDataLocalMozilla Firefoxfirefox.exe");


 capa.setPlatform(Platform.ANY);


 driver=new RemoteWebDriver(new URL(NodeURL),capa);


 }


 @Test


 public void f() throws InterruptedException {


 driver.get(BaseURL);


 System.out.println(driver.getTitle());


 Thread.sleep(50000);


 }


 @AfterTest


 public void afterTest() {


 driver.quit();


 }


 }




错误


[TestNG] Running:


 C:Userspraveenraj.dAppDataLocalTemptestng-eclipse-1233453386testng-customsuite.xml



FAILED CONFIGURATION: @BeforeTest beforeTest


org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8


Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'


System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'


Driver info: driver.version: FirefoxDriver


Command duration or timeout: 97 milliseconds


Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'


System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'


Driver info: org.openqa.selenium.remote.RemoteWebDriver


 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)


 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)


 at java.lang.reflect.Constructor.newInstance(Unknown Source)


 at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)


 at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)


 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)


 at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)


 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)


 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)


 at Sample.sample1.beforeTest(sample1.java:28)


 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)


 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)


 at java.lang.reflect.Method.invoke(Unknown Source)


 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)


 at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)


 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)


 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)


 at org.testng.TestRunner.beforeRun(TestRunner.java:641)


 at org.testng.TestRunner.run(TestRunner.java:609)


 at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)


 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)


 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)


 at org.testng.SuiteRunner.run(SuiteRunner.java:240)


 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)


 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)


 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)


 at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)


 at org.testng.TestNG.run(TestNG.java:1057)


 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)


 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)


 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8


Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'


System info: host: 'IN-IF-WS1-0154', ip: '192.168.10.162', os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_07'


Driver info: driver.version: FirefoxDriver


Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'


System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_13'


Driver info: driver.version: FirefoxDriver


 at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72)


 at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59)


 at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55)


 at org.openqa.selenium.firefox.FirefoxDriver.getBinary(FirefoxDriver.java:182)


 at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:107)


 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)


 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)


 at java.lang.reflect.Constructor.newInstance(Unknown Source)


 at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:62)


 at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:56)


 at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:216)


 at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)


 at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)


 at java.util.concurrent.FutureTask.run(Unknown Source)


 at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:170)


 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)


 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)


 at java.lang.Thread.run(Unknown Source)



SKIPPED CONFIGURATION: @AfterTest afterTest


SKIPPED: f



===============================================


 Default test


 Tests run: 1, Failures: 0, Skips: 1


 Configuration Failures: 1, Skips: 1


===============================================



===============================================


Default suite


Total tests run: 1, Failures: 0, Skips: 1


Configuration Failures: 1, Skips: 1


===============================================



[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@93b52b: 27 ms


[TestNG] Time taken by org.testng.reporters.jq.Main@3ba002: 22 ms


[TestNG] Time taken by org.testng.reporters.EmailableReporter2@fa930d: 6 ms


[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1f9c5c8: 6 ms


[TestNG] Time taken by org.testng.reporters.XMLReporter@197f158: 6 ms


[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms



时间: 原作者:

94 5

File pathToBinary = new File("C:userProgrammeFirefoxPortableAppFirefoxfirefox.exe");


FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);


FirefoxProfile firefoxProfile = new FirefoxProfile(); 


WebDriver driver = new FirefoxDriver(ffBinary,firefoxProfile);



原作者:
...