我尝试执行selendroid命令时出错

时间:2015-04-17 01:52:41

标签: java selenium selendroid

我已经在互联网上阅读了一些教程,而且我不知道我是否做得很好。

我写了这个方法,当我点击我的Android应用程序的某个按钮时,我希望我在这个按钮上的点击将能够打开Android浏览器和访问谷歌。

代码:



package com.example.androidapp;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class Sel {
	
	public void Trabalha(){
		WebDriver driver = new RemoteWebDriver(DesiredCapabilities.android());
		driver.get("http://google.com");		
		
	}

}




在这一步之后,我将selendroid .jar放在我的项目apk的同一目录中,我尝试了这个命令:

java -jar selendroid-standalone-0.15.0

-with-dependencies.jar -app AndroidApp.apk

在此命令之后,我收到一些错误 - >



C:\Users\Cleiton\workspace\AndroidApp\bin>java -jar selendroid-standalone-0.15.0
-with-dependencies.jar -app AndroidApp.apk
abr 16, 2015 10:41:50 PM io.selendroid.standalone.SelendroidLauncher main
INFORMAÃıES: ################# Selendroid #################
abr 16, 2015 10:41:50 PM io.selendroid.standalone.SelendroidLauncher main
INFORMAÃıES: ################# Configuration in use #################
abr 16, 2015 10:41:50 PM io.selendroid.standalone.SelendroidLauncher main
INFORMAÃıES: io.selendroid.standalone.SelendroidConfiguration@3b07d329[
  port=4444
  timeoutEmulatorStart=300000
  supportedApps=[AndroidApp.apk]
  verbose=false
  emulatorPort=5560
  deviceScreenshot=false
  selendroidServerPort=8080
  keystore=<null>
  keystorePassword=<null>
  keystoreAlias=<null>
  emulatorOptions=<null>
  keepEmulator=false
  registrationUrl=<null>
  proxy=<null>
  serverHost=<null>
  keepAdbAlive=false
  maxSession=5
  maxInstances=5
  noWebViewApp=false
  noClearData=false
  sessionTimeoutSeconds=1800
  forceReinstall=false
  logLevel=ERROR
  deviceLog=true
  serverStartTimeout=20000
  printHelp=false
  serverStartRetries=5
  folder=<null>
]
abr 16, 2015 10:41:50 PM io.selendroid.standalone.SelendroidLauncher launchServe
r
INFORMAÃıES: Starting Selendroid standalone on port 4444
abr 16, 2015 10:41:50 PM io.selendroid.standalone.SelendroidLauncher launchServe
r
GRAVE: Error building server: Environment variable 'ANDROID_HOME' was not found!

Exception in thread "main" io.selendroid.server.common.exceptions.SelendroidExce
ption: Environment variable 'ANDROID_HOME' was not found!
        at io.selendroid.standalone.android.AndroidSdk.androidHome(AndroidSdk.ja
va:97)
        at io.selendroid.standalone.android.AndroidSdk.platformToolsHome(Android
Sdk.java:86)
        at io.selendroid.standalone.android.AndroidSdk.aapt(AndroidSdk.java:39)
        at io.selendroid.standalone.android.impl.DefaultAndroidApp.deleteFileFro
mWithinApk(DefaultAndroidApp.java:107)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.deleteFileFr
omAppSilently(SelendroidServerBuilder.java:135)
        at io.selendroid.standalone.builder.SelendroidServerBuilder.resignApp(Se
lendroidServerBuilder.java:144)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.addT
oAppsStore(SelendroidStandaloneDriver.java:121)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.init
ApplicationsUnderTest(SelendroidStandaloneDriver.java:155)
        at io.selendroid.standalone.server.model.SelendroidStandaloneDriver.<ini
t>(SelendroidStandaloneDriver.java:94)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.initialize
SelendroidServer(SelendroidStandaloneServer.java:65)
        at io.selendroid.standalone.server.SelendroidStandaloneServer.<init>(Sel
endroidStandaloneServer.java:54)
        at io.selendroid.standalone.SelendroidLauncher.launchServer(SelendroidLa
uncher.java:65)
        at io.selendroid.standalone.SelendroidLauncher.main(SelendroidLauncher.j
ava:117)

C:\Users\Cleiton\workspace\AndroidApp\bin>
&#13;
&#13;
&#13;

-------------修订-------------------

作为系统变量更新后,那么一切正常。

我设法运行服务器!!!

但现在,当我点击调用该功能的按钮&#34; TRABALHA&#34;然后应用程序就会终止。

enter image description here

- - - - 修订------------

这是应用程序崩溃时的logcat输出。

04-21 16:40:53.602: E/AndroidRuntime(1092): FATAL EXCEPTION: main
04-21 16:40:53.602: E/AndroidRuntime(1092): Process: com.example.androidapp, PID: 1092
04-21 16:40:53.602: E/AndroidRuntime(1092): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/openqa/selenium/remote/RemoteWebDriver;
04-21 16:40:53.602: E/AndroidRuntime(1092):     at com.example.androidapp.Sel.Trabalha(Sel.java:10)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at com.example.androidapp.MainActivity.onClick(MainActivity.java:48)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.view.View.performClick(View.java:4780)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.view.View$PerformClick.run(View.java:19866)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.os.Handler.handleCallback(Handler.java:739)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.os.Handler.dispatchMessage(Handler.java:95)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.os.Looper.loop(Looper.java:135)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at android.app.ActivityThread.main(ActivityThread.java:5257)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at java.lang.reflect.Method.invoke(Native Method)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at java.lang.reflect.Method.invoke(Method.java:372)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
04-21 16:40:53.602: E/AndroidRuntime(1092): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.openqa.selenium.remote.RemoteWebDriver" on path: DexPathList[[zip file "/data/app/com.example.androidapp-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
04-21 16:40:53.602: E/AndroidRuntime(1092):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-21 16:40:53.602: E/AndroidRuntime(1092):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
04-21 16:40:53.602: E/AndroidRuntime(1092):     ... 12 more
04-21 16:40:53.602: E/AndroidRuntime(1092):     Suppressed: java.lang.ClassNotFoundException: org.openqa.selenium.remote.RemoteWebDriver
04-21 16:40:53.602: E/AndroidRuntime(1092):         at java.lang.Class.classForName(Native Method)
04-21 16:40:53.602: E/AndroidRuntime(1092):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
04-21 16:40:53.602: E/AndroidRuntime(1092):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
04-21 16:40:53.602: E/AndroidRuntime(1092):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
04-21 16:40:53.602: E/AndroidRuntime(1092):         ... 13 more
04-21 16:40:53.602: E/AndroidRuntime(1092):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

1 个答案:

答案 0 :(得分:2)

set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

尝试按cmd设置ANDROID_HOME,因为我在最初启动服务器时遇到了同样的问题但是Getting Started with Selendroid他们已经给出了设置ANDROID_HOME变量的链接,该变量通过cmd设置它。