Search code examples
selenium-webdrivertestng-dataprovider

How to print text below and above Passed: in the console area in selenium


I have three @test methods to add, update and delete records in a webpage, once my execution completes I am looking for an output something like below, where can I use the sisout to print the highlighted messages, I am running my code in TestNG.

enter image description here

   @Test(priority=2)
  void updateAddressBook() {
try{
driver.findElement(By.id("radio1")).click();
driver.findElement(By.id("edit")).click();
driver.findElement(By.id("company")).clear();
Thread.sleep(3000);
driver.findElement(By.id("company")).sendKeys("Vuram");
driver.findElement(By.id("add")).click();
Log.info("Validate company name is updated for user 2");
Reporter.log("Company name sucessfully updated for user 2");
passCount++;
}  catch (Error e) {
    verificationErrors.append("Cannot provide the input please stick to the UI constraints5.\n");
} catch(Exception e){
    verificationErrors.append("Cannot provide the input please stick to the UI constraints6.\n");
}

try {
    String x = driver.findElement(By.id("result")).getText();
    if(x.contains("Vuram"));
    {  
        passCount++;
    }
 } catch (Error e) {
    verificationErrors.append("Element by id 'td' not found.\n");
  } catch (Exception e) {
    verificationErrors.append("Element by id 'td' not found.\n");
  }
}

Solution

  • This is the solution what are you looking for, Just implement it sample demo:

    System.out.println(); for Console Logs

    @Test(description = "") for Test Description

    public class demo {
    
        @Test(description = "This is description of Test Case")
        public void TestDemo() {
    
            System.out.println("****************************");
            System.out.println("Hello World");
            System.out.println("****************************");
        }
    
    }
    

    Console