Forum Discussion

mdvijay's avatar
mdvijay
New Contributor
15 years ago

Groovy Script - Junit+selenium

Hi all,
I using Junit framework in the groovy script to run my selenium test.
before starting the test in selenium, i have to use some details from my xml response (previous test step of my test suite is xml request).

Below is my code for the reference:-
import junit.framework.*;
import com.thoughtworks.selenium.*;
import junit.textui.TestRunner;
import java.util.*;
import com.eviware.soapui.support.*;


public class Temp extends TestCase
{
    private Selenium selenium;   
    public Temp(String name)
    {
      super(name);
    } 
    public void setUp()
    {
        //some code
        selenium = new DefaultSelenium( "localhost",4444, "*firefox","www.google.com");       
        selenium.start();
        selenium.setSpeed("2000");       
    } 
    public static TestSuite suite()
    {
      return new TestSuite(Temp.class);
    }
    public String GetEmailID()
    {
    try
    {
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
//Extract data from the SOAP request
def HolderResquest = groovyUtils.getXmlHolder( "InsertArticle#Request" );
String sUserName = HolderResquest["//web:InsertArticle/web:Request/User/Name"] ;
SoapUI.log.error (sUserName) ;
return sUserName; 
    }
    catch (Exception e)
    {
    SoapUI.log.error (e);
    } 
    } 
    public void test1()
    {
        try
        {
        String New;
        SoapUI.log.error ("test Started")        ;
        selenium.open("/");
        selenium.windowFocus();
          selenium.windowMaximize();
selenium.click("link=search");
selenium.waitForPageToLoad("30000");
        New = GetEmailID();
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isElementPresent("ctl00_ctl00_decoratedArea_loginStatus_linkLogout"));
        }
        catch (Exception e)
        {
        SoapUI.log.error( "TestCase [" + e );     
        }
}
    public void tearDown()
    {
        // some code
        //selenium.stop();       
    } 
}

Temp test = new Temp("test1");
TestRunner a = new TestRunner();
TestResult result = a.run(test.suite());

Please have look into the GetEmailID function,  this function is not returning the value.

Thank you very much for your time

Kind regards
Vijay
No RepliesBe the first to reply