Appium Java TestNG Framework>Launch Appium programatically via Mac null point exception with appium main.js file
Appium Java TestNG Framework>Launch Appium programatically via Mac null point exception with appium main.js file
Mac book air
Java 1.8
Appium Desktop version 1.8.1
Hi Guys,
I am building a TestNG framework and and I want to start my appium Desktop server programmatically for my tests. So what I decided to do was to create a java test class to invoke appium for me, I thought I'd coded it ok but when I ran it just to check. Got a 'null point exception'
'null point exception'
1. What did I do wrong?
2. How do I fix this?
Here is the launch appium programmatically code:
package aappiumLaunchServer;
import java.io.File;
import io.appium.java_client.service.local.AppiumServiceBuilder;
public class LaunchAppium
private static AppiumServiceBuilder service;
public static void main(String args)
//text
stopAppium();
startAppium();
stopAppium();
public static void startAppium()
System.out.println("Start Appium Server");
service = new AppiumServiceBuilder().usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js "));
service.build().start();
System.out.println("You can now use Appium Server");
public static void stopAppium()
System.out.println("Appium Server is shutting down....");
try
service.build().stop();
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Your current appium session is terminated... ");
System.out.println(" Appium Server has shut down. Thank you for using Appium Server");
Here is the message from eclipse
appium Server is shutting down....
java.lang.NullPointerExceptionYour current appium session is terminated...
Appium Server has shut down. Thank you for using Appium Server
Start Appium Server
at aappiumLaunchServer.LaunchAppium.stopAppium(LaunchAppium.java:44)
at aappiumLaunchServer.LaunchAppium.main(LaunchAppium.java:16)
Exception in thread "main" io.appium.java_client.service.local.InvalidServerInstanceException: Invalid server instance exception has occured: The invalid appium node /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js has been defined
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeStructure(AppiumServiceBuilder.java:102)
at io.appium.java_client.service.local.AppiumServiceBuilder.checkAppiumJS(AppiumServiceBuilder.java:294)
at io.appium.java_client.service.local.AppiumServiceBuilder.createArgs(AppiumServiceBuilder.java:389)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:342)
at aappiumLaunchServer.LaunchAppium.startAppium(LaunchAppium.java:29)
at aappiumLaunchServer.LaunchAppium.main(LaunchAppium.java:17)
Caused by: java.io.IOException: The node /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js doesn't exist
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeStructure(AppiumServiceBuilder.java:104)
... 5 more
2 Answers
2
Just with the debug mode at startAppium method try to create a file instance
new File ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js "
This will probably show you that it can not find the file
You can place a breakpoint in your code and stop there to see if you can create a file instance
– rastaman
Aug 23 at 13:18
Add these lines in beginning of code and check File file = new File ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js "); syso(file.getPath()); syso(file.getAbsolutePath()); syso(file.getCanonicalPath());
– Amit Jain
Aug 23 at 13:35
@Amit thanks man I will try this and get back to you.
– fypnlp
Aug 23 at 14:03
It seems you are trying to use JS main.js file from Appium.app instead install appium using node and you should find your file under
Appium_MAIN_JS = System.getenv(APPIUM_HOME)+"/node_modules/appium/build/lib/main.js" (define APPIUM_HOME in your bash_profile)
It's possible that your code does not have access to reach Appium.app (I presume it is in Application folder)
and then you can call
.buildService(new AppiumServiceBuilder().withAppiumJS(new File(Appium_MAIN_JS)))
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What specifically should I debug? I don't know what I need to debug to fix it. The file does exist because I was able to locate it and copy it location into terminal which I then copied into the test class. So I don't know why its saying it can't find it because its exists.
– fypnlp
Aug 23 at 12:58