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

我写了这个方法,当我单击我的android应用程序的某个按钮时,希望我单击此按钮将能够打开android浏览器和acess google。

码:



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>





- - - - - - -更新 - - - - - - - - - -

更新为系统变量之后,一切正常。

我设法运行服务器!

但是现在,当我单击调用函数“ TRABALHA”的按钮时,应用程序将简单地终止。



- - -更新 - - - - - -

这是应用程序崩溃时的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

最佳答案

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进行设置。

10-07 17:01