0

Need help, my question here is how can I code it such when the result is not expected testNG will display the test case as failure/fail? if the result is expected test case result is passed? very new to TestNG. my problem here is no matter how many times I run, the testNG result is PASSED.

public class TestNgbasic{  DesktopOptions option=new DesktopOptions();  

@BeforeMethod
public void setup() {
//  DesktopOptions option=new DesktopOptions();  // Start your outlook session
    option.setApplicationPath("C:\\Windows\\System32\\calc.exe");      
}

@Test
public void testcase1 () throws MalformedURLException, InterruptedException
{
    WiniumDriver driver=new WiniumDriver(new URL("http://localhost:9999"), option);
    Thread.sleep(5000);
    driver.findElement(By.name("Seven")).click();
    driver.findElement(By.id("plusButton")).click();
    driver.findElement(By.name("Eight")).click();
    driver.findElement(By.id("equalButton")).click();
    Thread.sleep(5000);
    String result = driver.findElement(By.id("CalculatorResults")).getAttribute("Name");        
    if ("Display is 15".equals(result))
    {
        System.out.print("Pass");   
    }
    else 
        System.out.print("Fail");   
}   

}

5

1 Answer 1

1

Please use TESTNG assert:

Assert.assertEquals(actualtitle, expectedtitle); fails the test . You have to import import org.testng.Assert;

public class TestNgbasic{  DesktopOptions option=new DesktopOptions();  

@BeforeMethod
public void setup() {
//  DesktopOptions option=new DesktopOptions();  // Start your outlook session
    option.setApplicationPath("C:\\Windows\\System32\\calc.exe");      
}

@Test
public void testcase1 () throws MalformedURLException, InterruptedException
{
    WiniumDriver driver=new WiniumDriver(new URL("http://localhost:9999"), option);
    Thread.sleep(5000);
    driver.findElement(By.name("Seven")).click();
    driver.findElement(By.id("plusButton")).click();
    driver.findElement(By.name("Eight")).click();
    driver.findElement(By.id("equalButton")).click();
    Thread.sleep(5000);
    String result = driver.findElement(By.id("CalculatorResults")).getAttribute("Name");        
    Assert.assertEquals(result, "Display is 15");

}
1
  • Thank you it works! :) Commented Apr 6, 2020 at 3:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.