1

我正在开发一个 SoapUI 项目,我需要使用测试运行程序运行我的测试套件。我正在为环境变量使用外部 groovy 脚本。我在这里面临的问题是,每当我从测试运行器运行测试用例时,它的返回 Workspace 为 null,在 External groovy 中使用。因此,在外部 groovy 中,我将工作空间设为 null 导致错误 [getProjectByname() 无法在 null 上调用]。下面是

使用工作空间的全局脚本的构造函数

    AvengerAPITestManager(String TestProject, String TestSuite, String TestCase,String TestStep)              
    {
        TestName = "AvengerAPITests";
        testProject = SoapUI.getWorkspace().getProjectByName(TestProject);
        tSuite = testProject.getTestSuiteByName(TestSuite);
        tCase = testProject.getTestSuiteByName(TestSuite).getTestCaseByName(TestCase);
        tStepName = TestStep.toString();
        tStep=testProject.getTestSuiteByName(TestSuite).getTestCaseByName(TestCase).getTestStepByName (TestStep);                  
    }

上面我们有用户 SoapUI.getWorkspace() 在尝试从 soapUI 运行时工作正常,但是无论我试图从 testrunner SoapUI.getWorkspace 运行时都为空。我什至尝试像传递测试项目名称一样传递工作区,但它仍然没有用。

我也尝试过这样的事情

   AvengerAPITestManager(Object workspace,String TestProject, String TestSuite, String                  TestCase, String TestStep) 
   {
        TestName = "AvengerAPITests";
        testProject = workspace.getProjectByName(TestProject);
        tSuite = testProject.getTestSuiteByName(TestSuite);
        tCase = testProject.getTestSuiteByName(TestSuite).getTestCaseByName(TestCase);
        tStepName = TestStep.toString();
        tStep = testProject.getTestSuiteByName(TestSuite).getTestCaseByName(TestCase).getTestStepByName(TestStep);
   }

在上面的代码中,我尝试在传递测试用例名称时从测试用例中传递 Workspace 对象,但我仍然为工作区获取 null。请告诉我如何处理这个问题。

4

3 回答 3

1

这是有用的工作示例https://github.com/stokito/soapui-junit

您应该放置将其公开给类路径的sample-soapui-project.xmlto文件夹/src/test/resources

于 2013-12-30T09:51:25.030 回答
0

如果您想在外部代码中使用soap ui,请尝试使用特定项目文件直接创建新的测试运行器:

SoapUITestCaseRunner runner = new SoapUITestCaseRunner(); 
runner.setProjectFile( "src/dist/sample-soapui-project.xml" );
runner.run();

或者如果你想更精确地定义测试执行,你可以使用这样的东西:

WsdlProject project = new WsdlProject( "src/dist/sample-soapui-project.xml" ); 
TestSuite testSuite = project.getTestSuiteByName( "Test Suite" ); 
TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" );

// create empty properties and run synchronously
TestRunner runner = testCase.run( new PropertiesMap(), false ); 

PS:不要忘记导入您在代码中使用的soap ui类并将它们放到类路径中。

PPS:如果你只需要在soap ui 之外运行测试用例和/或自动化这个过程,为什么不直接使用testrunner.sh/.bat 来做同样的事情呢?(这里是这种方式的描述:http: //www.soapui.org/Test-Automation/functional-tests.html

于 2013-08-15T05:58:54.897 回答
0

我不确定这是否会帮助那里的任何人,但这是我为解决工作空间为 null 导致错误[getProjectByname() 无法在 null 上调用] 时遇到的问题所做的工作,当我从 cmd 运行时,试试这个:

import com.eviware.soapui.model.project.ProjectFactoryRegistry  

import com.eviware.soapui.impl.wsdl.WsdlProjectFactory    

import com.eviware.soapui.impl.wsdl.WsdlProject    

//get the Util project 

def project = null     
def workspace = testRunner.testCase.testSuite.project.getWorkspace();

//if running Soapui

if (workspace != null) {

 project = workspace.getProjectByName("Your Project")

}

//if running in Jenkins/Hudson

else{

 project = new WsdlProject("C:\\...\\....\\....\\-soapui-project.xml");

}

if (project.open && project.name == "Your Project") {

 def properties = new com.eviware.soapui.support.types.StringToObjectMap()    
 def testCase = project.getTestSuiteByName("TestSuite 1").getTestCaseByName("TestCase");    
 if(testCase == null)

 {    

  throw new RuntimeException("Could not locate testcase 'TestCase'! ");

 } else {

// This will run everything in the selected project   
  runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

 }


} 
else {

 throw new RuntimeException("Could not find project ' Order Id....' !")

}

上面的代码将运行所选项目中的所有内容。

于 2018-03-28T17:16:00.470 回答