Selenium Assert等于Value1或Value2

Gen*_*uts 0 java testng selenium intellij-idea selenium-webdriver

我想在Selenium(Java,Testng)中测试如果我的实际值等于这两个值中的一个,因为我的值可以是Value1或Value2,并且两个值都是正确的.

如果我想断言只有一个相等,我使用这个结构:

String expectedPopUpV1 = "Value1";
String expectedPopUpV2 = "Value2";
String actualPopUp = driver.findElement(By.cssSelector(Value)).getText();
Assert.assertEquals(actualPopUp,expectedPopUp);
Run Code Online (Sandbox Code Playgroud)

但如果我想制作类似的东西,该怎么办?

Assert.assertEquals(actualPopUp,expectedPopUp1||expectedPopUp1);
Run Code Online (Sandbox Code Playgroud)

Guy*_*Guy 5

您可以使用assertTrue(boolean condition, String message)此功能并在消息中提供详细信息

boolean isEqual = actualPopUp.equals(expectedPopUpV1) || actualPopUp.equals(expectedPopUpV2);
Assert.assertTrue(isEqual, "The text " + actualPopUp + " is not " + expectedPopUpV1 + " or " + expectedPopUpV2);
Run Code Online (Sandbox Code Playgroud)