Forum Discussion

Dheepha's avatar
Dheepha
Contributor
11 years ago

Groovy script to call multiple java class/code in selenium

Hi,
I would like to know from groovy test script how do i call multiple java classes/codes.

I'm integrating SOAPUI with selenium via groovy and I achieved it just by placing the Selenium Standalone server in eviware/bin/ext folder.

1. I have written a code in java - selenium and executed using selenium Test NG in eclipse
2. Added the java code(converted into groovy) and placed in soapui and executed. It worked as expected.
3. Now I have written multiple java codes in eclipse and called all java classes in main java class in eclipse and executed that as well.
4. But how do i do the same step using groovy.

Following is the groovy snippet to login to a website:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

WebDriver driver = new FirefoxDriver()
driver.get("http://....");
driver.findElement(By.name("username")).sendKeys("xxx");
driver.findElement(By.name("password")).sendKeys("yyy");
driver.findElement(By.name("go")).click();
driver.quit();

Now say eg: if i write the login script is Test1.java and Customer Search in Test2.java
I'm calling Tes1.java and Test2.java in MainTest.java using eclipse and it worked perfect

Similarly, how do i call multiple java codes in main groovy class.

Thanks,
Dheepha V
  • Hi,

    I'm pretty confused to do the following, as per the link stated above.
    -SoapUI is a java project, it must be in some .jars somewhere, hopefully in just one.
    -Import that into your Groovy (Java) project.
    -Then you should be able to call appropriate functions from your code.

    What I should do after converting the java package to jar file and place in it in sopui- eviware/bin/ext folder.

    What would be the groovy script to call the main java.class file.

    Regards,
    Dheepha B
  • SiKing's avatar
    SiKing
    Community Expert
    Dheepha wrote:
    I'm pretty confused to do the following, as per the link stated above.
    -SoapUI is a java project, it must be in some .jars somewhere, hopefully in just one.

    Yes, see $SOAPUI_HOME/bin/*.jar and $SOAPUI_HOME/lib/*.jar.
    Dheepha wrote:
    -Import that into your Groovy (Java) project.
    -Then you should be able to call appropriate functions from your code.

    Yes, some additional information is here: http://www.soapui.org/Developers-Corner ... oapui.html and here: http://www.soapui.org/apidocs/index.html