Search code examples
javaseleniumselenium-webdrivertestngassert

Asserts in selenium TestNG (The method assertEquals(String, String) is undefined for the type Assert)


Error faced:

FAILED: f
java.lang.Error: Unresolved compilation problem: 
    The method assertEquals(String, String) is undefined for the type Assert
package firstTestNGpackage;

import net.jodah.failsafe.internal.util.Assert;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class FIrstTestNGfile {
    public String baseUrl = "http://demo.guru99.com/test/newtours/";
    String driverPath = "/home/local/ZOHOCORP/bala-pt4540/chromedriver";
    public WebDriver driver ;
  @Test
  public void f() {
          System.setProperty("webdriver.chrome.driver", driverPath);
          driver = new ChromeDriver();
          driver.get(baseUrl);
          String expectedTitle = "Welcome: Mercury Tours";
          String actualTitle = driver.getTitle();
          Assert.assertEquals(actualTitle, expectedTitle);
          driver.close();
    
  }
}

Solution

  • import net.jodah.failsafe.internal.util.Assert;

    Are you sure this is the right import? I assume you would like to use import org.testng.Assert; instead because this has the String compare method: https://www.javadoc.io/doc/org.testng/testng/6.8.17/org/testng/Assert.html#assertEquals(java.lang.String,%20java.lang.String)