【问题标题】:Running SoapUI test cases using testRunner使用 testRunner 运行 SoapUI 测试用例
【发布时间】:2013-08-14 11:03:24
【问题描述】:

我正在开发一个 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。请告诉我如何处理这个问题。

【问题讨论】:

  • 请有人给我解决这个问题的方法......
  • 你在哪里有全局脚本?当您说它不是从测试运行器运行时,您如何使用它?我对 SoapUI 测试运行程序和您所指的测试运行程序有点困惑。你能强调一下清除我的灰色区域吗?

标签: groovy soapui


【解决方案1】:

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

您应该将sample-soapui-project.xml 放置到/src/test/resources 文件夹中,以便将其公开给类路径

【讨论】:

【解决方案2】:

如果您想在外部代码中使用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

【讨论】:

    【解决方案3】:

    我不确定这是否会帮助那里的任何人,但这是我为解决工作空间为 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....' !")
    
    }
    

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

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多