java - 截取 Selenium 中断言的屏幕截图?

标签 java selenium testng

以下是我的断言。

Assert.assertEquals(securityQuestionPage.UserName.getText().toString(),BaseClass.unsuccessfulpassword);

我想根据断言的结果使测试用例失败/通过..

如果断言失败:

test.fail("description", takescreenshot)

如果断言通过

test.pass("passed",takeScreenshot)

不使用if语句,我可以有像三元运算符这样的断言吗?

有类似的吗?

Assert.AsserEquals(locator.getText(), expectedMessage,test.pass(""),test.fail())

最佳答案

您可以使用try-catch block :

try{
 Assert.assertEquals(securityQuestionPage.UserName.getText().toString(),BaseClass.unsuccessfulpassword);  

// Now if the above line is correct then flow will not go to catch block followed by line just after this line.
 test.pass("passed",takeScreenshot)
}

catch(Exception e){
    test.fail("description", takescreenshot)
 }

关于java - 截取 Selenium 中断言的屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50924709/

相关文章:

java - 将 long[] 更改为 Set。错误消息 : The method addAll in the type Collections is not applicable for the arguments (Set<Long>, 长[])

Java 用重音符号替换所有内容

python - 两个独立路径的 XPath?

java - maven项目中"Parameter '浏览器' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined"错误

java - Spring3/Hibernate3/TestNG : some tests give LazyInitializationException, 有些没有

java - 动态创建TestNG.xml文件并传递参数

java - 不共享公共(public)资源的线程是否可以根据线程 ID/名称进行通知?

java - 我如何找出 Eclipse 陷入无限构建周期的原因?

ruby-on-rails - docker 中的 Capybara headless chrome 返回 DevToolsActivePort 文件不存在

java - 使用忽略大小写的属性查找元素