Home » Java » How to run headless browser automation script using HtmlUnitDriver thru SoapUI – Groovy script?

How to run headless browser automation script using HtmlUnitDriver thru SoapUI – Groovy script?

Posted by: admin October 29, 2018 Leave a comment

Questions:

I’m trying to execute headless browser script using the following Selenium script from SoapUI – Groovy script step.

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());
}

And it’s throwing the following error message in the SoapUI console.

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)

But the the same script is running perfectly normal browser automation i.e. if I remove the following line and added….

Added:

System.setProperty("webdriver.chrome.driver","D:\SoapUI-5.2.1\bin\ext\chromedriver.exe")
WebDriver driver = new ChromeDriver(); 

Removed:

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME);

I have placed the supporting JAR files in the SoapUI/bin/ext folder.

– selenium-server-standalone-3.4.0
– chromedriver 2.39
– selenium-htmlunit-driver-2.51.0

So, I have googled but no luck to solve my issue. Anyone help me to resolve it?

Thanks,
Karunagara Pandi

Answers: