Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting null pointer in Before methods #533

Closed
saran1992 opened this issue Aug 16, 2019 · 9 comments
Closed

Getting null pointer in Before methods #533

saran1992 opened this issue Aug 16, 2019 · 9 comments

Comments

@saran1992
Copy link

This is my test class. Am I missing anything?

public class LoginTests{

LoginPage login;

@BeforeClass
public void dataSetup() throws IOException, InterruptedException {
	login = new LoginPage(AppiumDriverManager.getDriver());
	login.login("Login URL");
}

@Test(groups = "Parallel")
public void loginWithValidUser() throws InterruptedException, IOException {
	login = new LoginPage(AppiumDriverManager.getDriver());
	Assert.assertTrue(login.isUserLoggedIn());
}

@Test(groups = "Parallel")
public void logOut() throws InterruptedException, IOException {
	login = new LoginPage(AppiumDriverManager.getDriver());
	Assert.assertTrue(login.isUserLoggedIn());
}

}

Error log:
java.lang.NullPointerException
at com.appium.manager.TestLogger.endLogging(TestLogger.java:68)
at com.appium.manager.AppiumParallelTestListener.afterInvocation(AppiumParallelTestListener.java:84)
at org.testng.internal.invokers.InvokedMethodListenerInvoker$InvokeAfterInvocationWithoutContextStrategy.callMethod(InvokedMethodListenerInvoker.java:100)
at org.testng.internal.invokers.InvokedMethodListenerInvoker.invokeListener(InvokedMethodListenerInvoker.java:62)
at org.testng.internal.Invoker.runInvokedMethodListeners(Invoker.java:566)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:545)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:414)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

@saikrishna321
Copy link
Member

You can't use @BeforeClass in your test as ATD implements ITestListners you need to create your Listener and add it from config.properties

@saran1992
Copy link
Author

Thanks for the quick response @saikrishna321
If possible, can you please post any example in this thread where driver is invoked in before method using ATD?

@saikrishna321
Copy link
Member

@saran1992 I found something needs to be changed to get this working.

Marking this as a bug

@saikrishna321
Copy link
Member

saikrishna321 commented Aug 26, 2019

@saran1992 Fix in master

Currently, we only support using @BeforeMethod and @AfterMethod for setting test status and any setup that needs to be setUp globally will get into Listeners which be part of #540

https://github.com/AppiumTestDistribution/PageObjectPatternAppium/blob/13c01f46ab584f0a5266932623e4e6098e5cddd0/src/test/java/com/appium/tests/LoginTest.java#L20-L24

@saran1992
Copy link
Author

saran1992 commented Aug 27, 2019

Hi @saikrishna321 ,

The fix works fine when we run a single class from Runner.java
However, when there are multiple classes added, we get the following exception:

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:125)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:46)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.HasSessionDetails.getSessionDetails(HasSessionDetails.java:39)
at io.appium.java_client.HasSessionDetails.getSessionDetail(HasSessionDetails.java:56)
at io.appium.java_client.HasSessionDetails.getPlatformName(HasSessionDetails.java:65)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.(AppiumFieldDecorator.java:96)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.(AppiumFieldDecorator.java:144)
at com.appium.pages.LoginPage.(LoginPage.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:414)
at org.testng.internal.thread.ThreadUtil$1.call(ThreadUtil.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

@saikrishna321
Copy link
Member

at com.appium.pages.LoginPage.(LoginPage.java:20)

What's happening in this ??

@saran1992
Copy link
Author

public LoginPage(AppiumDriver driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver), loginPageObjects);
}

@saikrishna321
Copy link
Member

@saran1992 I'm unable to reproduce.

@saikrishna321
Copy link
Member

Fixed in v11.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants