<path>处的应用程序不存在或无法使用Appium访问

时间:2019-05-30 12:34:50

标签: appium appium-android

我正在使用Eclipse学习appium,并被困在启动模拟器上。我尝试了其他操作,例如在文件夹结构中移动文件,但是我一直在获取文件不存在或无法访问的信息。我尝试搜索答案,但没有任何帮助。

package myAppiumTutorial;

import java.io.File;
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.MobileCapabilityType;

public class Base {

    public static void main(String[] args) throws MalformedURLException {
        // TODO Auto-generated method stub
        File f = new File("scr");
        File fs = new File(f,"ApiDemos-debug.apk");
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "MyFirstEmu");
        cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
        AndroidDriver<AndroidElement> driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);

来自appium的日志

[Appium] Setting automation to 'UiAutomator1'.
[Appium] Appium v1.13.0 creating new AndroidDriver (v4.15.1) session
[Appium] Capabilities:
[Appium]   platformName: android
[Appium]   app: C:\Users\Zamranj\eclipse-workspaceNew\AppiumIntro\scr\ApiDemos-debug.apk
[Appium]   deviceName: MyFirstEmu
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"app":"C:\\Users\\Zamranj\... were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 638fc0a9-1aa0-4b56-ba69-3c854b8e1816
[ADB] Found 1 'build-tools' folders under 'C:\Users\Zamranj\AppData\Local\Android\Sdk' (newest first):
[ADB]     C:/Users/Zamranj/AppData/Local/Android/Sdk/build-tools/28.0.3
[ADB] Using 'adb.exe' from 'C:\Users\Zamranj\AppData\Local\Android\Sdk\platform-tools\adb.exe'
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[ADB] Using 'adb.exe' from 'C:\Users\Zamranj\AppData\Local\Android\Sdk\platform-tools\adb.exe'
[debug] [ADB] Setting device id to emulator-5554
[debug] [ADB] Running 'C:\Users\Zamranj\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 25
[debug] [ADB] Device API level: 25
[AndroidDriver] Consider setting 'automationName' capability to 'uiautomator2' on Android >= 6, since UIAutomator framework is not maintained anymore by the OS vendor.
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
[debug] [ADB] Running 'C:\Users\Zamranj\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop io.appium.unlock'
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1559218980295 (07:23:00 GMT-0500 (Central Daylight Time))
[debug] [W3C] Encountered internal error running command: Error: The application at 'C:\Users\Zamranj\eclipse-workspaceNew\AppiumIntro\scr\ApiDemos-debug.apk' does not exist or is not accessible
[debug] [W3C]     at APPLICATIONS_CACHE_GUARD.acquire (C:\Users\Zamranj\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\helpers.js:159:13)
[HTTP] <-- POST /wd/hub/session 500 2956 ms - 835
[HTTP]

我的APK的位置

enter image description here

1 个答案:

答案 0 :(得分:0)

我相信您的问题在于您尝试加载文件的方式。

请尝试以下操作:

File f = new File(classLoader.getResource("ApiDemos-debug.apk").getFile());

也请查看以下内容: