Forum Discussion

soapUserNewbie's avatar
soapUserNewbie
New Contributor
6 years ago

How to call a test step from another project that reads into a property step within that project

I have two projects. ProjectA(TestStepA ) has a step that calls ProjectB's step (TestStepB ).

 

ProjectB's step (TestStepB ) reads into a property step (TestStepBProperty) which is within ProjectB.

 

The problem is, ProjectB's step (TestStepB ) cannot read the property step (TestStepBProperty) eventhough it is in the same project.

 

But, if I am executing TestStepB standalone, it was able to read the property in TestStepBProperty.

 

 

ProjectA

    - TestSuiteA

        - TestCaseA

             -TestStepA (calls TestStepB in ProjectB)

 

 

ProjectB

    - TestSuiteB

        - TestCaseB

             -TestStepBProperty

             -TestStepB(reads TestStepBProperty)

 

 

Hope you can help me with this.

3 Replies

  • richie's avatar
    richie
    Community Hero

    Hi,

     

    i didn't even know you could call a test step from another project!  What is the mechanism you're using to achieve this?

     

    Can you provide a little more detail in regards to the test steps you are actually using within your testsuite/testcase hierarchies?

     

    I know there's a 'Run TestCase' test step (I stumbled across this last week) which allows you to call a different test case from perhaps a different test suite within the same project - but not a different project?

     

    I should highlight that it's best practice to have as little inter-testcase/suite dependencies as possible.

     

    Is there a reason you don't just copy the whole ProjectB test case you are calling into the ProjectA project?

     

    Cheers,

     

    richie

    • soapUserNewbie's avatar
      soapUserNewbie
      New Contributor

      Hi Richie,

       

      In ProjectA's groovy script, I used this codes

       

          def workspace   = testRunner.testCase.testSuite.project.getWorkspace();
          def ProjB   = workspace.getProjectByName(ProjectNameB)   
          def SuitesB = ProjB.getTestSuiteByName(TestSuiteNameB)
          def CaseB  = SuitesB.getTestCaseByName(TestCaseNameB)
          def Step1  = CaseB.getTestStepByName(TestStepNameB)
          Step1.run(testRunner,context) 

       

      where ProjectNameB,TestSuiteNameB,TestCaseNameB and TestStepNameB are all in ProjectB.

       

      To add more information for what steps  have used,

       

      ProjectA

          - TestSuiteA

              - TestCaseA

                   -TestStepA (is a groovy script that calls TestStepB in ProjectB)

       

       

      ProjectB

          - TestSuiteB

              - TestCaseB

                   -TestStepBProperty is a Property Step

                   -TestStepB(is HTTP request step which reads a property in TestStepBProperty using "${Property in  

                    TestStepBProperty}")

       

      It is not possible to copy ProjectB to ProjectA because ProjectA is just a Project runner, which can also run other projects.

       

      Thank you for spending time with my question.

      • richie's avatar
        richie
        Community Hero

        Hi,

         

        well I know why it's not working but unsure how to resolve.

         

        there is a checkbox on the testcase properties 'Search preceding steps for Property Values' which if I understand correctly means that any step that calls a property from a properties step will search all the preceding steps in the test to do this.

         

        The reason why your test case works when you run it independantly is the property is 'in session' (for lack of a better phrase).  So if you run the TestCaseB once and the property is passed to the HTTP Request that uses the property.  Furthermore after running the test once, because the property is still 'in session'  (there's got to be a better phrase cos this isn't a genuine session but I'm struggling) - you could just run the HTTP step again and it would still work.

         

        When you try and TestCaseA which calls the HTTP Request in TestCaseB, the property isn't 'in session'.

         

        I don't know if this would work or not - but if TestCaseA is calling the HTTP Request in TestCaseB - could you not alter the groovy to actually call the TestCaseB's Properties step first and then subsequently call TestCaseB's HTTP Request?

         

        As I say - unsure if this would work - but I'd give it a shot to see what happens,

         

        cheers,

         

        richie