0

I have multiple Environment and a lot of test cases, but not all test cases are needed to be run in all environment. Is there a way to run only an specific test cases from a test suite based on the selected Environment.

For Example If I select Environment1, it will run the following test cases

TC0001
TC0002
TC0003
TC0004
TC0005

If I select Environment2, it will run only the following test cases

TC0001
TC0003
TC0005
Rao
  • 20,781
  • 11
  • 57
  • 77
raiqee
  • 3
  • 3
  • Welcome to Stack Overflow, please take some time to follow the [Stack Overflow tour](http://stackoverflow.com/tour) and read about [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) Also provide us the relevant code you wrote for your question (You can also read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)) – Dipiks Jan 25 '17 at 08:50

1 Answers1

2

There can be different solution to achieve this since you have multiple environments i.e., pro software being used.

I would achieve the solution using Test Suite's Setup Script:

  • Create Test Suite level custom property. Use the same name as your environment name. For instance, DEV is the environment defined, use the same as test suite property name and provide the list of values separated by comma as value for that property, say TC1, TC2 etc.,
  • Similarly defined other environments and its values as well.
  • Copy the below script in Setup Script for the test suite and execute the script which enables or disables the test cases according to the environment and property value

Test Suite's Setup Script

/**
* This is soapui's Setup Script
* which enables / disables required
* test cases based on the user list
* for that specific environment
**/
def disableTestCase(testCaze) {
    testCaze.disabled = true
}

def enableTestCase(testCaze) {
    testCaze.disabled = false
}

def getEnvironmentSpecificList(def testSuite) {
    def currentEnv = testSuite.project.activeEnvironment.NAME
    def enableList = testSuite.getPropertyValue(currentEnv).split(',').collect { it.trim()}
    log.info "List of test for enable: ${enableList}"
    enableList
}

def userList = getEnvironmentSpecificList(testSuite)
testSuite.testCaseList.each { kase ->
    if (userList.contains(kase.name)) {
        enableTestCase(kase)
    } else {
        disableTestCase(kase)
    }
}

Other way to achieve this is using Event feature of ReadyAPI, you may use TestRunListener.beforeRun() and filter the test case whether to execute or ignore.

EDIT: If you are using ReadyAPI, then you can the new feature called tag the test cases. A test case can be tagged with multiple values and you can execute tests using specific tags. In this case, you may not needed to have the setup script as that is for the open source edition. Refer documentation for more details. This solution is only specific to Pro software and Open Source edition does have this tag feature.

Rao
  • 20,781
  • 11
  • 57
  • 77
  • How can you do it in Event.. I'm using a Pro SoapUI – raiqee Jan 27 '17 at 09:29
  • It would be good if you try the given solution and accept it as answer if helpful. Event way, does not seems to be straight forward not much elegant. – Rao Jan 27 '17 at 09:32
  • I encountered an error in this line def userList = getEnvironmentSpecificList (testSuite).. The error is this [link] (https://www.screencast.com/t/d4twV54IOduU) – raiqee Jan 27 '17 at 10:05
  • You are not following the instructions. Are you? Please use `Setup Script` of test suite. that is neither supposed to be in a separate test case nor groovy script. Please see the screen shot of the same here - https://www.soapui.org/functional-testing/working-with-scripts.html. You should double click on `Core - All Markets` to find the `Setup Script`. Have you defined test suite properties too? – Rao Jan 27 '17 at 10:06
  • By the way, there is minor issue found in the script, updated answer. So, request to try the updated script. – Rao Jan 27 '17 at 10:42
  • @raiqee, have you run this solution? do you have any question? if that worked, would you mind accepting it as answer? – Rao Feb 22 '17 at 05:27
  • @rao can i use above script in soapui os? – J. Doem May 13 '17 at 12:35