Error when i try to execute selendroid command

随声附和 提交于 2019-12-12 04:39:38

问题


i've read some tutorials on the internet, and i don't know if i'm doing all right.

I wrote this method, when i click in some button of my android application I hope that my click in this button will be able to open the android browser and acess google.

Code:

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");		
		
	}

}

after this step, i placed the selendroid .jar in the same directory of my project apk and i tried this command:

java -jar selendroid-standalone-0.15.0

-with-dependencies.jar -app AndroidApp.apk

After this command, i receive some error ->

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>

-------------UPDATED-------------------

AFTER updating as system variables , THEN Everything worked .

I managed to run the server !!!

But now , when I click the button that calls the function "TRABALHA" Then the application simply terminates .

-----UPDATED------------

This is the logcat output when the app crash.

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:


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

Try to set ANDROID_HOME by cmd as I also had the same problem while starting server initially but while Getting Started with Selendroid they had given a link to set ANDROID_HOME variable which sets it via cmd.



来源:https://stackoverflow.com/questions/29688884/error-when-i-try-to-execute-selendroid-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!