Ask a Question

Automate SoapUI

TvO
Occasional Contributor

Re: Automate SoapUI

Hi There,

 

Sounds Ok, that Jenkins and i will definatelly look into it. It might be usefull for me in future, but its not what i want to do at this moment..

What i want to do is make the projects, testcases and teststeps  every time i need to do my regression tests so that i don't have to keep track of every single alteration in the wsdl's.

Its supposed to become a time saver.

 

For this moment all i have to know is what groovy command i need to use to close project A and open project B. If i know that, then i can try (its all try and error atm) to get a step further...

 

The steps that i want to follow are:

1: automatically make projects 

    1.1 automatically fill some environment variables like different environment url's, different usernames/passwords, etc

2: automatically make testcases

3: automatically make teststeps

4: automatically fill the teststeps

5: run tests automatically and get a report

 

Step 1 is working (not 1.1, i will save that for later)

Step 2 isnt atm.

Step 5 is covered, i know how to do that

 

 

TvO
Occasional Contributor

Re: Automate SoapUI

Ok, i managed to do steps 1 and  2

 

Atm i am really struggling with adding SOAP teststeps from the WSDL.

I have several operations in the WSDL, lets say: Create, CreateOrUpdate, Delete, Retrieve, etc.

 

Now i need to make 1 teststep for each operations in the wsdl automatically.

 

Does anyone know how to let groovy read the wsdl and make a teststep for each method found?

 

I am working with the following:

Project Test

Suite: Testsuite 1

Case: Testcase 1

 

Teststeps? (to be made)

 

rupert_anderson
Valued Contributor

Re: Automate SoapUI

Hi,

 

Sorry, I've been quiet on this topic, work has been very busy!

 

To create a project and import a WSDL did you see:

 

https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-get-parameter-of-SOAP-operation/m-p/997...

 

To create Projects / TestSuites / TestSteps / Requests with Groovy, I did something like this for REST services, please see:

 

https://github.com/bearsoftware/ReplaceRequestInAllTestStepsAction/blob/master/src/test/groovy/bsl/c...

 

https://github.com/bearsoftware/ReplaceRequestInAllTestStepsAction/blob/master/src/test/groovy/bsl/c...

 

Do these links help at all?

 

Regards,

Rup

 

Author of SoapUI Cookbook
TvO
Occasional Contributor

Re: Automate SoapUI

Hi Rupert,

 

Thanks for the reply.

 

Difficulty for me is that i am a complete newbee at groovy and java.

Which means i really don't know which commando i actually miss.

 

So far i have got this working: 

I have 1 project, with a datasource step and a groovy step.

The datasource step will get the variables url and name for me from an excel list.

Up till making the project and the testsuite + testcase, it works fine.

But now i have to add some lines to make the appropiate teststeps for me. The WSDL has several methods included and i need some code to add them all.

I have been googling and trying to get the right syntax, but i cant seem to get the steps made from the wsdl.

 

-------------------------------------------------------------

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
import com.eviware.soapui.impl.wsdl.teststeps.*

 

def url = context.expand( '${Lees wsdl vanuit excel#url}' )
def projectName = context.expand( '${Lees wsdl vanuit excel#naam}' )
def currentProject = testRunner.testCase.testSuite.project
def workspace = testRunner.testCase.testSuite.project.workspace

WsdlProject project = currentProject
.getWorkspace()
.createProject(projectName, new File(projectName + ".xml"))
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, url, true )[0]
suite = project.addNewTestSuite("testsuite1")
tc = suite.addNewTestCase ("testcase1")

------------------------------------------------------------------

 

 

TvO
Occasional Contributor

Re: Automate SoapUI

Almost there...i found some code that does what i want.

Only thing is...it does work, but looks at the wrong project...

 

My full code is now:

 

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
import com.eviware.soapui.impl.wsdl.teststeps.*

def url = context.expand( '${Lees wsdl vanuit excel#url}' )
def projectName = context.expand( '${Lees wsdl vanuit excel#naam}' )
def currentProject = testRunner.testCase.testSuite.project
def workspace = testRunner.testCase.testSuite.project.workspace

 

WsdlProject project = currentProject
.getWorkspace()
.createProject(projectName, new File(projectName + ".xml"))
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, url, true )[0]
//Lees wsdl vanuit excel

//def project = workspace.createProject(projectName, new File(projectName + ".xml"))
suite = project.addNewTestSuite("testsuite1")
tc = suite.addNewTestCase ("testcase1")

 

//new part for making the teststeps

 

for (iFace in testRunner.testCase.testSuite.project.getInterfaceList()) {
//for (iFace in testRunner.tc.suite.project.getInterfaceList()) {
if (iFace.getName().matches(".*?[0-9]")) {
for (operation in iFace.getOperationList()) {
TStepC = WsdlTestRequestStepFactory.createConfig(operation, operation.getName());
testStep = tc.addTestStep(TStepC);
}
}
}

 

The last part works, if i copy the script to the newly made project and run it there.

It doesn't work if i keep it in the starting project. 

Either the getInterfaceList or the getOperationList commando is looking at the wrong project.

 

The code supposes to make a new project, with a new testsuite, a new testcase and new teststeps.

Up till making a new testcase, it works fine. It makes a brandnew Testcase in the new project.

The last part, the new teststeps are however not made in the new project..

 

Can anyone help me out to straighten this out? Should be such a small thing, but i have been staring and trying for hours now and i cannot seem to get it right...

TvO
Occasional Contributor

Re: Automate SoapUI

This is getting frustrating...are there any ppl out here who know Groovy script at all?

The only person that gave me something, has been rupert Anderson (which i thank for his replies)

 

 

 

rupert_anderson
Valued Contributor

Re: Automate SoapUI

Hi,

 

Sorry, I haven't been able to give more direct help, things are fairly busy work-wise.

 

Whilst you're feeling frustrated, you shouldn't, if you're new to java / groovy, then I would say you're actually doing pretty well! By the way, I know other SoapUI users do similar things to what you are trying to do, but I would say what you're doing should be considered an advanced usage of SoapUI, and isn't something people are likely to just know without actually following your steps.

 

Just taking a quick look at your script (haven't executed it myself), I was thought that there might be a chance that using testRunner variable to resolve the interface list might cause the TestCase creation to end up referencing the project that the script is actually running in rather than your new project?

 

for (iFace in testRunner.testCase.testSuite.project.getInterfaceList()) {
//for (iFace in testRunner.tc.suite.project.getInterfaceList()) {
if (iFace.getName().matches(".*?[0-9]")) {
for (operation in iFace.getOperationList()) {
TStepC = WsdlTestRequestStepFactory.createConfig(operation, operation.getName());
testStep = tc.addTestStep(TStepC);
}

I was looking in the source code for something similar to creating TestCase / TestSteps, and I saw the Action 

GenerateWsdlTestSuiteAction

This is the code that the menu 'Action' runs. It has a method:

 

private void generateSingleTestCase(WsdlTestSuite testSuite, WsdlInterface iface, boolean useExisting,
                                        boolean createLoadTest, List<String> operations) {
        WsdlTestCase testCase = testSuite.addNewTestCase(iface.getName() + " TestSuite");

        for (int i = 0; i < iface.getOperationCount(); i++) {
            WsdlOperation operation = iface.getOperationAt(i);
            if (!operations.contains(operation.getName())) {
                continue;
            }

            if (useExisting && operation.getRequestCount() > 0) {
                for (int x = 0; x < operation.getRequestCount(); x++) {
                    testCase.addTestStep(WsdlTestRequestStepFactory.createConfig(operation.getRequestAt(x),
                            operation.getName()));
                }
            } else {
                testCase.addTestStep(WsdlTestRequestStepFactory.createConfig(operation, operation.getName()));
            }
        }

        if (createLoadTest) {
            testCase.addNewLoadTest("LoadTest 1");
        }
    }

Maybe this could be stripped down and adapted to your needs or give clues?

 

Also, I think you might need to create the WSDL service definitions in the new project? Otherwise when you create the new TestSteps, they might reference the WSDL service definitions in the original project, which I don't think is what you actually want. SoapUI can have this type of issue when cloning existing objects that reference service definitions e.g. the new objects end up referring back.

 

Hope this makes sense. Just guesses at the moment, but I think you're probably quite close.

 

Regards,

Rup

Author of SoapUI Cookbook
TvO
Occasional Contributor

Re: Automate SoapUI

Hi Rupert,

 

Many thanks for your reply!!!

 

Yeah, its the testrunner line that sets me back to the original project.

Its 1 of those lines i don't get how it works. I have triend to put a variabele at the place of the .project. but that doesnt work, so the 'project' seems to be some statement that needs to be in that line and can't be altered.

 

The fun part is that the WSDL is actually imported in the new project. I don't know why exactly (if i know why, then i probably can work out why it isn't doing the same for the teststeps).

 

If i look at this part:

WsdlProject project = currentProject
.getWorkspace()
.createProject(projectName, new File(projectName + ".xml"))
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, url, true )[0]

suite = project.addNewTestSuite("testsuite1")
tc = suite.addNewTestCase ("testcase1")

 

and i Run it, the currentProject variabele gives back the 'original project', so i am puzzled why the line 'WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, url, true )[0]' actually imports the wsdl into the right project (i mean, its the same project variabele as in the testrunner line).

 

Maybe its a nice side-effect of the 'createProject' line...(that he keeps the focus on the newly made project there)

 

I will definatly try to use the code you gave from the Action method. How dit you find that? As a newbee, i thought those commands were just fixed commands for the groovy language 🙂 Happy surprise that there is actually a way of finding out what its really doing!

 

So many thanks and if i succeed, i will definatly let you know 🙂

 

TvO
Occasional Contributor

Re: Automate SoapUI

yes, made it work!

 

Your reply made me find this site: 

http://www.programcreek.com/java-api-examples/index.php?source_dir=soapui-master/soapui/src/main/jav...

 

and there i finally learned what those imports mean and what they exactly do.

and then i found another side which told me how to set the keyword project right, so that i could skip the whole 'testrunner' line that was shifting me to the initial project again 🙂

 

I am sure my code is not clean yet, but it works now! My code is now: 

 

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory

def url = context.expand( '${Lees wsdl vanuit excel#url}' )
def projectName = context.expand( '${Lees wsdl vanuit excel#naam}' )
def currentProject = testRunner.testCase.testSuite.project
def workspace = testRunner.testCase.testSuite.project.workspace

WsdlProject project = currentProject
.getWorkspace()
.createProject(projectName, new File(projectName + ".xml"))
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, url, true )[0]

project = workspace.getProjectByName(projectName)

suite = project.addNewTestSuite("testsuite1")
tc = suite.addNewTestCase ("testcase1")

def factory = new WsdlTestRequestStepFactory()
//for (iFace in testRunner.testCase.testSuite.project.getInterfaceList()) {
for (iFace in project.getInterfaceList()) {
if (iFace.getName().matches(".*?[0-9]")) {
for (operation in iFace.getOperationList()) {
TStepC = WsdlTestRequestStepFactory.createConfig(operation, operation.getName());
testStep = tc.addTestStep(TStepC);
}
}
}

rupert_anderson
Valued Contributor

Re: Automate SoapUI

Nice one! 🙂

 

I was just about to send you this, here it is just incase it helps:

 

import com.eviware.soapui.SoapUI
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory
import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.model.testsuite.TestCase
import com.eviware.soapui.model.testsuite.TestSuite
import com.eviware.soapui.impl.wsdl.teststeps.registry.*

WsdlProject project = new WsdlProject(SoapUI.workspace)

//Replace this with your WSDL
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project,"http://www.webservicex.com/globalweather.asmx?WSDL", true)[0]

def newTestSuite = project.addNewTestSuite("testsuite1")
def newTestCase = newTestSuite.addNewTestCase ("testcase1")

for (operation in iface.getOperationList()) {
	testStepConfig = WsdlTestRequestStepFactory.createConfig(operation, operation.getName());
	newTestCase.addTestStep(testStepConfig);
}

//*** Logs operations (optional below this line, just for debug)
Iterator<com.eviware.soapui.model.iface.Operation> i = iface.getOperationList().iterator()
while (i.hasNext()) {
    WsdlOperation op = (WsdlOperation) i.next()
    log.info("Operation: " + op.getName())
}

List<TestSuite> testSuites = project.testSuiteList
	testSuites.each{testSuite ->
     log.info "Found TestSuite name ["+testSuite.name+"]"
     List<TestCase> testCases = testSuite.testCaseList
     testCases.each{testCase ->
     	log.info "Found TestCase ["+testCase.name+"]"
          
          def testSteps = testCase.testSteps
          testSteps.each {testStep ->
          	log.info "Found TestStep [" + testStep + "]"
          }
     }
}

It has some debugging code at the bottom to log the TestSuites, TestCases, TestSteps on the created project. 

 

Yeah, using the testRunner like you did was referencing the old project.

 

So, now you can create the project, testsuite, testcase, teststeps, what next? Do you want to save the generated project?

 

Cheers,

Rup

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: