错误:新应用路径没有扩展.apk

Error: New app path did not have extension .apk

提问人:Snusovic 提问时间:2/26/2021 更新时间:2/28/2021 访问量:759

问:

尝试学习 Appium 并运行一些我在运行 Maven 项目时无法真正弄清楚的问题,并想看看我是否可以执行 java 应用程序。

执行 Java 应用程序时,它会抱怨 apk 文件。apk文件位于“src”文件夹中(见附图),我输入了正确的路径。 原始错误:新应用路径“C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src”没有扩展名:.apk,.apks

    ******MY CODE:******

public class main {

public static AndroidDriver<AndroidElement> Capabilities(String appName) throws IOException {
        
        
//      System.getProperty("user.dir");
        FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "\\src\\main\\java\\practise\\AppiumFramework\\global.properties");
        Properties prop = new Properties();
        prop.load(fis);
    
        AndroidDriver<AndroidElement>  driver;
        File appDir = new File("src");
        File app = new File(appDir, (String) prop.get(appName));
        
        DesiredCapabilities cap = new DesiredCapabilities(); 
        
        String device = (String) prop.get("device");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME,"device");
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 14);
        cap.setCapability(MobileCapabilityType.APP, appDir.getAbsolutePath());
        driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        
        return driver;
        
    } 

}





**CONSOLE OUTPUT**:   
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: New app path 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src' did not have extensions: .apk,.apks
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'LAPTOP-PDE95IER', ip: '192.168.1.24', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
    Driver info: driver.version: AndroidDriver
    remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: New app path 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src' did not have extensions: .apk,.apks
        at getResponseForW3CError (C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
        at asyncHandler (C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37)
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'LAPTOP-PDE95IER', ip: '192.168.1.24', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
    Driver info: driver.version: AndroidDriver
        at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
        at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        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:213)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
        at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:95)
        at practise.AppiumFramework.main.Capabilities(main.java:37)
        at practise.AppiumFramework.ecommerc_tc_4.main(ecommerc_tc_4.java:18)
    Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
        ... 14 more
    Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: New app path 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src' did not have extensions: .apk,.apks
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'LAPTOP-PDE95IER', ip: '192.168.1.24', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
    Driver info: driver.version: AndroidDriver
    remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: New app path 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src' did not have extensions: .apk,.apks
        at getResponseForW3CError (C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
        at asyncHandler (C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)


**APPIUM LOG:**
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"app":"C:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src","automationName":"uiautomator2","platformName":"Android","deviceName":"device","newCommandTimeout":14},"capabilities":{"firstMatch":[{"appium:app":"C:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src","appium:automationName":"uiautomator2","appium:deviceName":"device","appium:newCommandTimeout":14,"platformName":"android"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"C:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src","automationName":"uiautomator2","platformName":"Android","deviceName":"device","newCommandTimeout":14},null,{"firstMatch":[{"appium:app":"C:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src","appium:automationName":"uiautomator2","appium:deviceName":"device","appium:newCommandTimeout":14,"platformName":"android"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1614346210971 (14:30:10 GMT+0100 (centraleuropeisk normaltid))
[Appium] Appium v1.20.2 creating new AndroidUiautomator2Driver (v1.61.2) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver]   "alwaysMatch": {
[debug] [BaseDriver]     "platformName": "android",
[debug] [BaseDriver]     "appium:app": "C:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src",
[debug] [BaseDriver]     "appium:automationName": "uiautomator2",
[debug] [BaseDriver]     "appium:deviceName": "device",
[debug] [BaseDriver]     "appium:newCommandTimeout": 14
[debug] [BaseDriver]   },
[debug] [BaseDriver]   "firstMatch": [
[debug] [BaseDriver]     {}
[debug] [BaseDriver]   ]
[debug] [BaseDriver] }
[BaseDriver] Session created with session id: 210de100-ae52-494e-9efd-b449c93d0142
[BaseDriver] Using local app 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src'
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1614346210995 (14:30:10 GMT+0100 (centraleuropeisk normaltid))
[debug] [W3C] Encountered internal error running command: Error: New app path 'C:\Users\Elvedin\eclipse-workspace\AppiumFramework\src' did not have extensions: .apk,.apks
[debug] [W3C]     at verifyAppExtension (C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\helpers.js:120:9)
[debug] [W3C]     at C:\Users\Elvedin\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\helpers.js:269:5
[HTTP] <-- POST /wd/hub/session 500 30 ms - 785
[HTTP]
[Appium] Received SIGINT - shutting down
[debug] [Appium] There are no active sessions for cleanup
[HTTP] Waiting until the server is closed
[HTTP] Received server close event

src path folder

main class

ecommerce_tc_4 class

global.properties file

Java Android Appium 服务器端

评论


答:

0赞 dmytro Minz 2/28/2021 #1

check capabilities in documentation. Specify with - absolute path to .apk file: . There are no specified .apk file in your code: app/abs/path/to/my.apkC:\\Users\\Elvedin\\eclipse-workspace\\AppiumFramework\\src