SoapUI groovy脚本错误:没有此类属性:类的日志
我试图在soapui中用groovy编写模块化代码。 我创建了一个类示例,其中有一个方法hello(),该方法有一个log.info语句 我正在创建这个类的一个实例来调用函数hello。 在运行脚本时,我得到以下错误 groovy.lang.MissingPropertyException:没有此类属性:类的日志:例如 我需要帮助SoapUI groovy脚本错误:没有此类属性:类的日志,groovy,soapui,modularity,Groovy,Soapui,Modularity,我试图在soapui中用groovy编写模块化代码。 我创建了一个类示例,其中有一个方法hello(),该方法有一个log.info语句 我正在创建这个类的一个实例来调用函数hello。 在运行脚本时,我得到以下错误 groovy.lang.MissingPropertyException:没有此类属性:类的日志:例如 我需要帮助 class Example{ void hello(){ log.info ' >>>> Hello World';
class Example{
void hello(){
log.info ' >>>> Hello World';
}
}
Example example = new Example();
example.hello();
或者,您也可以移出log.info,继续这样做。事情
class Example{
String hello(){
return ' >>>> Hello World';
}
}
Example example = new Example();
log.info example.hello();
或者,您也可以移出log.info,继续这样做。事情
class Example{
String hello(){
return ' >>>> Hello World';
}
}
Example example = new Example();
log.info example.hello();
找到了解决办法。
给你。
1.需要将类放入上下文中。
2.需要将日志作为对象传递给函数
希望这能帮助其他寻求类似解决方案的人
class Example{
void hello(Object log){
log.info ' >>>> Hello World';
}
}
context = new Example();
context.hello(log);
找到了解决办法。
给你。
1.需要将类放入上下文中。
2.需要将日志作为对象传递给函数
希望这能帮助其他寻求类似解决方案的人
class Example{
void hello(Object log){
log.info ' >>>> Hello World';
}
}
context = new Example();
context.hello(log);
下面是一个完整脚本的示例。这里log对象是成员变量,并使用带有map的构造函数进行初始化。注意,这里的类也存在于脚本本身中。如果它是可重用的,则必须在每个脚本中复制它
class TestLogging {
def log
def sayHello(def name){
log.info "Hello $name"
}
}
def testLogging = new TestLogging(log:log)
testLogging.sayHello('Mr. ABC')
通常,当我编写一些groovy库类时,我使用以下方法来定义类、创建库和访问SOAPUI提供的变量,以及如何从脚本调用。这将显示类的可重用性-定义一次,在任何地方重用:
TestRunnerHelper.groovy——编译并创建一个jar文件,并将其放在SOAPUI_HOME/bin/ext目录下
类TestRunnerHelper{
定义上下文
def测试运行程序
def日志
def printTestDetails(){
log.info“测试用例的名称为:”+testRunner.testCase.Name
log.info“测试套件的名称为:”+testRunner.testCase.testSuite.Name
}
}
现在,使用上面的类在任何项目->测试套件->测试用例->Groovy脚本测试步骤中编写一个脚本
def testHelper = new TestRunnerHelper(context:context, log:log, testRunner:testRunner)
testHelper.printTestDetails()
注意:如果groovy类中有一些包名,那么它也应该在脚本中导入
我想通过第二个示例说明的是,您可以在自己喜欢的IDE中编写库类(我编写了groovy,但也可以使用java),并通过将soapui提供的变量上下文、日志、testRunner变量传递给您的类来利用它们。下面是一个完整脚本的示例。这里log对象是成员变量,并使用带有map的构造函数进行初始化。注意,这里的类也存在于脚本本身中。如果它是可重用的,则必须在每个脚本中复制它
class TestLogging {
def log
def sayHello(def name){
log.info "Hello $name"
}
}
def testLogging = new TestLogging(log:log)
testLogging.sayHello('Mr. ABC')
通常,当我编写一些groovy库类时,我使用以下方法来定义类、创建库和访问SOAPUI提供的变量,以及如何从脚本调用。这将显示类的可重用性-定义一次,在任何地方重用:
TestRunnerHelper.groovy——编译并创建一个jar文件,并将其放在SOAPUI_HOME/bin/ext目录下
类TestRunnerHelper{
定义上下文
def测试运行程序
def日志
def printTestDetails(){
log.info“测试用例的名称为:”+testRunner.testCase.Name
log.info“测试套件的名称为:”+testRunner.testCase.testSuite.Name
}
}
现在,使用上面的类在任何项目->测试套件->测试用例->Groovy脚本测试步骤中编写一个脚本
def testHelper = new TestRunnerHelper(context:context, log:log, testRunner:testRunner)
testHelper.printTestDetails()
注意:如果groovy类中有一些包名,那么它也应该在脚本中导入
我想通过第二个示例说明的是,您可以在自己喜欢的IDE中编写库类(我编写了groovy,但也可以使用java),并利用变量上下文、日志、,soapui提供的testRunner变量通过将它们传递给类来实现。以下是添加类内日志函数和从其他(外部)脚本调用此函数的解决方案 在SoapUI(TestLogging)中创建Groovy步骤并添加以下代码:
class TestLogging
{
def log;
def context;
def testRunner;
def sayHello()
{
log.info ("Hello ");
}
}
context.setProperty("testClass", new TestLogging(log:log,context:context,testRunner:testRunner));
添加另一个脚本并添加以下代码以添加TestLogging类的函数:
tSuite = testRunner.testCase.testSuite.project.testSuites["TestSuiteName"]
module = tSuite.testCases["TestCaseName"].testSteps["TestLogging"]
// initialise the tSuite; which places an instance of TestLogging in the context
module.run(testRunner, context)
// get the instance of TestLogging Class from the context.
def testClass= context.testClass
//call function
testClass.sayHello();
下面是添加类函数内部日志和从其他(外部)脚本调用此函数的解决方案 在SoapUI(TestLogging)中创建Groovy步骤并添加以下代码:
class TestLogging
{
def log;
def context;
def testRunner;
def sayHello()
{
log.info ("Hello ");
}
}
context.setProperty("testClass", new TestLogging(log:log,context:context,testRunner:testRunner));
添加另一个脚本并添加以下代码以添加TestLogging类的函数:
tSuite = testRunner.testCase.testSuite.project.testSuites["TestSuiteName"]
module = tSuite.testCases["TestCaseName"].testSteps["TestLogging"]
// initialise the tSuite; which places an instance of TestLogging in the context
module.run(testRunner, context)
// get the instance of TestLogging Class from the context.
def testClass= context.testClass
//call function
testClass.sayHello();
下面是一个简单直接的方法
Example.log = log;
Example.hello();
class Example{
def static log;
def static hello(){
log.info ("Hello World...");
}
}
在非静态方法的情况下。创建一个类引用并通过它调用函数。例如
Example ex = new Example;
ex.hello();
下面是一个简单直接的方法
Example.log = log;
Example.hello();
class Example{
def static log;
def static hello(){
log.info ("Hello World...");
}
}
在非静态方法的情况下。创建一个类引用并通过它调用函数。例如
Example ex = new Example;
ex.hello();
您需要使用类名定义
log
,并且应该在类内声明log
为static
,如下所示:
Example.log = log
class Example {
def static log
public void hello()
{
log.info ' >>>> Hello World';
}
}
Example example = new Example();
example.hello();
您需要使用类名定义
log
,并且应该在类内声明log
为static
,如下所示:
Example.log = log
class Example {
def static log
public void hello()
{
log.info ' >>>> Hello World';
}
}
Example example = new Example();
example.hello();
我需要弄清楚如何在函数中使用log.info。要求是我需要在函数中使用log.info。就像本例中的hello()函数一样。我需要弄清楚如何在函数中使用log.info。要求是在函数中使用log.info。与本例中的hello()函数类似。