1. 運(yùn)行時(shí)用代碼創(chuàng)建全局變量or給全局變量重新賦值:
創(chuàng)建自定義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. 自動運(yùn)行啟動chrome時(shí)出現(xiàn)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')
相關(guān)的包
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. 自定義獲取元素?cái)?shù)量的方法
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<WebElement> rows_table = driver.findElements(By.tagName('tr'))
int rows_count = rows_table.size()
println('No. of rows: ' + rows_count)
4.調(diào)用自測試用例時(shí),根據(jù)需要傳入?yún)?shù)
//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是參數(shù)名,與被調(diào)用用例內(nèi)所需參數(shù)一致
value傳入值
5. Verify Element Visible 和 Verify Element Present有什么不同
Element Visible:元素在頁面上可見
Element Present:元素在html里存在
Element Not Visible: 元素在html里存在,但是網(wǎng)頁上不可見
Element Not Present: 元素在html里不存在
//自己的總結(jié),可能不夠嚴(yán)謹(jǐn)