我需要检查一个cookie是否存在于页面上。
根据这个帖子,我需要检查一个cookie是否存在于页面上。
我已经尝试了以下的脚本Katalon模式添加这些从测试用例的标准导入。
import com.kms.katalon.core.webui.driver.driverFactory as DriverFactory。
将org.openqa.selenium.WebDriver导入为WebDriver。
而我写了。
WebUI.verifyMatch(driver.manage().getCookieNamed('foo'), is(null()))
然后我在null pointer上得到以下错误信息
FAILED Reason:java.lang.NullPointerException: 无法在空对象上调用方法call()。
有没有办法用Katalon Studio的脚本模式对 "无 "现有的cookie进行检查?
P.S:我已经尝试过其他的方法。
try {
_fbp = driver.manage().getCookieNamed('_fbp').getName()
}
catch (Exception e) {
String _fbp = new String('Something went wrong')
System.out.println('Something went wrong')
}
WebUI.verifyMatch('Something went wrong', _fbp, false)
它只在verifyMatch部分失败。似乎 "有些东西出错了 "并没有真正存储在变量_fbp中。
FAILED.Reason:groovy.lang.MissingPropertyException: 没有这样的属性。_fbp for class。
WebUI.verifyMatch()
是用于检查之间的匹配 两根弦.
你可以使用普通的Groovy断言来实现。取而代之的是
WebUI.verifyMatch(driver.manage().getCookieNamed('foo'), is(null()))
这样做。
assert driver.manage().getCookieNamed('foo').is(null)