2012-12-18 35 views
1

我正在使用下面的代码。如何解决,导入包时无法解析类?

import org.openqa.selenium.By 
import org.openqa.selenium.WebDriver 
import org.openqa.selenium.WebElement 
import org.openqa.selenium.firefox.FirefoxDriver 
import org.openqa.selenium.support.ui.ExpectedCondition 
import org.openqa.selenium.support.ui.WebDriverWait 

WebDriver driver = new FirefoxDriver() 
driver.get("http://www.google.com") 

但它返回..

23:08:25,789 ERROR [SoapUI] An error occured [No match found], see error log for details 
23:08:25,791 ERROR [SoapUI] An error occured [startup failed: 
Script2.groovy: 1: unable to resolve class org.openqa.selenium.By 
@ line 1, column 1. 
    import org.openqa.selenium.By 
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class org.openqa.selenium.By 
@ line 1, column 1. 
     at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148) 
     at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1240) 
     at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148) 
     at org.codehaus.groovy.control.CompilationUnit$8.call(CompilationUnit.java:601) 
     at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839) 
     at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544) 
     at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:493) 
     at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306) 
     at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287) 
     at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731) 
     at groovy.lang.GroovyShell.parse(GroovyShell.java:743) 
     at groovy.lang.GroovyShell.parse(GroovyShell.java:770) 
     at groovy.lang.GroovyShell.parse(GroovyShell.java:761) 
     at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148) 
     at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93) 
     at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89) 
     at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149) 
     at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 
+0

你对java.exe的调用看起来像什么?看起来你可能错过了Java classpath中的Selenium类。 –

+0

如何添加? – ChanGan

+0

我在一段时间内没有使用硒,而且我对Groovy不熟悉(它看起来像你正在使用)。我知道Groovy是建立在Java上的,并且您将需要将Selenium JAR文件添加到Java类路径中,以便使用任何Selenium函数。此链接可能有所帮助:http://groovy.codehaus.org/Running(标题为“向类路径添加内容”一节) –

回答

0

看来,你缺少的库。要添加这些:

@Grapes([ 
     @Grab("org.codehaus.geb:geb-core:0.7.2"), 
     @Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.42.2"), 
     @Grab("org.seleniumhq.selenium:selenium-support:2.42.2") 
]) 

在你的脚本的顶部把上述这些线路。

然后放入导入语句,这些语句将使用将首先下载到您的系统并存储在缓存中以供下次检索的库。

现在运行您的脚本。首次运行脚本时,编译时需要一些时间,因为它会将库下载到系统并存储在缓存中。 但从第二次开始,它不会花费太多时间。