无法在真实设备上运行appium脚本。得到一个糟糕的应用错误

时间:2017-04-10 12:31:07

标签: java android appium ui-automation

我试图在eclipse中执行这个java代码,使用Appium和使用USB连接的真实设备。我无法在设备中测试安装在设备中的应用程序。

    package appiumproject;
    import io.appium.java_client.android.AndroidDriver;
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;

    public class StartApplication {

            private static AndroidDriver driver;
            public static void main(String[] args) throws MalformedURLException, InterruptedException {

                File classpathRoot = new File(System.getProperty("user.dir"));
                File appDir = new File(classpathRoot, "/sdcard/Android/data/");
                File app = new File(appDir, "com.alensw.PicFolder");

                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
                capabilities.setCapability("deviceName", "BX9034M10V");
                capabilities.setCapability("platformVersion", "4.1.2");
                capabilities.setCapability("platformName", "Android");
                capabilities.setCapability("app", app.getAbsolutePath());
                capabilities.setCapability("appPackage", "com.alensw.PicFolder");
                //capabilities.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity");

                driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
                driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
                Thread.sleep(10000);
                driver.quit();

以下是我在eclipse控制台中遇到的错误。有人能让我知道错误的原因:'糟糕的应用' 如何从Android设备中提供app appctivity的classPathRoot?
            线程“main”中的异常org.openqa.selenium.SessionNotCreatedException:无法创建新会话。 (原始错误:错误的应用程序:C:\ Users \ admin \ workspace \ AppiumProject \ sdcard \ Android \ data \ com.alensw.PicFolder。应用程序路径必须是绝对的,或相对于appium服务器安装目录,或者URL压缩文件或特殊应用程序名称。原因:错误:使用本地应用程序,但未以.zip,.ipa或.apk结尾)(警告:服务器未提供任何堆栈跟踪信息)     命令持续时间或超时:0毫秒     构建信息:版本:'3.3.1',修订版:'5234b32',时间:'2017-03-10 09:04:52 -0800'     系统信息:主机:'ADMIN-PC',ip:'10 .0.0.63',os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.8 .0_121'     驱动程序信息:driver.version:AndroidDriver         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)         at java.lang.reflect.Constructor.newInstance(Unknown Source)         在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)         在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)         在io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:160)         at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:75)         在io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)         在io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)         在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)         at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)         at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)         在io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)         在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)         在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:131)         在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:144)         在io.appium.java_client.DefaultGenericMobileDriver。(DefaultGenericMobileDriver.java:38)         在io.appium.java_client.AppiumDriver。(AppiumDriver.java:88)         在io.appium.java_client.AppiumDriver。(AppiumDriver.java:112)         在io.appium.java_client.android.AndroidDriver。(AndroidDriver.java:73)         在appiumproject.StartApplication.main(StartApplication.java:29)

    }

1 个答案:

答案 0 :(得分:0)

在以下功能中,您需要提及.apk文件的路径

capabilities.setCapability("app", app.getAbsolutePath());

应该如下:

capabilities.setCapability("app","path of apk file");