2012-12-18 39 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") 
]) 

在你的腳本的頂部把上述這些線路。

然後放入導入語句,這些語句將使用將首先下載到您的系統並存儲在緩存中以供下次檢索的庫。

現在運行您的腳本。首次運行腳本時,編譯時需要一些時間,因爲它會將庫下載到系統並存儲在緩存中。 但從第二次開始,它不會花費太多時間。