katalon can calling variable from custom keyword to another custom keyword in same class?
I want to calling ‘countList’ in frist keyword to use in second keyword for verifyEqual
example:
@Keyword //frist
def verifytext1(input) {
int total = WebUI.getText(findTestObject('Search/text_total_records'))
int countList = driver.findElements(By.xpath('//*[@class="dataListMid"]')).size()
WebUI.verifyEqual(total, 'Total Records: ' + countList)
}
@Keyword //second
def verifytext2(input) {
int countText = driver.findElements(By.xpath('//*[@id="start"]/div/span/div[contains(translate(text(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"),'+input+')]')).size()
WebUI.verifyEqual(countList,countText)
}
@Keyword
def verifytext1(input) {
int total = WebUI.getText(findTestObject('Search/text_total_records'))
WebUI.verifyEqual(total, 'Total Records: ' + this.getCountList())
}
@Keyword //second
def verifytext2(input) {
int countText = driver.findElements(By.xpath('//*[@id="start"]/div/span/div[contains(translate(text(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"),' + input + ')]')).size()
WebUI.verifyEqual(this.getCountList(), countText)
}
private int getCountList() {
return driver.findElements(By.xpath('//*[@class="dataListMid"]')).size()
}
1 Like
(FYI: There is a built-in keyword for findElements)
1 Like
Slightly amended version (hide the Selenium API behind the Katalon API as much as possible):
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.WebElement
...
@Keyword
def verifytext1(input) {
int total = WebUI.getText(findTestObject('Search/text_total_records'))
WebUI.verifyEqual(total, 'Total Records: ' + this.getCountList())
}
@Keyword //second
def verifytext2(input) {
int countText = WebUI.findWebElements(makeTestObjectByXPath('//*[@id="start"]/div/span/div[contains(translate(text(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"),' + input + ')]')).size()
WebUI.verifyEqual(this.getCountList(), countText)
}
private int getCountList() {
return WebUI.findWebElements(makeTestObjectByXPath('//*[@class="dataListMid"]')).size()
}
private TestObject makeTestObjectByXPath(String xpath) {
TestObject tObj = new TestObject(xpath)
tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
return tObj
}
1 Like