麦克书空气
Java 1.8
Appium 桌面版 1.8.1
嗨,大家好,
我正在构建一个 TestNG 框架,并且我想以编程方式启动我的 appium 桌面服务器以进行测试。所以我决定做的是创建一个java测试类来为我调用appium,我以为我已经编码好了,但是当我运行它只是为了检查。有一个 'null point exception'
1. 我做错了什么?
2. 我该如何解决这个问题?
这是以编程方式启动appium的代码:
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");
}
}
这是来自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