Forum Discussion

tjvelkof's avatar
tjvelkof
Occasional Visitor
7 months ago

Environment-specific assertions

I make use of XPath assertions. Is it possible to create assertions whose expected values differ, based on the environment in which the test is run?

2 Replies

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    What I often do in such a case is assert via a script assertion.

    In the script I get the current active environment via:

     

    def activeEnvironmentName = messageExchange.modelItem.project.activeEnvironment.name

    //note, this is the name for your environment you have setup in the "Endpoints & Environments" setting.

    //for tst

    def expectedResult = "tst123"

    if (activeEnvironmentName == "acc"){

    //for acc

    expectedResult = "acc123"

     

    then proceed with the actual assertion by getting the actual api response value and assert it against expectedResult

     

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    If you set up a Project level custom property, that will have a per-Environment value. If you then use a property expansion to that property as your XPath assertion's expected value, that should work. You can read more here.