Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriver + TestNG - How to handle test results

I'm quite new to WebDriver and TestNG framework. I've started with a project that does a regression test of an e-commerce website. I'm done with the login and registration and so on. But there is something that I don't quite understand.

Example, I have this easy code that searches for a product.

driver.get(url + "/k/k.aspx");
driver.findElement(By.id("q")).clear();
driver.findElement(By.id("q")).sendKeys("xxxx"); //TODO: Make this dynamic
driver.findElement(By.cssSelector("input.submit")).click();

Now I want to check if xxxx is represented on the page. This can be done with

webdriver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]*xxxxxx[\\s\\S]*$")

I store this in a Boolean and check if its true or false.

Now to the question, based on this Boolean value I want to say that the test result is success or fail. How can I do that? What triggers a testNG test to fail?

like image 613
Oleaha Avatar asked Feb 18 '23 05:02

Oleaha


1 Answers

TestNG or any other testing tool decides success or failure of a test based on assertion.

Assert.assertEquals(actualVal, expectedVal);

So if actualVal and expectedVal are same then test will pass else it will fail.

Similarly you will find other assertion options if you using any IDE like Eclipse.

like image 147
rai.skumar Avatar answered Feb 21 '23 16:02

rai.skumar