Global Variables - Katalon Studio

霸气de小男生 提交于 2020-02-05 20:55:11

问题


I am working with Cucumber & Groovy in Katalon Studio.

I have ten feature file lines in Cucumber and corresponding step definitions.

In my cucumber feature file first step has the indicator where if the first line is passed with the parameter with "NO RUN", the test case should not run and it should be moved to the next test case.

So, I thought, I will use the Global variable indicator where I can handle in the test and assign the values. I see that and could create the Global Variable (RUN INDICATOR) under the Execution profile. But, not sure how I need to use that variable in the test script or refer.

Can someone please provide the inputs on this to proceed further ?

Step Definition

@Given("running indicator flag (.*)")
def run_indicator_flag(String ind1)  {
    println "Passing Indicator " + ind1
    assert ((ind1!='') || (ind1!='N'))
    WebUI.openBrowser('', FailureHandling.STOP_ON_FAILURE)
}

回答1:


You can use test listeners to do that.

  1. Create a Global Variable with the empty string value (You need to do this before actually running the test case/suite):
GlobalVariable.RUN_INDICATOR = ''

You will update its value either manually or preceding test will update it to whatever value you wish.

  1. Create a test listener with the following code
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
    if(GlobalVariable.RUN_INDICATOR=='NO RUN'){
        testCaseContext.skipThisTestCase()
        println "Test Case skipped"
    }
}

If the GlobalVariable.RUN_INDICATOR is set to 'NO RUN', this test case will be skipped and the test suite will continue with the next one.



来源:https://stackoverflow.com/questions/56767341/global-variables-katalon-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!