运行testng.xml文件时" [TestNG] No tests found. Nothing was run"此错误



在这里,我尝试仅使用一个浏览器实例在同一类中执行测试用例。但在这里罢工。我如何刷新并返回同一页面以执行相同类的进一步案例。如果我在不同的类中执行案例,它们执行良好,但在同一类中执行时会出错。

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Parallel {
Parallel objectb;
WebDriver driver;
public Parallel(WebDriver driver) {
this.driver=driver;
// TO DO Auto-generated constructor stub
}
public void Open(WebDriver driver) {
this.driver=driver;
// TO DO Auto-generated constructor stub
}
@BeforeClass
public void beforeclass() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+".\drivers\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.browserstack.com/users/sign_up");
}
@Test
public void testOnChromeWithBrowserStackUrl() throws InterruptedException {
Open(driver);
Thread.sleep(2000);
driver.manage().window().maximize();
driver.findElement(By.id("user_full_name")).sendKeys("Mamta Singh");
driver.findElement(By.id("user_email_login")).sendKeys("mamtasingh24@gmail.com");
driver.findElement(By.id("user_password")).sendKeys("browserstack");
System.out.println(
"this is the test related to chrome browserstack homepage" + " " + Thread.currentThread().getId());
}
@Test
public void testOnChromeWithBrowserStackSignUp() throws InterruptedException
{
objectb= new Parallel(driver);
Thread.sleep(2000);
driver.manage().window().maximize();
driver.findElement(By.id("user_full_name")).sendKeys("Sadhvi Singh");
driver.findElement(By.id("user_email_login")).sendKeys("sadhvisingh24@gmail.com");
driver.findElement(By.id("user_password")).sendKeys("browserstack");
System.out.println("this is the test related to chrome browserstack login"+ " " +Thread.currentThread().getId());
}
@AfterClass
public void close()
{
driver.quit();
}
}

测试类中需要一个标准构造函数。

public class Parallel {
public Parallel() {
// Do something
}
...
}

顺便说一句:你的代码中有一些东西没有意义。 您有一个构造函数和一个带有WebDriver参数Open的公共方法,但您仍然在beforeclass中初始化驱动程序。因此,您可以删除构造函数和Open方法。

最新更新