RE: Using testNG Framework


This code works but now that I’m using¬† TestNG it doesn’t.¬† it seems that only the code in the @BeforeMethod works. as if nothing is passed the @Test. If I put all the code in the @BeforeMethod it runs.


package FrameWork;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.AfterMethod;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;



import org.testng.annotations.Test;
public class NewTest {

public WebDriver driver;
publicvoid main() {
//Setting Variables
String strUsername = "name";

String strPassword = "PW";

String strAccountname = "new";
WebElement txtTwtelecomLogin = driver.findElement(By.className("apbutton"));;
WebElement txtUsername = driver.findElement("tbUserName"));
WebElement txtPassword = driver.findElement("tbPassword"));
WebElement txtLogin = driver.findElement("btnLogin"));
publicvoid beforeMethod() {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Navigate to Test A
publicvoid afterMethod() {

Richard Allen Train Asked on September 30, 2014 in Selenium WebDriver.
Add Comment
4 Answers
Best answer

The issue was that I should have been using @beforeTest and @afterTest. rather than @beforeMethod and @afterMethod.

Train Answered on October 10, 2014.

What is/are the difference you found? using different annotation. Also please check your own comments and answers.

My solution was very simply you can see in my answer (driver = new ChromeDriver(); //Chanhe is in this line (Removed WebDriver).).

And use your solution above (The issue was that I should have been using @beforeTest and @afterTest. rather than @beforeMethod and @afterMethod.) in your code without using my solution (driver = new ChromeDriver(); //Chanhe is in this line (Removed WebDriver).) and let us know?

Happy coding.

on October 12, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.