遇到的错误:
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();
}
}
import net.jodah.failsafe.internal.util.Assert;
您确定这是正确的进口吗?我假设您想使用
import org.testng.Assert;
来代替,因为它具有字符串比较方法: https://www.javadoc.io/doc/org.testng/testng/6.8.17/org/testng/Assert.html# assertEquals(java.lang.String,%20java.lang.String)
我在使用 Eclipse 时遇到了同样的错误,为了解决我的问题,我在 Eclipse Marketplace 中下载了 testng 软件