0

I'm trying to execute @Test outside the throw exception method. The only way I can be able to execute the @Test methods is if I call them within the throws exception method and this makes the @Test methods to fail. Please see my code.

public class Communication extends WebPortalLogin       {


    public static String driverPath = "C:/";
    public static WebDriver driver;


    @BeforeTest
    public void Circulars() throws Exception  {

        ExcelUtils.setExcelFile("C://TestData//TestData.xlsx", "Sheet1");

        String username = ExcelUtils.getCellData(1, 1);   
        String password = ExcelUtils.getCellData(1, 2); 

        driver = WebPortalLogin.login(username, password);

        circulars(driver);
        option_list(driver);
        close_browser();

    }

    @Test
    public void circulars(WebDriver driver)     {

      WebPortalNGFile.communication(driver).click();
      WebPortalNGFile.circulars(driver).click();

  }

  @Test
  public void option_list(WebDriver driver)     {

    WebPortalNGFile.communication(driver).click();
    WebPortalNGFile.option_list(driver).click();

  }

  @Test
  public void close_browser()    {
      driver.close();

  }

}   
HDJEMAI
  • 9,436
  • 46
  • 67
  • 93

1 Answers1

0

In your class, the first thing that executes is your @BeforeTest method. The idea of @BeforeTest is really to have a method which executes before each @Test.

Now, for some reason you are trying to call your @Test circulars() method from your @BeforeTest method which simply won't work.

Next, why did you add @Test annotation to your close_browser() and option_list() methods? Looks like they are just helper methods and don't need @Test annotation.

Read more about @BeforeTest and @Test annotations.

Below are some vague corrections to your code that might help you.

public class Communication extends WebPortalLogin{

public static String driverPath = "C:/";
public static WebDriver driver;

@Test
public void Circulars() throws Exception{

    ExcelUtils.setExcelFile("C://TestData//TestData.xlsx", "Sheet1");

    String username = ExcelUtils.getCellData(1, 1);   
    String password = ExcelUtils.getCellData(1, 2); 

    driver = WebPortalLogin.login(username, password);

    circulars(driver);
    option_list(driver);
    close_browser(driver);
}

public void circulars(WebDriver driver){
    WebPortalNGFile.communication(driver).click();
    WebPortalNGFile.circulars(driver).click();
}

public void option_list(WebDriver driver){
    WebPortalNGFile.communication(driver).click();
    WebPortalNGFile.option_list(driver).click();
}

public void close_browser(WebDriver driver){
    driver.close();
} }
sen4ik
  • 407
  • 4
  • 16
  • Hi sen4ik,Circular() is set_up() actually and the close_browser() is an AfterTest because it terminates the browser. circulars() and option_list() are tests hence the annotation @Test, I need them to be listed individually on the report that's why they have to run as individual methods and not be called inside the exception method. – Thabiso Ditabe Jun 13 '17 at 07:32