如何将参数从一个项目传递到另一个项目? [英] How to pass parameter from one project to another project?

查看:151
本文介绍了如何将参数从一个项目传递到另一个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要将项目1(1_Admin Basics& Get APIs)中生成的用户标识传递给附加屏幕截图。其他项目(2_Courses& Classes)。

我正在使用测试运行器运行每个项目。全球房地产转让不适用于这种情况。可以帮助我做出上述情况。



我不想将4个项目合并到1个项目中。它应该是4个项目,并且需要将参数从1个项目传递到其他项目。

解决方案

您可以使用 workspace 属性来访问当前的其他项目以从其中获取属性。您可以通过 groovy脚本来完成。



在第一个项目中,在您的 testCase 中添加一个 groovy脚本testStep ,并将该属性设置为项目级别,如下所示:

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

在第二个项目中,在 testCase中添加另一个 groovy脚本 通过工作区获取属性的值,然后在所需的级别进行赋值(例如在 testSuite 中),但可以添加你需要的任何地方):

  //获取另一个项目
def otherProject = testRunner.testCase.testSuite。 project.workspace.getProjectByName('SecondProjectName')
//获取属性值
def value = otherProject.getPropertyValue('myProp')
log.info value
// set testSuite
testRunner.testCase.testSuite.setPropertyValue('varFromOtherProject',value)

然后使用以下符号在第二个项目的 testStep 中使用变量:



$ {#TestSuite#varFromOtherProject}



似乎您只是使用 testRunner 运行项目,因此您无法使用<$ c $来访问其他项目c> workspace ,因此作为一种可能的解决方法,您可以在第一个项目的文件中编写属性值,然后读取文件中的内容你的第二个项目。



因此,在您的第一个项目中,使用以下代码添加一个 groovy脚本testStep

 新档案('./ myProp')。text ='someValue'

然后在您的第二个项目中阅读文件并在某个测试级别设置属性:

  //从文件
获取值def value = new File('./ myProp')。text
log.info value
//在这种情况下,在testSuite中设置var在某个级别
testRunner.testCase.testSuite.setPropertyValue('varFromOtherProject',value)

正如在你的 SOAP testStep 中使用后面的符号来解释属性一样:



$ {#TestSuite#varFromOtherProject}



希望它有帮助,


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_Courses & Classes).

I am running each project by using test runner. Global property transfer is not working in this scenario. Can some 1 help me out to do the above mentioned scenario.

I don’t want to combine 4 projects into 1 project. It should be 4 projects and need to pass the parameter from 1 project to other.

解决方案

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,

这篇关于如何将参数从一个项目传递到另一个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆