How to pass parameter from one project to another project?

后端 未结 1 1152
感情败类
感情败类 2021-01-14 23:56

I am having 4 Rest API’s Projects as of attached screen shot.

I Need to pass a generated userID from project 1 (1_Admin Basics & Get APIs) to other project (2_Co

相关标签:
1条回答
  • 2021-01-15 00:10

    You can do it for example using the workspace property to access the other projects from the current one to get the properties from its. You can do it through a groovy script.

    In the first project add a groovy script testStep in your testCase and set the property at project level as follows:

    testRunner.testCase.testSuite.project.setPropertyValue('myProp','myValue')
    

    In the second project add another groovy script in the testCase to get the value of your property through the workspace and assign at your desired level (for example in a testSuite, but you can add wherever you need it):

    // get the other project
    def otherProject = testRunner.testCase.testSuite.project.workspace.getProjectByName('SecondProjectName')
    // get your property value
    def value = otherProject.getPropertyValue('myProp')
    log.info value
    // set the var at some level in this case in testSuite
    testRunner.testCase.testSuite.setPropertyValue('varFromOtherProject',value)
    

    Then use the variable in the testStep of your second project using the follow notation:

    ${#TestSuite#varFromOtherProject}

    UPDATE:

    Seems that you're running your projects alone using testRunner therefore you can't access other projects using workspace, so as a possible workaround you can write your property value in a File in your first project and then read the File content in your second project.

    So in your first project add a groovy script testStep with the follow code:

    new File('./myProp').text = 'someValue'
    

    Then in your second project read the File and set the property at some test level:

    // get the value from the file
    def value = new File('./myProp').text
    log.info value
    // set the var at some level in this case in testSuite
    testRunner.testCase.testSuite.setPropertyValue('varFromOtherProject',value)
    

    And as it's explained before use the follow notation in your SOAP testStep to get the property:

    ${#TestSuite#varFromOtherProject}

    Hope it helps,

    0 讨论(0)
提交回复
热议问题