单声道"Hello World"示例正常工作,但是Java不起作用 [英] Mono "Hello World" example working, but Java is not

查看:115
本文介绍了单声道"Hello World"示例正常工作,但是Java不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Java和C#Mono的Sauce Labs主页上运行入门示例.

I'm running the Getting Started Examples from the Sauce Labs homepage both with Java and C# Mono.

Mono示例的工作原理很吸引人,但是Java报道说

The Mono example works like a charm, but the Java one reports that

Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

我尝试重新编写Java示例,使其类似于Mono示例:

I've tried re-writing the Java example to be similar to the Mono example as such:

public class WebDriverTest {

    private WebDriver driver;

    @Before
    public void setUp() throws Exception {

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("version", "10");
        capabilities.setCapability("platform", Platform.LINUX);
        capabilities.setCapability("name", "Testing Selenium 2 with C# on Sauce");
        capabilities.setCapability("username", "banksysan");
        capabilities.setCapability("accessKey", "MY-APP-KEY");

        driver = new RemoteWebDriver(
                new URL("http://ondemand.saucelabs.com:80/wd/hub"), capabilities);
    }

    @Test
    public void webDriver() throws Exception {
        driver.get("http://www.amazon.com/");
        assertEquals("Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", driver.getTitle());
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

}

还有其他建议吗?

谢谢

更新

我已尝试按照下面的Ross所建议的那样按照教程中的描述运行,在此动词之后,Maven会退出并出现以下错误:

I've tried running as described in the tutorial as suggested by Ross below, following this verbatum causes Maven to exit with the following error:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project sauce-labs-tutorial: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]

我已经编辑了酱汁文件,只是添加了缺少的package声明,但是添加此声明根本没有任何区别.

I have edited the sauce files, just adding the package declaration which is missing, however adding this didn't make any difference at all.

更新2

完成Maven堆栈跟踪:

Complete Maven stack trace:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Forking command line: /bin/sh -c cd /home/david/Documents/development/sauceLabs/java/sauce-labs-tutorial && /usr/java/jdk1.7.0_11/jre/bin/java -jar /home/david/Documents/development/sauceLabs/java/sauce-labs-tutorial/target/surefire/surefirebooter5443687714708881867.jar /home/david/Documents/development/sauceLabs/java/sauce-labs-tutorial/target/surefire/surefire4108475136019888668tmp /home/david/Documents/development/sauceLabs/java/sauce-labs-tutorial/target/surefire/surefire_08561306448128018862tmp
Running TestSuite

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:16.389s
[INFO] Finished at: Wed Mar 13 20:17:58 GMT 2013
[INFO] Final Memory: 10M/213M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test (default-test) on project sauce-labs-tutorial: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test failed: There was an error in the forked process
[ERROR] java.lang.NullPointerException
[ERROR] at dave.WebDriverWithHelperTest.getSessionId(WebDriverWithHelperTest.java:78)
[ERROR] at com.saucelabs.testng.SauceOnDemandTestListener.markJobAsFailed(SauceOnDemandTestListener.java:103)
[ERROR] at com.saucelabs.testng.SauceOnDemandTestListener.onTestFailure(SauceOnDemandTestListener.java:97)
[ERROR] at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
[ERROR] at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
[ERROR] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1292)
[ERROR] at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
[ERROR] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
[ERROR] at org.testng.TestRunner.privateRun(TestRunner.java:767)
[ERROR] at org.testng.TestRunner.run(TestRunner.java:617)
[ERROR] at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
[ERROR] at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
[ERROR] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
[ERROR] at org.testng.SuiteRunner.run(SuiteRunner.java:240)
[ERROR] at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
[ERROR] at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
[ERROR] at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
[ERROR] at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
[ERROR] at org.testng.TestNG.run(TestNG.java:1031)
[ERROR] at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
[ERROR] at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:189)
[ERROR] at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:105)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:117)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:601)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test (default-test) on project sauce-labs-tutorial: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test failed: There was an error in the forked process
java.lang.NullPointerException
    at dave.WebDriverWithHelperTest.getSessionId(WebDriverWithHelperTest.java:78)
    at com.saucelabs.testng.SauceOnDemandTestListener.markJobAsFailed(SauceOnDemandTestListener.java:103)
    at com.saucelabs.testng.SauceOnDemandTestListener.onTestFailure(SauceOnDemandTestListener.java:97)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1292)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    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:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:189)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:105)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
    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:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test failed: There was an error in the forked process
java.lang.NullPointerException
    at dave.WebDriverWithHelperTest.getSessionId(WebDriverWithHelperTest.java:78)
    at com.saucelabs.testng.SauceOnDemandTestListener.markJobAsFailed(SauceOnDemandTestListener.java:103)
    at com.saucelabs.testng.SauceOnDemandTestListener.onTestFailure(SauceOnDemandTestListener.java:97)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1292)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    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:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:189)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:105)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.RuntimeException: There was an error in the forked process
java.lang.NullPointerException
    at dave.WebDriverWithHelperTest.getSessionId(WebDriverWithHelperTest.java:78)
    at com.saucelabs.testng.SauceOnDemandTestListener.markJobAsFailed(SauceOnDemandTestListener.java:103)
    at com.saucelabs.testng.SauceOnDemandTestListener.onTestFailure(SauceOnDemandTestListener.java:97)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1895)
    at org.testng.internal.Invoker.runTestListeners(Invoker.java:1879)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1292)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    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:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:189)
    at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:105)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:475)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:349)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:152)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:806)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:701)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:629)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    ... 20 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

在WWW上浏览,似乎已经发现surefire是可能的罪魁祸首.我已经在POM中升级了版本,但是问题仍然存在.

Browsong the WWW it looks like surefire has been spotted as a possible culprit. I've upgraded the version in the POM but the problem still persists.

推荐答案

是否可以尝试使用以下代码创建RemoteWebDriver实例:

Can you try create the RemoteWebDriver instance using the following code:

 driver = new RemoteWebDriver(
            new URL("http://banksysan:MY-APP-KEY@ondemand.saucelabs.com:80/wd/hub"), capabilities);

我们还创建了一个更多深入的教程,其中介绍了将Java测试与Sauce Labs配合使用的方法.可能也有帮助.

We've also created a more in-depth tutorial on getting Java tests to work with Sauce Labs, which might help too.

更新:生成的潜在错误是

Update: The underlying error that was generated was

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-25-generic', java.version: '1.7.0_11'
Driver info: driver.version: RemoteWebDriver

这又是由于代理服务器阻止了对ondemand.saucelabs.com的出站请求.

which in turn was due to a proxy server that was blocking the outbound request to ondemand.saucelabs.com.

通过指定Java系统属性包括代理信息解决了该问题,例如.

Including the proxy information by specifying Java system properties resolved the issue, eg.

System.setProperty("http.proxyHost", proxyHost);            
System.setProperty("http.proxyPort", proxyPort)            
System.setProperty("http.proxyUser", userName);            
System.setProperty("http.proxyPassword", password);

这篇关于单声道"Hello World"示例正常工作,但是Java不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆