In TestNG only BeforeTest is executing not test and AfterTest And it shows error this driver is null

0 votes
import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class NewTest {
    public WebDriver driver;
    
    @BeforeTest
    public void setupTest() {
        WebDriverManager.chromedriver().setup();
        WebDriver driver = new ChromeDriver();
        
    }
    
    @Test
    public void googleSearch() {    
        
        driver.get("https://www.google.com");
        driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
        
        WebElement searchBox = driver.findElement(By.name("q"));
        WebElement searchButton = driver.findElement(By.name("btnK"));
        
        searchBox.sendKeys("Selenium");
        searchBox.sendKeys(Keys.ENTER);
        //searchButton.click();
        
        searchBox = driver.findElement(By.name("q"));
        searchBox.getAttribute("value"); // => "Selenium"

    }
    
    @AfterTest
    public void tearDownTest() {
           driver.close();
           System.out.println("Successfull, Run the test");
    }
        
               
}
Aug 30, 2022 in Java by Mian

edited 5 days ago 6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP