运行testng.xml文件时出现此错误“ [TestNG]未找到测试。没有任何运行”

时间:2019-10-15 05:44:50

标签: selenium testng

在这里,我试图仅使用一个浏览器实例在同一类中执行测试用例。但打到这里了。我该如何刷新并返回同一页面以执行更多相同类的案例。如果我在不同类别中执行这些案例,则它们执行得很好,但在同一类中执行时却出错。

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();
    }
}

1 个答案:

答案 0 :(得分:1)

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

public class Parallel {

    public Parallel() {
        // Do something
    }

    ...
}

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