appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 753 forks source link

bug: get java.lang.NullPointerException when start appium programmatically #2014

Closed fatahillahardhi closed 11 months ago

fatahillahardhi commented 11 months ago

Do I have the most recent component updates?

Is the component officially supported by the Appium team?

Is there an existing issue for this?

Current Behavior

I tried to run Appium programmatically and always failed because java.lang.NullPointerException

Expected Behavior

can run normally because when I used Appium 1.22.3 it can run as well

Minimal Reproducible Example

Screenshot 2023-09-13 at 5 58 09 PM

Environment

Link to Appium Logs

https://gist.github.com/fatahillahardhi/7f2023cabb07f2425342dec1eb7b1a47

Further Information

/Users/fatahillahardhi/Library/Java/JavaVirtualMachines/azul-17.0.8/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/Aqua 2023.2 EAP.app/Contents/lib/idea_rt.jar=50804:/Applications/Aqua 2023.2 EAP.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Applications/Aqua 2023.2 EAP.app/Contents/lib/idea_rt.jar:/Applications/Aqua 2023.2 EAP.app/Contents/plugins/testng/lib/testng-rt.jar:/Users/fatahillahardhi/Desktop/Automation/AppiumJavaSample/target/test-classes:/Users/fatahillahardhi/.m2/repository/io/appium/java-client/8.5.1/java-client-8.5.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-api/4.12.1/selenium-api-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/4.12.1/selenium-remote-driver-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/auto/service/auto-service-annotations/1.1.1/auto-service-annotations-1.1.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/guava/guava/32.1.2-jre/guava-32.1.2-jre.jar:/Users/fatahillahardhi/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/Users/fatahillahardhi/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/Users/fatahillahardhi/.m2/repository/org/checkerframework/checker-qual/3.33.0/checker-qual-3.33.0.jar:/Users/fatahillahardhi/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:/Users/fatahillahardhi/.m2/repository/com/google/j2objc/j2objc-annotations/2.8/j2objc-annotations-2.8.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-buffer/4.1.96.Final/netty-buffer-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-codec-http/4.1.96.Final/netty-codec-http-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-codec/4.1.96.Final/netty-codec-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-handler/4.1.96.Final/netty-handler-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-common/4.1.96.Final/netty-common-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-classes-epoll/4.1.96.Final/netty-transport-classes-epoll-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-classes-kqueue/4.1.96.Final/netty-transport-classes-kqueue-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-native-epoll/4.1.96.Final/netty-transport-native-epoll-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-native-kqueue/4.1.96.Final/netty-transport-native-kqueue-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-native-unix-common/4.1.96.Final/netty-transport-native-unix-common-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport/4.1.96.Final/netty-transport-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-resolver/4.1.96.Final/netty-resolver-4.1.96.Final.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-api/1.28.0/opentelemetry-api-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-context/1.28.0/opentelemetry-context-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-exporter-logging/1.28.0/opentelemetry-exporter-logging-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-metrics/1.28.0/opentelemetry-sdk-metrics-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-extension-incubator/1.28.0-alpha/opentelemetry-extension-incubator-1.28.0-alpha.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-logs/1.28.0/opentelemetry-sdk-logs-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-common/1.28.0/opentelemetry-sdk-common-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-extension-autoconfigure-spi/1.28.0/opentelemetry-sdk-extension-autoconfigure-spi-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-extension-autoconfigure/1.28.0/opentelemetry-sdk-extension-autoconfigure-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-api-events/1.28.0-alpha/opentelemetry-api-events-1.28.0-alpha.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk-trace/1.28.0/opentelemetry-sdk-trace-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-sdk/1.28.0/opentelemetry-sdk-1.28.0.jar:/Users/fatahillahardhi/.m2/repository/io/opentelemetry/opentelemetry-semconv/1.28.0-alpha/opentelemetry-semconv-1.28.0-alpha.jar:/Users/fatahillahardhi/.m2/repository/net/bytebuddy/byte-buddy/1.14.5/byte-buddy-1.14.5.jar:/Users/fatahillahardhi/.m2/repository/org/asynchttpclient/async-http-client/2.12.3/async-http-client-2.12.3.jar:/Users/fatahillahardhi/.m2/repository/org/asynchttpclient/async-http-client-netty-utils/2.12.3/async-http-client-netty-utils-2.12.3.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-codec-socks/4.1.60.Final/netty-codec-socks-4.1.60.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-handler-proxy/4.1.60.Final/netty-handler-proxy-4.1.60.Final.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-native-epoll/4.1.60.Final/netty-transport-native-epoll-4.1.60.Final-linux-x86_64.jar:/Users/fatahillahardhi/.m2/repository/io/netty/netty-transport-native-kqueue/4.1.60.Final/netty-transport-native-kqueue-4.1.60.Final-osx-x86_64.jar:/Users/fatahillahardhi/.m2/repository/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar:/Users/fatahillahardhi/.m2/repository/com/typesafe/netty/netty-reactive-streams/2.0.4/netty-reactive-streams-2.0.4.jar:/Users/fatahillahardhi/.m2/repository/com/sun/activation/jakarta.activation/1.2.2/jakarta.activation-1.2.2.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-http/4.12.1/selenium-http-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/dev/failsafe/failsafe/3.3.2/failsafe-3.3.2.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-json/4.12.1/selenium-json-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-manager/4.12.1/selenium-manager-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-os/4.12.1/selenium-os-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-support/4.12.1/selenium-support-4.12.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar:/Users/fatahillahardhi/.m2/repository/commons-validator/commons-validator/1.7/commons-validator-1.7.jar:/Users/fatahillahardhi/.m2/repository/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar:/Users/fatahillahardhi/.m2/repository/commons-digester/commons-digester/2.1/commons-digester-2.1.jar:/Users/fatahillahardhi/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/fatahillahardhi/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/Users/fatahillahardhi/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar:/Users/fatahillahardhi/.m2/repository/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar:/Users/fatahillahardhi/.m2/repository/org/slf4j/slf4j-api/2.0.7/slf4j-api-2.0.7.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-java/4.9.1/selenium-java-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/4.9.1/selenium-chrome-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/auto/service/auto-service/1.0.1/auto-service-1.0.1.jar:/Users/fatahillahardhi/.m2/repository/com/google/auto/auto-common/1.2/auto-common-1.2.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-chromium-driver/4.9.1/selenium-chromium-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-devtools-v111/4.9.1/selenium-devtools-v111-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-devtools-v112/4.9.1/selenium-devtools-v112-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-devtools-v113/4.9.1/selenium-devtools-v113-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-devtools-v85/4.9.1/selenium-devtools-v85-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/4.9.1/selenium-edge-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/4.9.1/selenium-firefox-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/4.9.1/selenium-ie-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/4.9.1/selenium-safari-driver-4.9.1.jar:/Users/fatahillahardhi/.m2/repository/org/testng/testng/7.7.1/testng-7.7.1.jar:/Users/fatahillahardhi/.m2/repository/com/beust/jcommander/1.82/jcommander-1.82.jar:/Users/fatahillahardhi/.m2/repository/org/webjars/jquery/3.6.1/jquery-3.6.1.jar:/Users/fatahillahardhi/.m2/repository/io/github/bonigarcia/webdrivermanager/5.3.2/webdrivermanager-5.3.2.jar:/Users/fatahillahardhi/.m2/repository/com/github/docker-java/docker-java/3.2.14/docker-java-3.2.14.jar:/Users/fatahillahardhi/.m2/repository/com/github/docker-java/docker-java-core/3.2.14/docker-java-core-3.2.14.jar:/Users/fatahillahardhi/.m2/repository/com/github/docker-java/docker-java-api/3.2.14/docker-java-api-3.2.14.jar:/Users/fatahillahardhi/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.10.3/jackson-annotations-2.10.3.jar:/Users/fatahillahardhi/.m2/repository/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar:/Users/fatahillahardhi/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.10.3/jackson-databind-2.10.3.jar:/Users/fatahillahardhi/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.10.3/jackson-core-2.10.3.jar:/Users/fatahillahardhi/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.64/bcpkix-jdk15on-1.64.jar:/Users/fatahillahardhi/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.64/bcprov-jdk15on-1.64.jar:/Users/fatahillahardhi/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.30/jcl-over-slf4j-1.7.30.jar:/Users/fatahillahardhi/.m2/repository/com/github/docker-java/docker-java-transport-httpclient5/3.2.14/docker-java-transport-httpclient5-3.2.14.jar:/Users/fatahillahardhi/.m2/repository/com/github/docker-java/docker-java-transport/3.2.14/docker-java-transport-3.2.14.jar:/Users/fatahillahardhi/.m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar:/Users/fatahillahardhi/.m2/repository/org/brotli/dec/0.1.2/dec-0.1.2.jar:/Users/fatahillahardhi/.m2/repository/org/apache/httpcomponents/client5/httpclient5/5.2.1/httpclient5-5.2.1.jar:/Users/fatahillahardhi/.m2/repository/org/apache/httpcomponents/core5/httpcore5/5.2/httpcore5-5.2.jar:/Users/fatahillahardhi/.m2/repository/org/apache/httpcomponents/core5/httpcore5-h2/5.2/httpcore5-h2-5.2.jar com.intellij.rt.testng.RemoteTestNGStarter -usedefaultlisteners false -socket50803 @w@/private/var/folders/jj/56gfzdnx3ndd258xtjxrzr4c0000gp/T/idea_working_dirs_testng.tmp -temp /private/var/folders/jj/56gfzdnx3ndd258xtjxrzr4c0000gp/T/idea_testng.tmp
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Start local Appium server

java.lang.NullPointerException
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:226)
    at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:184)
    at org.openqa.selenium.remote.service.DriverService$Builder.getLogOutput(DriverService.java:448)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:495)
    at com.eot.sample.Hooks.startAppiumServer(Hooks.java:20)
    at com.eot.sample.ios.AppiumNativeiOSHelloWorldTest.beforeAll(AppiumNativeiOSHelloWorldTest.java:23)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:376)
    at org.testng.SuiteRunner.run(SuiteRunner.java:330)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
    at org.testng.TestNG.runSuites(TestNG.java:1099)
    at org.testng.TestNG.run(TestNG.java:1067)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)

Test ignored.

===============================================
Default Suite
Total tests run: 1, Passes: 0, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 3
===============================================

Process finished with exit code 0

here's my code

public static void startAppiumServer() {
        System.out.println(String.format("Start local Appium server"));
        new AppiumServiceBuilder()
                .usingAnyFreePort()
                .usingDriverExecutable(new File("/usr/local/bin/node"))
                .withArgument(GeneralServerFlag.RELAXED_SECURITY)
                .build()
                .start();
}
Screenshot 2023-09-13 at 6 10 30 PM
qubui commented 11 months ago

I got the same issue with Android, is there any solution? please help me

ashwithpoojary98 commented 11 months ago

@fatahillahardhi and @qubui add a log file in the Appium service builder it will resolve new AppiumServiceBuilder() .usingAnyFreePort() .usingDriverExecutable(new File("/usr/local/bin/node")) .withLogFile(new File(System.getProperty("user.dir")+"appium.log")) .withArgument(GeneralServerFlag.RELAXED_SECURITY) .build() .start();

The below code will resolve the issue .withLogFile(new File(System.getProperty("user.dir")+"appium.log"))

qubui commented 11 months ago

Thanks a lot @ashwithpoojary98, you are my life saver :).

qubui commented 11 months ago

I need one more help that how to run test with real device for android and on browserStack, @ashwithpoojary98 do you have any hint?

ashwithpoojary98 commented 11 months ago

@qubui, For Android, you can connect your real device and enable the developer option on your phone. Then, you can start executing the test cases. However, for iOS, you need extra configuration to run the test cases on real devices. BrowserStack is similar to local execution, but you need to change the URL and add an app, username, and passkey to the capabilities.

qubui commented 11 months ago

@ashwithpoojary98 Do you have a code for these?

manikantp commented 11 months ago

.withLogFile(new File(System.getProperty("user.dir")+"appium.log"))

What does this line exactly do @ashwithpoojary98 This line fixed the problem somehow

ashwithpoojary98 commented 11 months ago

@manikantp issue with the Selenium Build log file, and it was recently fixed. Before, it was checking for the file in a default location that does not exist.

manikantp commented 11 months ago

@manikantp issue with the Selenium Build log file, and it was recently fixed. Before, it was checking for the file in a default location that does not exist.

Oh that's why I thought why is the code behaving like this 😅. Thanks by the way 👍. This helped a lot

valfirst commented 11 months ago

Duplicate of #2004