我尝试使用以下来自 SoapUI - Groovy 脚本步骤的 Selenium 脚本执行无头浏览器脚本。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import com.gargoylesoftware.htmlunit.BrowserVersion;
loginApp()
public void loginApp()
{
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME);
driver.setJavascriptEnabled(true);
driver.get("MyURL")
driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);
driver.findElement(By.id("username")).sendKeys("1234567");
driver.findElement(By.id("password")).sendKeys("1234567");
driver.findElement(By.id("submit")).submit();
driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);
log.info("Page title is: " + driver.getTitle());
}
它在SoapUI控制台中抛出以下错误消息。
Mon May 21 17:46:32 IST 2018:ERROR:groovy.lang.MissingPropertyException: No such property: CHROME for class: com.gargoylesoftware.htmlunit.BrowserVersion
groovy.lang.MissingPropertyException: No such property: CHROME for class: com.gargoylesoftware.htmlunit.BrowserVersion
at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:900)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1678)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1654)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3407)
at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at Script8.loginApp(Script8.groovy:12)
at Script8.run(Script8.groovy:8)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
但是相同的脚本运行完全正常的浏览器自动化,即如果我删除以下行并添加....
加了:
System.setProperty("webdriver.chrome.driver","D:\\SoapUI-5.2.1\\bin\\ext\\chromedriver.exe")
WebDriver driver = new ChromeDriver();
移除:
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME);
我已将支持的JAR文件放在 SoapUI / bin / ext 文件夹中。
- selenium-server-standalone-3.4.0
- chromedriver 2.39
- selenium-htmlunit-driver-2.51.0
所以,我用Google搜索但没有运气来解决我的问题。有人帮我解决了吗?
谢谢,
Karunagara Pandi