2015-09-11 46 views
1

对不起。我相信这不是一个新问题,但我发誓我一直在寻找几天,并尝试了几种解决方案,但没有人符合我的需要。我希望你们能帮助我...SoapUI&Groovy - 如何使用Run testCase从不同的TestCase获取属性

我的问题:

  1. 我有它发送的bash命令我们的服务器主脚本:
TestSuite: Tools; 
    TestCase: sendBashCommands; 
     TestStep: groovycript; 
  • 这个测试脚本是由几个测试用例使用“运行testCase”调用的。每个测试用例有不同的bash命令:
  • TestSuite: ServerInfo 
        TestCase: getServerVersion 
         Property: BashCommand="cat smt | grep Version" 
         TestStep: Run sendBashCommands 
    
        TestCase: getServerMessage 
         Property: BashCommand="cat smt | grep Message" 
         TestStep: Run sendBashCommands 
        ... 
    

    在我sendBashCommands .groovyScript我已经试过如下:

    //def bashCmd= context.expand('${#BashCommand}'); 
        //it returns empty; 
    //def bashCmd= testRunner.testCase.getPropertyValue("BashCommand"); 
        //it returns null; 
    //def bashCmd= context.getTestCase().getPropertyValue("BashCommand"); 
        //it returns null; 
    def bashCmd = context.expand('${#TestCase#BashCommand}'); 
        //it also returns empty; 
    

    目前我使用的有效的解决方案与项目属性,但我真正需要的是与这些属性在测试用例的级别上调用sendBa sh命令脚本。那可能吗?我怎么能这样做?

    回答

    0

    我认为你是在做维护的目的...... 根据你的方法,结果必须为空或空。因为你的groovyscript不能直接获得其他测试用例的属性。如果直接调用getProperty()方法,那么它将引用当前的testStep属性。所以下面的方法可以帮助你。

    把下面的代码在您的测试情况下, “getServerVersion” 等

    def currentProject = testRunner.testCase.testSuite.project 
    // the following is to store the names of the test suite and the test cases from which you want to call your main script 
    
    currentProject.setPropertyValue("TestSuiteName",testRunner.testCase.getTestSuite().getLabel().toString()) 
    currentProject.setPropertyValue("TestCaseName", testRunner.getTestCase().getLabel().toString()) 
    // call sendBashCommands here -> run sendBashCommands 
    

    把这个代码在主Groovy脚本(sendBashCommands.groovyscript)

    def currentProject = testRunner.testCase.testSuite.project 
    def callingTestCase = currentProject.testSuites[currentProject.getPropertyValue("TestSuiteName")].testCases[currentProject.getPropertyValue("TestCaseName")] 
    def bashCmd = callingTestCase.getPropertyValue("BashCommand") 
    // to verify 
    log.info bashCmd 
    

    该项目是常见到所有的测试套件,所以你必须在任何情况下使用项目属性,即为您的要求:) 享受:)

    +0

    正是我所需要的!非常感谢! – cin2e

    +0

    欢迎! :) :) –