header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
December 05, 2008, 12:50:42 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
Trouble getting access to context, log, and testRunner variables
Welcome, Guest. Please login or register.
December 05, 2008, 12:50:42 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  Trouble getting access to context, log, and testRunner variables
« previous next »
Pages: [1] Print
Author Topic: Trouble getting access to context, log, and testRunner variables  (Read 377 times)
Steven Smith
Newbie
*
Posts: 3


« on: December 20, 2007, 05:57:47 pm »

I am currently using version 1.7.6 on OS X (non-pro version).  I am writing a groovy script and attempting to access any of the log, context or testRunner variables and continue to receive the following error:

Thu Dec 20 11:53:52 EST 2007:ERROR:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script17.groovy: 23: the name testRunner doesn't refer to a declared variable or class. The static scope requires to declare variables before using them. If the variable should have been a class check the spelling.
 @ line 23, column 26.org.codehaus.groovy.syntax.SyntaxException: the name testRunner doesn't refer to a declared variable or class. The static scope requires to declare variables before using them. If the variable should have been a class check the spelling.
 @ line 23, column 26.
   at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:86)
   at org.codehaus.groovy.control.ResolveVisitor.transformVariableExpression(ResolveVisitor.java:670)
   at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:538)
   at org.codehaus.groovy.control.ResolveVisitor.transformMethodCallExpression(ResolveVisitor.java:728)
   at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:546)
   at org.codehaus.groovy.control.ResolveVisitor.transformMethodCallExpression(ResolveVisitor.java:728)
   at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:546)
   at org.codehaus.groovy.control.ResolveVisitor.transformDeclarationExpression(ResolveVisitor.java:747)
   at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:542)
   at org.codehaus.groovy.control.ResolveVisitor.visitExpressionStatement(ResolveVisitor.java:839)
   at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:70)
   at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:83)
   at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:102)
   at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:845)
   at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:82)
   at org.codehaus.groovy.ast.CodeVisitorSupport.visitTryCatchFinally(CodeVisitorSupport.java:122)
   at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitTryCatchFinally(ClassCodeVisitorSupport.java:167)
   at org.codehaus.groovy.ast.stmt.TryCatchStatement.visit(TryCatchStatement.java:72)
   at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:83)
   at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:102)
   at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:845)
   at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:82)
   at org.codehaus.groovy.control.ResolveVisitor.visitMethod(ResolveVisitor.java:181)
   at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:838)
   at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:36)
   at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:787)
   at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:128)
   at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:595)
   at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:833)
   at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:480)
   at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:306)
   at groovy.lang.GroovyShell.parseClass(GroovyShell.java:513)
   at groovy.lang.GroovyShell.parse(GroovyShell.java:525)
   at groovy.lang.GroovyShell.parse(GroovyShell.java:505)
   at groovy.lang.GroovyShell.parse(GroovyShell.java:544)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:81)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:52)
   at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:140)
   at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction.actionPerformed(GroovyScriptStepDesktopPanel.java:226)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
   at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
   at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
   at java.awt.Component.processMouseEvent(Component.java:5602)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
   at java.awt.Component.processEvent(Component.java:5367)
   at java.awt.Container.processEvent(Container.java:2010)
   at java.awt.Component.dispatchEventImpl(Component.java:4068)
   at java.awt.Container.dispatchEventImpl(Container.java:2068)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
   at java.awt.Container.dispatchEventImpl(Container.java:2054)
   at java.awt.Window.dispatchEventImpl(Window.java:1791)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

1 error


Please tell me what I am doing wrong.

Logged
Steven Smith
Newbie
*
Posts: 3


« Reply #1 on: December 20, 2007, 06:00:18 pm »

Forgot to include the script

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;
public class JDBCExample1 {
  public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try{
      Class.forName("oracle.jdbc.OracleDriver");
      con = DriverManager.getConnection("jdbc:oracle:thin:@someserver:1526:service",
           "username", "password");
      stmt = con.createStatement();
      rs = stmt.executeQuery("select * from table where field like('somevalue%')");
      while (rs.next()) {
        SoapUI.log("user id: " + rs.getLong(1) + " username: " + rs.getString(2));
      }
      //print out properties
      def propertyStep = testRunner.getTestCase().getTestStepByName("UserProperties");
      SoapUI.log("baseName = " + propertyStep.getPropertyValue("baseName"));
      //SoapUI.log("testing " + testRunner.testCase.name);
      //SoapUI.log("baseName = " + context.getProperty("UserProperties", "baseName"));
    }catch(SQLException e){
      e.printStackTrace();
    }catch(ClassNotFoundException e){
      e.printStackTrace();
    }finally{
      try{rs.close();}catch(Exception e){}
      try{stmt.close();}catch(Exception e){}
      try{con.close();}catch(Exception e){}
   }
  }
}
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,506


« Reply #2 on: December 20, 2007, 09:07:14 pm »

Hi Steven,

thanks for your post.. I don't think you should wrap the script in a class / main method.. try just
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;

    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    try{
      Class.forName("oracle.jdbc.OracleDriver");
      con = DriverManager.getConnection("jdbc:oracle:thin:@someserver:1526:service",
           "username", "password");
      stmt = con.createStatement();
      rs = stmt.executeQuery("select * from table where field like('somevalue%')");
      while (rs.next()) {
        SoapUI.log("user id: " + rs.getLong(1) + " username: " + rs.getString(2));
      }
      //print out properties
      def propertyStep = testRunner.getTestCase().getTestStepByName("UserProperties");
      SoapUI.log("baseName = " + propertyStep.getPropertyValue("baseName"));
      //SoapUI.log("testing " + testRunner.testCase.name);
      //SoapUI.log("baseName = " + context.getProperty("UserProperties", "baseName"));
    }catch(SQLException e){
      e.printStackTrace();
    }catch(ClassNotFoundException e){
      e.printStackTrace();
    }finally{
      try{rs.close();}catch(Exception e){}
      try{stmt.close();}catch(Exception e){}
      try{con.close();}catch(Exception e){}
   }

Hope this helps!

regards,

/Ole
eviware.com
Logged
Steven Smith
Newbie
*
Posts: 3


« Reply #3 on: December 21, 2007, 03:22:31 pm »

Thanks for the quick response.  I realized that just before I saw this post.  Not being familiar with Groovy, I found an example on the web and just did a copy paste.  Didn't even realize I had a class declaration until I was comparing with some example code that did run.

Thanks!!
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header