Trying
Trying

Reputation: 1

Getting this error " [TestNG] No tests found. Nothing was run" while running testng.xml file

Here i am trying to execute test cases in same class with only one browser instance. But struck here. How can i refresh and come back to same page to execute further cases of same classes.If i execute the cases in different classes, they are executing fine but giving error when executing in same class.

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

Upvotes: 0

Views: 118

Answers (1)

AndiCover
AndiCover

Reputation: 1734

You need a standard constructor in your test class.

public class Parallel {

    public Parallel() {
        // Do something
    }

    ...
}

BTW: There are a few things in your code that do not make sense. You have a constructor and a public method Open with a WebDriver argument but you are initializing the driver in the beforeclass anyway. So you could remove the constructor and the Open method.

Upvotes: 1

Related Questions