Null pointer exception while running testng.xml with groups tag
See original GitHub issuepackage com.qa.tc;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class GroupTest {
WebDriver driver;
@BeforeMethod
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "D:\\Girish\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://opensource-demo.orangehrmlive.com/");
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
@Test(groups= {"Smoke"})
public void signIntest()
{
driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("Admin");
driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("admin123");
driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
System.out.println(driver.getTitle());
}
@AfterMethod
public void tearDown()
{
driver.close();
}
}
Testng xml as below
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Sample test Suite">
<test name = "Sample test">
<groups>
<run>
<include name = "Smoke" />
</run>
</groups>
<classes>
<class name = "com.qa.tc.GroupTest" />
</classes>
</test>
</suite>
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
NPE error when running TestNg test groups using eclipse
I am trying to run a Test group in TestNG by right clicking on TestNG.xml as a test suite and get below Error....
Read more >Failed Test due to NullPointerException - Google Groups
I was wondering why group "init" is nonexistent. I defined it in my test class and testng.xml. Can TestNG read groups and methods...
Read more >Are You Getting NullPointerException For Second TestNG ...
I encounter Null pointer exception when using @BeforeTest, @BeforeMethod and trying to run two classes from testng.xml.
Read more >Documentation - TestNG
You can also define new groups inside testng.xml and specify additional details in attributes, such as whether to run the tests in parallel,...
Read more >TestNG.java.lang.NullPointerException running second @Test
It seems like you never apply the PageFactory on this class. Therefore, when trying the line profile.click() the variable is null (because never ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The second sample you shared doesn’t have anything that can trigger your NPE.
The original sample that you shared, triggers an NPE because of a problem in your code.
Your
WebDriver
instantiation is being done via the@BeforeMethod
annotation. But you are choosing to run tests via groups calledSmoke
to which you haven’t added your@BeforeMethod
method and you haven’t added thealwaysRun=true
attribute also. So your@BeforeMethod
is not getting executed.To fix the problem, either add
alwaysRun=true
or addSmoke
group to your@BeforeMethod
Thanks @krmahadevan It worked when used alwaysRun=true attribute in @BeforeMethod annotation