Zomzomzom
Zomzomzom

Reputation: 47

Print messages on failed test cases in Selenium?

I am trying to print messages in Selenium when a step is failing. I am not sure which method should I use. My script is in Java and all it does is to open a website and click some stuff. The error messages are not helpful and I want to be able to translate these unhelpful messages to some customized ones by myself.

Which method or code should be used for that?

Upvotes: 1

Views: 2758

Answers (2)

rajan
rajan

Reputation: 77

you can simply use if else statement, if you don't want to complex things.

WebElement a = driver.findElement(By.id("android:id/button1"));

                    if(a.isDisplayed())
                    {
                        System.out.println("Element is displayed");

                        a.click();

                        System.out.println("Element is Clicked");
                    }
                   else {
                        System.out.println("Element not present");
                    } 

Hope this will solve your problem

Upvotes: 1

Wes Young
Wes Young

Reputation: 76

Use TestNG/Junit as your test framework and then you can use assertions. I use a lot of soft asserts. Example:

softAssert.assertEquals('Expected','Actual',"Failed because Actual did not match expected");

The third value there is the error message. You can set it to whatever you want. It will report only if failure occurs.

Short of that, you can use some try/catch methods but that's not ideal when there are already tools for the job.

Upvotes: 2

Related Questions