w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to make the opening of browser(all test in one browser) static in testng for selenium

You already declared the type for driver in your field declarations. Redeclaring it in openMain() is your problem. It should look like this.

import static org.testng.Assert.assertNotNull;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class OpenSite {
    private WebDriver driver;

    @BeforeClass(alwaysRun=true)
    public void openMain()
    {
     
System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
      driver = new ChromeDriver();
      driver.get("http://vtu.ac.in/");
    }

    @Test
    //Clicking on the first link on the page
    public void aboutVTU()
    {
        assertNotNull(driver);
        driver.findElement(By.id("menu-item-323")).click();
    }

    @Test(dependsOnMethods="aboutVTU")
    //clicking on the 2nd link in the page
    public void Institutes()
    {
        assertNotNull(driver);
        driver.findElement(By.id("menu-item-325")).click();
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.