Got it. Since I wanted to cover the scenario of the existence of the table also, I changed my keyword to the following:
class FavoritesKeywords {
@Keyword
def boolean locateTable(){
// creating a variable 'driver' and assigning its value
WebDriver driver = DriverFactory.getWebDriver()
//To locate the table and set the keyword to return a boolean value
return driver.findElements(By.xpath("//table[@class='cart']")).size() > 0
return driver.findElements(By.xpath("//table[@class='cart']//thead")).size() > 0
}
}
Here is the error I got:
2019-08-13 13:54:47.970 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - ❌ Unable to locate element: //table[@class='cart']//thead
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'CES-FS7JG72', ip: '10.120.70.125', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 25012, moz:profile: C:\Users\M\Ap..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 0174af81-bdfb-4a8d-8637-68c80e6636d2
*** Element info: {Using=xpath, value=//table[@class='cart']//thead}
2019-08-13 13:54:47.975 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/mj_regression/Favorites_all_headers FAILED.
Reason:
org.openqa.selenium.NoSuchElementException: Unable to locate element: //table[@class='cart']//thead
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'CES-FS7JG72', ip: '10.120.70.125', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 60.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 25012, moz:profile: C:\Users\M\Ap..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 0174af81-bdfb-4a8d-8637-68c80e6636d2
*** Element info: {Using=xpath, value=//table[@class='cart']//thead}
It is trying to find the headers of the table but is unable to do because the table is not there. What can I change to cover this scenario also?