Katalon Studio - 自用tips

1. 运行时用代码创建全局变量or给全局变量重新赋值:
创建自定义keywords,或者test case里的自定义方法

@Keyword
 void addGlobalVariable(String name, def value) {
  GroovyShell shell1 = new GroovyShell()
  MetaClass mc = shell1.evaluate("internal.GlobalVariable").metaClass
  String getterName = "get" + name.capitalize()
  mc.'static'."$getterName" = { -> return value }
  mc.'static'."$name" = value
}

在case里的UI视图里使用customer keywords

2. 自动运行启动chrome时出现fail to load extension
解决:
在打开浏览器前使用代码:

System.setProperty('webdriver.chrome.driver', 'C:/software/Katalon_Studio_Windows_64-7.0.4/configuration/resources/drivers/chromedriver_win32/chromedriver.exe')   //katalon的路径

ChromeOptions options = new ChromeOptions()

options.setExperimentalOption('useAutomationExtension', false)

WebDriver driver = new ChromeDriver(options)

DriverFactory.changeWebDriver(driver)

WebUI.navigateToUrl('url')

相关的包
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.kms.katalon.core.webui.driver.DriverFactory

3. 自定义获取元素数量的方法

import com.kms.katalon.core.webui.driver.DriverFactory
import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement

WebDriver driver = DriverFactory.getWebDriver()
List rows_table = driver.findElements(By.tagName('tr'))
int rows_count = rows_table.size()
println('No. of rows: ' + rows_count)

4.调用自测试用例时,根据需要传入参数

//call test case using WebUI Class
WebUI.callTestCase(findTestCase({Test Case ID}), [key1:value1, key2:value2, … , keyN:valueN], FailureHandling.option)

//call test case using Mobile Class
Mobile.callTestCase(findTestCase({Test Case ID}), [key1:value1, key2:value2, … , keyN:valueN], FailureHandling.option)

key是参数名,与被调用用例内所需参数一致
value传入值

5. Verify Element Visible 和 Verify Element Present有什么不同

Element Visible:元素在页面上可见
Element Present:元素在html里存在
Element Not Visible: 元素在html里存在,但是网页上不可见
Element Not Present: 元素在html里不存在
//自己的总结,可能不够严谨

你可能感兴趣的:(Katalon Studio - 自用tips)