I am using testNG and selenium Web Driver and I am always facing the issue with passing the driver instance. Here, the BaseClass is used to have my driver setup and which has @BeforeSuite annotations to call before all the things. But when the Test Class is executing, the driver value is getting NULL and its throwing an error.
public class BaseClass {
@BeforeSuite
public void setup() {
System.out.println("Initializing the driver");
System.setProperty("webdriver.chrome.driver", "/Users/vinoth/Git/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://my.yocoboard.com");
}
@AfterSuite
public void tearDown() {
System.out.println("Quiting Everything");
}
The Above class is my Base Class where I have initiated my driver setup.
public class FirstClassYoCo extends BaseClass {
WebDriver driver;
WebDriverWait wait;
SoftAssert softAssert;
@Test(priority = 1, groups = "function")
public void validateCurrentWeek() {
//driver.get("https://my.yocoboard.com");
driver.findElement(By.id("email")).sendKeys("vinothselvam070@gmail.com");
driver.findElement(By.id("password")).sendKeys("vnotbs01");
driver.findElement(By.xpath("//span[text()='Sign In']")).click();
wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@id='onLoadSpinner']/img")));
}
The above one is my test class but while executing the first line of the "FirstClassYoCo", It throwing an Null pointer exception. The following one is the error statement
Starting ChromeDriver 87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280@{#355}) on port 41085
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1613131336.877][WARNING]: This version of ChromeDriver has not been tested with Chrome version 88.
Feb 12, 2021 5:32:16 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Login to the application
java.lang.NullPointerException
at org.yocotest.FirstClassYoCo.validateCurrentWeek(FirstClassYoCo.java:26)