如果其他条件 Assert.assertEquals selenium testNG [英] if else condition on Assert.assertEquals selenium testNG

查看:38
本文介绍了如果其他条件 Assert.assertEquals selenium testNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 java 处理 selenium 和 testNG .. 我对这段代码有一些问题:

I am working on selenium and testNG with java.. I have some problem about this code:

Assert.assertEquals(webDriver.getCurrentUrl(), "http://google.com");

问题是如何在 assertEquals 中创建 if else 条件.像这样

the question is how to create if else condition in assertEquals. like this

if( Assert.assertEquals(webDriver.getCurrentUrl(), "http://google.com"));
{
    //do Nothing
}

else
{
   // take screenshoot
}

有什么想法吗?

推荐答案

如果一个断言失败,它会抛出一个 assertionError.您需要捕获 AssertionError 并在捕获中捕获屏幕截图.

If an assert fails, it throws an assertionError. You need to catch the AssertionError and in the catch capture the screenshot.

try{
   Assert.assertEquals(...,...);
}catch(AssertionError e){
   Log error;
   Takescreenshot;
}

这篇关于如果其他条件 Assert.assertEquals selenium testNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆