开发者

Which class should I import to use verifyTrue

I am using Selenium with TestN开发者_JAVA百科G using dataProvider. I am verifying the list which have hundred names. I have added all of these into an excel sheet with comma separated in A CELL. I have programmed in Java as below:

import static org.testng.AssertJUnit.*;
public class example extends Base{
    @Test(dataProvider="List")
    public void isListofNamesPresent(String names) throws Exception
    String list[] = names.split(",");
    for(int i=0; i<list.length; i++){
        assertTrue(selenium.isTextPresent(list[i]));
        Reporter.log("Type of Case:"+ names +" are present");
    }
}

The above code asserts the list of names which are put in A CELL as (Aaron, James, Jack, Hegin, Henry).Since it has only one round of data it exits the method if any error between actual and expected because of assertTrue. If i give verifyTrue then it should get execute all the list even though there is a mismatch between actual and expected.

Can anyone please tell me how to use verifyTrue? I mean which class i need to import. I cannot extend any class as I have already extended a Base Class. So any import will do. I tried with SeleneseTestCase but no luck.

Thanks in advance


Another way you can do it would be to create your own verifyTrue() method that does something like this to catch the assert error:

public static void verifyTrue(boolean condition, String message) {
    try {
        Assert.assertTrue(condition, message);
        log("Expected value: true" + " Actual value: " + condition + " - PASSED ", true);
    } catch (Throwable e) {
        log("Expected value: true" + " Actual value: " + condition + " - FAILED " + message, true);
        addVerificationFailure(e);
    }
}


You can import SeleneseTestBase class to use verifyTrue() as below:

import com.thoughtworks.selenium.SeleneseTestBase;

SeleneseTestCase can also be used, but it is deprecated. So. it is better to use SeleneseTestBase

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜