0

In the below code i am trying to automate gmail by data driven frame work using TestNg , but my code @Before annotation only executing not other two .Please healp me.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class LoginData  {
WebDriver driver;
  @Test
  public void login() {

      driver.findElement(By.linkText("Sign in")).click();
      System.out.println("hello");
  }
  @BeforeTest
  public void beforeTest() throws Exception  {
      WebDriver driver=new FirefoxDriver();
      driver.get("https://www.gmail.com/intl/en/mail/help/about.html");
      Thread.sleep(2000);


  }

  @AfterTest
  public void fterTest() {
      driver.close();

  }

}

1 Answers1

0

Since you have declared WebDriver driver already; remove Webdriver from WebDriver driver==new FirefoxDriver();

I tried below and worked for me.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class LoginData1  {
WebDriver driver;


@Test
public void login() {

    driver.findElement(By.linkText("Sign in")).click();
    System.out.println("hello");
}
@BeforeTest
public void beforeTest() throws Exception  {
    driver=new FirefoxDriver();
    driver.get("https://www.gmail.com/intl/en/mail/help/about.html");
    Thread.sleep(2000);


}

@AfterTest
public void fterTest() {
    driver.close();

}
}

Accept if it works for you or let me know if this does not work... Thanks

Andy
  • 301
  • 2
  • 9