操作系统:Mac Appium桌面1.6.2 Java 1.8 App --- Native ---- Android
嗨,
最近几天,这一直使我发疯。
我想要的功能似乎是 正确 。
我在Android设备上启用了调试功能
我可以通过adb设备看到我的设备
但是,当我运行代码时,我得到了
An unknown server-side error occurred while processing the command.
所以我去了this link,然后把它放在字母后面,正确地添加了信息,仍然收到相同的错误消息。
我完全困惑。有人可以帮助我启动我的移动设备上已安装的应用程序吗?
(注意:出于安全原因修改了设备和IP地址)
以下是所需的功能:
软件包基础;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
public class AndroidDevice {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "420XXXXXXXXXX");
cap.setCapability(MobileCapabilityType.VERSION, "5.1.1");
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.pintrest");
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, ".activity.PinterestActivity ");
AndroidDriver<AndroidElement> driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
//com.pinterest/.activity.PinterestActivity
}
这是蚀的打印输出
Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find package com.skype.raider.Main on the device (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.23 seconds
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:22.379Z'
System info: host: 'Jacquelines-MacBook-Air.local', ip: '100.100.0.0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_71'
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:83)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:93)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:72)
at basics.AndroidDevice.main(AndroidDevice.java:25)enter code here
最后,Appium桌面
[info] [Appium] Welcome to Appium v1.8.1
[info] [Appium] Appium REST http interface listener started on 0.0.0.0:4723[info] [HTTP] --> POST /wd/hub/session
[info] [HTTP] {"desiredCapabilities":{"appActivity":".activityPintestActivity","appPackage":"com.pintrest","deviceName":"Android device","newCommandTimeout":"25","platformName":"Android"},"capabilities":{"desiredCapabilities":{"appActivity":".activityPintestActivity","appPackage":"com.pintrest","deviceName":"Android device","newCommandTimeout":"25","platformName":"Android"},"firstMatch":[{"platformName":"android"}]}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":".activityPintestActivity","appPackage":"com.pintrest","deviceName":"Android device","newCommandTimeout":"25","platformName":"Android"},null,{"desiredCapabilities":{"appActivity":".activityPintestActivity","appPackage":"com.pintrest","deviceName":"Android device","newCommandTimeout":"25","platformName":"Android"},"firstMatch":[{"platformName":"android"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1531662783699 (14:53:03 GMT+0100 (BST))
[warn] [Appium] Could not parse W3C capabilities: 'deviceName' can't be blank. Falling back to JSONWP protocol.
[warn] [Appium] The following capabilities were provided in the JSONWP desired capabilities that are missing in W3C capabilities: ["appActivity","appPackage","deviceName","newCommandTimeout","platformName"]. Falling back to JSONWP protocol.
[info] [Appium] Creating new AndroidDriver (v2.7.0) session
[info] [Appium] Capabilities:
[info] [Appium] appActivity: .activityPintestActivity
[info] [Appium] appPackage: com.pintrest
[info] [Appium] deviceName: Android device
[info] [Appium] newCommandTimeout: 25
[info] [Appium] platformName: Android
[debug] [BaseDriver] Creating session with MJSONWP desired capabilities: {"appActivity":".activityPi...
[warn] [BaseDriver] Capability 'newCommandTimeout' changed from string ('25') to integer (25). This may cause unexpected behavior
[info] [BaseDriver] Session created with session id: d423599b-1e41-47b9-8f88-bca2f4cde044
[debug] [AndroidDriver] Getting Java version
[info] [AndroidDriver] Java version is: 1.8.0_71
[info] [AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[info] [AndroidDriver] Using device: 4200000002400
[debug] [ADB] Setting device id to 4200000000400
[info] [AndroidDriver] App file was not listed, instead we're going to run com.pintrest directly on the device
[debug] [AndroidDriver] Checking whether package is present on the device
[debug] [ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s 420015649a5e2400 shell pm list packages com.pintrest'[error] [AndroidDriver] Error: Could not find package com.pintrest on the device
[error] [AndroidDriver] at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[error] [AndroidDriver] at AndroidDriver.checkPackagePresent$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/driver.js:346:11)
[error] [AndroidDriver] at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[error] [AndroidDriver] at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[error] [AndroidDriver] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js10021)
[error] [AndroidDriver] at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[error] [AndroidDriver] at
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
[debug] [ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s 420015649a5e2400 shell am force-stop io.appium.unlock'[debug] [AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1531662785119 (14:53:05 GMT+0100 (BST))
[error] [MJSONWP] Encountered internal error running command: Error: Could not find package com.pintrest on the device
[error] [MJSONWP] at Object.wrappedLogger.errorAndThrow (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[error] [MJSONWP] at AndroidDriver.checkPackagePresent$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-driver/lib/driver.js:346:11)
[error] [MJSONWP] at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[error] [MJSONWP] at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[error] [MJSONWP] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js10021)
[error] [MJSONWP] at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[error] [MJSONWP] at
[info] [HTTP] <-- POST /wd/hub/session 500 1425 ms - 186
[info] [HTTP]
答案 0 :(得分:0)
您(按代码提供)已重复:APP_PACKAGE,尽管2.参数为APP_ACTIVITY
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.pintrest");
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, ".activity.PinterestActivity ");
来自跟踪
[debug] [ADB] Running '/Users/jacquelinegeorge/Library/Android/sdk/platform-tools/adb -P 5037 -s 420015649a5e2400 shell pm list packages com.pintrest'[error] [AndroidDriver] Error: Could not find package com.pintrest on the device
打开应用程序,并检查应用程序是否与该软件包一起安装:
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
与此相关,您可以获得包的名称和活动
希望这会有所帮助,
答案 1 :(得分:0)
解决方案:
代码在这里,很明显地注意到问题是您赋予了相同的所需功能参数“ APP_PACKAGE”。
现在正确的能力参数如下:
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,“ com.pintrest”); cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,“ .activity.PinterestActivity”);
验证:
可能是您无法获取应用详细信息,只需按照以下命令明确获取并检查应用详细信息即可。
获取应用程序详细信息:adb shell dumpsys window windows | grep -E'mCurrentFocus | mFocusedApp'
要验证该应用程序是否可以成功移至cmd以上,以获取该应用程序的详细信息。
“ adb shell开始-n Apppackage / AppActivity”
现在,该应用成功启动,表明“应用详细信息”应该正确。 否则,请使用Apkdemo应用程序查找AppPackage,AppActivity并使用上述cmd通过每个活动进行验证。
以下应用程序对于自动化移动应用程序非常有用。 尝试:https://app.testsigma.com