Forum Discussion

Marathiboy's avatar
Marathiboy
New Contributor
6 years ago

raeadyapi cli issue

Hello,

 

i am new to readyapi. We have 2 seperate projects, one for read and other for write. Write project generates properties via groovy script and read project uses the same properties using groovy script to copy properties from write project.

 

In GUI everything works great.

 

I need to use CLI/jenkins to run first write and then read project. How I can achieve this? Is there a CLI interface to invoke groovy which will able to load/copy properties from other project?

 

 Thanks

 

M

7 Replies

  • I used to have two projects that would run within a single execution in Jenkins. Both projects would share an excel spreadsheet. When the first project would run it would log information into the spreadsheet that would then be used by the second project. In order to run them both from a single Jenkins job I added this code as the teardown script at the Suite Level of the first project. And what it does is run the second project within the same workspace. It's not the easiest solution but it did work.

     

    import com.eviware.soapui.impl.wsdl.WsdlProject
    def project = null
    projectPath=context.expand('${projectDir}')
    def workspace = testSuite.project.getWorkspace();
    try{
    if(workspace != null){
    project = workspace.getProjectByName("Project2")
    project = new WsdlProject(projectPath+"/Project2-soapui-project.xml");
    }
    //if running in Jenkins/Hudson
    else{
    project = new WsdlProject(projectPath+"/Project2-soapui-project.xml");
    }
    }
    catch(Exception e)
    {
    log.error("Service Exception desc : " + e.getMessage());
    }

    try{
    if(project.open && project.name == "Project2" ) {
    def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
    def testCase = project.getTestSuiteByName("Project2_TestSuite").getTestCaseByName("Project2Case");
    if(testCase == null)
    {
    throw new RuntimeException("Could not locate testcase 'Project2Case'! ");
    }
    else{

    testCase.setPropertyValue("projectPath_1", projectPath )
    def runner = testCase.run(properties, false);
    }
    }
    else{
    throw new RuntimeException("Could not find project 'Project2' !")
    }
    }
    catch(Exception e)
    {
    log.error("Service Exception desc : " + e.getMessage());

    }

    project = null

    • Marathiboy's avatar
      Marathiboy
      New Contributor

      Thank you all for response,

       

      What I was thinking is,

       

      if I could export properties to file from my write project and import them back into my read project (from prop file created earlier)

       

      Is there any readyapi api (cli) or groovy snipet to do this import/export? I can dump properties as cvs key/value easily, but is there a better and easier file format to import these properties?

       

      Thanks

       

      M

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Hi,

     

    I do also use a project setup script that will import properties from a file (called YYYYY.properties). This should do it. 

     

    def props = new Properties()
    
    def projectpath = project.path
    
    
    //replace the path with your file name below. use / instead of \ as path separator even on windows platform.
    new File(projectpath+"/XXXXX/YYYYY.properties").withInputStream { s ->
    props.load(s) 
    }
    props.each {
    project.setPropertyValue(it.key, it.value)
    }
    
    //I also write down the project path into the global properties (just in case)
    project.setPropertyValue("projectpath", projectpath)
    com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "projectpathXXXX", projectpath )
    • groovyguy's avatar
      groovyguy
      Champion Level 1

      I found a good way to handle this without having to rely on groovy. You can set up a Properties test step to either save or load to / from a file. When the test-runner processes the Properties step, it'll trigger that action. I've done a small change to some of my projects and have been able to set up one that writes to a properties file. The following project can read that properties file with no issue and no added groovy. :) 

  • sanj's avatar
    sanj
    Super Contributor

    Do you already have the groovy script and now looking at how to invoke using cli?

     

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    I'm currently working something similar, Marathiboy. In my research, due to how command line works, and that it only loads the test project provided in the CLI parameters. There's two ways I've found around this:

     

    1. Combine the Read/Write projects into one combined project. This may bring about overhead for having to maintain multiple versions of a project if you have to maintain separate projects for other reasons.
    2. Utilize a properties file instead of a groovy script. This should be feasible, but would take some effort to figure out. I haven't had time to do this, but it's on my radar.

    I, too, am curious if anyone knows a way around this, as asked. Based on my research so far, the two options above are all I have found so far.

  • Olga_T's avatar
    Olga_T
    SmartBear Alumni (Retired)

    Hi,

    Thank you all for sharing your solutions. Marathiboy, did you find an option that would suit you? If so, could you please accept it as a solution (the green button below each post) so that other users can easily find it if they have a similar question?