Mac book air
Java 1.8
Appium桌面版本1.8.1
嗨,
我正在构建一个TestNG框架,并且我想以编程方式启动我的appium Desktop服务器进行测试。所以我决定要做的是创建一个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");
}
}
这是日食的消息
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
答案 0 :(得分:1)
只需在startAppium方法的调试模式下尝试创建文件实例
new File ("/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js "
这可能会告诉您找不到文件
答案 1 :(得分:0)
似乎您正在尝试使用Appium.app中的JS main.js文件,而不是使用node安装appium,您应该在
下找到文件
Appium_MAIN_JS = System.getenv(APPIUM_HOME)+“ / node_modules / appium / build / lib / main.js”(在bash_profile中定义APPIUM_HOME)
您的代码可能无权访问Appium.app(我认为它位于Application文件夹中)
然后您可以致电 .buildService(new AppiumServiceBuilder()。withAppiumJS(new File(Appium_MAIN_JS)))
答案 2 :(得分:0)
如果从Windows的安装中安装了NodeJS,并且\ AppData \ Roaming \ npm为空,则应打开Windows PowerShell并运行命令: npm install -g appium