除了 Safari 的测试之外,我可以通过所有这些测试。我怎样才能使 Safari WebDriver 测试通过?
测试:
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariDriver;
public class SeleniumSetupTest
{
@Test
public void testThatSeleniumIsCorrectlyConfiguredWithChrome()
{
WebDriver chromeDriver = new ChromeDriver();
testDriver(chromeDriver);
}
@Test
public void testThatSeleniumIsCorrectlyConfiguredWithFireFox()
{
WebDriver firefoxDriver = new FirefoxDriver();
testDriver(firefoxDriver);
}
@Test
public void testThatSeleniumIsCorrectlyConfiguredWithSafari()
{
WebDriver safariDriver = new SafariDriver();
testDriver(safariDriver);
}
private void testDriver(WebDriver webDriver)
{
webDriver.get("http://www.google.com");
String pageTitle = webDriver.getTitle();
assertThat(pageTitle, equalTo("Google"));
webDriver.quit();
}
}
Maven的输出:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.selenium.SeleniumSetupTest
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/jared/.m2/repository/org/slf4j/slf4j-log4j12/1.7.2/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/jared/.m2/repository/ch/qos/logback/logback-classic/1.0.12/logback-classic-1.0.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Starting ChromeDriver (v2.3) on port 2247
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Sep 10, 2013 10:16:23 AM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 33337
Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.583 sec <<< FAILURE!
testThatSeleniumIsCorrectlyConfiguredWithSafari(com.example.selenium.SeleniumSetupTest) Time elapsed: 0.09 sec <<< ERROR!
java.lang.NoSuchMethodError: com.google.common.io.Resources.asByteSource(Ljava/net/URL;)Lcom/google/common/io/ByteSource;
at org.openqa.selenium.safari.SafariExtensions.getExtensionResource(SafariExtensions.java:293)
at org.openqa.selenium.safari.SafariExtensions.install(SafariExtensions.java:217)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:83)
at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:115)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:101)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:85)
at com.example.selenium.SeleniumSetupTest.testThatSeleniumIsCorrectlyConfiguredWithSafari(SeleniumSetupTest.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
Results :
Tests in error:
testThatSeleniumIsCorrectlyConfiguredWithSafari(com.example.selenium.SeleniumSetupTest): com.google.common.io.Resources.asByteSource(Ljava/net/URL;)Lcom/google/common/io/ByteSource;
Tests run: 3, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------