得到此错误“ [TestNG]找不到测试。运行testng.xml文件时什么都没运行”

问题描述 投票:0回答:1

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

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("[email protected]");
        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("[email protected]");
        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();
    }
}
selenium testng
1个回答
0
投票

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

public class Parallel {

    public Parallel() {
        // Do something
    }

    ...
}

BTW:您的代码中有些东西没有意义。您有一个构造函数和一个带有Open自变量的公共方法WebDriver,但是无论如何您都在beforeclass中初始化驱动程序。因此,您可以删除构造函数和Open方法。

© www.soinside.com 2019 - 2024. All rights reserved.