首页 > 解决方案 > 从 Groovy 中的 setup 方法内部调用闭包/方法

问题描述

由于某种原因,setup 方法无法识别它之前的闭包,因为当这段代码被放入测试套件并运行时,它会抛出 MissingMethodException我试图调用的闭包:

int initialNumberOfRows = 0

def findRowCount = {

    initialNumberOfRows = 5
}

/**
 * Some methods below are samples for using SetUp/TearDown in a test suite.
 */
/**
 * Sets up test environment.
 */
@SetUp(skipped = false) // Please change skipped to be false to activate this method.
def setUp() {
    //  login and select the test company first
    WebUI.callTestCase(findTestCase('Test Cases/TestCompanySelectGoesToDashboard'), [('shouldLogout') : false, ('shouldCloseBrowser') : false])
    //  go to the "Discounts" page
    WebUI.click(findTestObject('PageMenuOptions/a_Discounts'))
    //  determine the row count
    WebUI.delay(5)
    findRowCount()
}

我运行该代码并收到以下异常消息:

groovy.lang.MissingMethodException: No signature of method: DiscountsSuite.findRowCount() is applicable for argument types: () values: []

截至目前,闭包是一个存根,但将用于获取行数,之后我们将删除作为测试套件的清理(我通过测试套件创建行,我必须清理它们! )

标签: groovykatalon-studio

解决方案


推荐阅读