WebDriver + TestNG - How to process test results

I am completely new to the WebDriver and TestNG environments. I started with a project that performs a regression test of an e-commerce website. I ended up registering and registering and so on. But there is something that I do not quite understand.

For example, I have this simple code that is looking 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 present on the page. This can be done using

 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 for the question based on this Boolean value, I want to say that the test result is successful or unsuccessful. How can i do this? What causes testNG test?

+4
source share
4 answers

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

 Assert.assertEquals(actualVal, expectedVal); 

So, if actualVal and expectedVal match, then the test will fail differently and it will fail.

Similarly, you will find other approval options if you use any IDE, such as Eclipse.

+5
source

If you want to stop the test based on checking this text value, you can use Asserts. However, if you want to write the test result as a failure and continue, try using soft statements that register the test as passed or failed and continue with the test. The latest Testng comes with this to handle this - info on the Cedric blog

+3
source

write this code where your if condition is not working

 throw new RuntimeException("XXXX not found: "); 
0
source

u can use a throw exception, and every method that this method will define must also call Excetion after the method name, or you can use try catch. Sample:

 protected Boolean AssertIsCorrectURL(String exedctedURL) throws Exception { String errMsg = String.format("Actual URL page: '%s'. Expected URL page: '%s'", this.driver.getCurrentUrl(), exedctedURL); throw new Exception(errMsg); } 
0
source

All Articles