BruceyBandit BruceyBandit - 7 months ago 19
Groovy Question

Selecting endpoints dependent on which level to run tests

I have a bit of structural dilemma in soap. When running tests, it can be possible to run tests at project, test suite or test case level.

Now currently what happens is that we can run a whole project via project level and it will display a prompt box to select an endpoint (through a project level setup script and produces a project report using the project level tear down script).

However, it may be possible that the tester may not want to run a whole project and only wants to run a test suite or even a test case. Now it may be possible that the tester may only want to run only a test suite or even only a test case. Now it would be a hassle disabling suites or cases you don't want to run.

Now the problem i have is that if I start putting prompt boxes to select endpoints at suite or case level, everytime we hit a suite or case, it will always ask for an endpoint. Another thing is that I am thinking not creating suite or test case reposts because if running many suites or cases one by one, it is just an overkill on reporting.

I like your thinking on this, but I was speaking with my professional colleague and what we're thinking is this:

Add the below code for all test suites and test case level in their relevant setup scripts where it asks for endpoint (this is same code used in project set up script for selecting endpoint):

import com.eviware.soapui.support.*
def alert = com.eviware.soapui.support.UISupport

def urls = []

project.properties.each
{
if (it.value.name.startsWith("BASE_URL_"))
{
urls.push(it.value.name.replace("BASE_URL_", ""))
}
}

def urlName = alert.prompt("Please select the environment URL", "Enter URL", urls)
if (urlName)
{
def url = project.getPropertyValue("BASE_URL_" + urlName)
def urlBase = "BASE_URL_" + urlName

project.setPropertyValue("BASE_URL", url)

switch (urlBase){

case "BASE_URL_TEST":
project.setPropertyValue("DOMAIN_NAME", "TEST");
break;
case "BASE_URL_STAGE":
project.setPropertyValue("DOMAIN_NAME", "STAGE");
break;
default:
project.setPropertyValue("DOMAIN_NAME", "NO DOMAIN");
break;

}
}
else
{
log.warn 'haven\'t received user input'
log.warn 'No base URL is selected or cancelled, try again'
assert false
}


Now what we add is the following and we may need to use properties but again see what you think is best:


  • If test is ran at project level, it will prompt to select endpoint through project setup script but it will not ask for selecting endpoint through test suite or test case setup script. So it's only a single endpoint selection

  • If test is ran at suite level, it will prompt to select endpoint through project setup script but it will not ask for selecting endpoint through test case setup script. So it's only a single endpoint selection

  • For running at test case level, well it only runs for that test case so it's at the lowest level as it asks for an endpoint for that test case.



We can't have setup scripts disabled at any level because there maybe over code in those setup script that will need to be exectued, we just need a way to say depending on which level, don't ask for selecting endpoints at lower levels.

Seems complicated to implement but does anyone know best way to implement this or do they even have a better idea than this theory?

Thanks

Rao Rao
Answer Source

For a moment, let us assume you get it done for all levels (project, suite, and each case). May be you forgot about the step level ;-)

Do you have any Pros in your approach?, for me, NO.

Cons in your approach:

  1. Each time user executes a test (be it project / suite / any test case), engineer needs to select value from the drop down, which is unwanted though testing against the same server as previous test case & little annoying.
  2. Test execution requires manual intervention each time test execution is invoked.
  3. User Interface is required as drop down being used.
  4. Will be come road block / hurdle for end to end automation or to achieve automation.
  5. Test execution can't done in headless mode. And this is important if you need to use Continuous Integration tools.

Proposed Approach :-

If I have to do the above, I would do the following. That would be clean, damn simple, no such complications would arise that you had mentioned in the long summary.

Looks there are following project properties defined with addresses of the test servers:

  • BASE_URL_TEST
  • BASE_URL_STAGE

There is also another project property defined BASE_URL and all the above logic is to allow the user to select the value from above properties to base URL value.

Now all user have to do is change the value for project property BASE_URL. I would think just user have to set one of the below value by hand what he / she needed as (one of them) before proceeding with their tests.

  • ${#Project#BASE_URL_TEST} or
  • ${#Project#BASE_URL_STAGE}

NOTE that a property value can be referred into another property by the use of Property Expansion like above.

  • With the above, user can set whatever is needed and change only if required or have to change the test server.
  • No setup script at any level is required any more, and just simply change the value of the property.
  • Properties are given to make to life simple, which can be used in N number of places and maintain the project easily.
  • Most Importantly, overcome the Cons mentioned in the beginning.
  • It is general practice that SoapUI is used to design the tests, and SOAPUI_HOME/bin/testrunner.bat or .sh utility to execute the tests in command line mode and that is the way to achieve Continuous Integration.
  • That's why use of properties helps here to achieve the above without any issues.

Even simple:
Just have one project property BASE_URL (remove others), user have to just edit the property value and have the test server name / IP address and is done for once, say http://testjuniper. Isn't it dead simple?

And I believe, the engineer would definitely know which server he / she is using to execute the tests.

Having said that, now user do not have bother at all, irrespective of executing a project / suite / test case, as long as testing is carried out against the same server / environment.

Once, the test execution is finished against TEST environment, the engineer may move on to other environment say STAGING, just change BASE_URL property value accordingly.