使用 Appium 测试 Android 应用程序时无法创建新的远程会话 [英] Unable to create new remote session while testing an Android application with Appium

查看:65
本文介绍了使用 Appium 测试 Android 应用程序时无法创建新的远程会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Appium 在 Eclipse 中运行使用 java 编码的测试脚本示例.我通过 npm 运行 Appium(我使用的是 Appium 1.6.3,我对 Appium 并不陌生,我之前在 Mac 和 Windows 上运行它没有任何问题,但这次在 Ubuntu 中它看起来有点不同,而它没有使用 appium应用程序,但带有控制台)

I'm trying to run an Example of test scripts coded with java in Eclipse with Appium. I run Appium by npm (i'm using Appium 1.6.3, i'm not new to Appium i run it before on Mac and on windows without any problem but this time in Ubuntu it looks a bit different while it's not with the appium application but with console)

appium --address 127.0.0.1

我正在使用

  • java-client-4.1.2.jar
  • selenium-java-3.0.1.jar
  • selenium-server-standalone-3.0.1.jar
  • testng-6.9.10.jar

我的java类是:

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class FirstTest {

    AndroidDriver<AndroidElement> driver;

    File path = new File("/home/emna/Téléchargements/AutomationFiles/app-release.apk");


    @BeforeClass
    public void setUp() throws MalformedURLException {

        System.out.println("app Dir.--->" + path);

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability("deviceName", "SM-G360H");
        capabilities.setCapability("version", "4.4.4");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "platform");
        capabilities.setCapability("udid", "***************");
        capabilities.setCapability("app", path.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.bulldozer.gaa");
        capabilities.setCapability("appActivity",
                "com.bulldozer.gaa.activities.MainActivity");
        driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    }

    @Test
    public void Test1() throws InterruptedException {

        // driver.wait(10000);
        System.out.println("GAA");
        driver.findElement(By.id("acceptCheckbox")).click();
        driver.findElement(By.id("continueBtn")).click();

    }

    @AfterClass
    public void tearDown() {
        driver.quit();

    }

}

但问题是:

[TestNG] Running:
  /tmp/testng-eclipse--2049046107/testng-customsuite.xml

app Dir.--->/home/emna/Téléchargements/AutomationFiles/app-release.apk
Jan 24, 2017 1:14:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jan 24, 2017 1:14:59 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Jan 24, 2017 1:15:10 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=/home/emna/Téléchargements/AutomationFiles/app-release.apk, appPackage=com.bulldozer.gaa, appActivity=com.bulldozer.gaa.activities.MainActivity, platformVersion=platform, platformName=Android, udid=*************, deviceName=SM-G360H, version=4.4.4}], required capabilities = Capabilities [{}]
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'tarek-Vostro-3902', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-59-generic', java.version: '1.8.0_91'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)

这里是 Appium 日志文件:

Here the Appium log file :

    [debug] [ADB] Running '/home/emna/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","***************","shell","am","force-stop","io.appium.unlock"]
[debug] [Logcat] Stopping logcat capture
[debug] [AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[MJSONWP] Encountered internal error running command: Error: Error occured while starting App. Original error: Permission to start activity denied.
    at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)
    at ADB.callee$0$0$ (../../../lib/tools/apk-utils.js:80:9)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at process._tickCallback (internal/process/next_tick.js:103:7)
[HTTP] <-- POST /wd/hub/session 500 11015 ms - 223 
[HTTP] --> POST /wd/hub/session {"capabilities":{"desiredCapabilities":{"app":"/home/emna/Téléchargements/AutomationFiles/app-release.apk","appPackage":"com.bulldozer.gaa","appActivity":"com.bulldozer.gaa.activities.MainActivity","platformVersion":"platform","platformName":"Android","udid":"************","deviceName":"SM-G360H","version":"4.4.4"},"requiredCapabilities":{}}}
[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","capabilities","sessionId","id","sessionId","id","sessionId","id"]} and you sent ["capabilities"]
[HTTP] <-- POST /wd/hub/session 400 5 ms - 205

推荐答案

问题出在 apk 文件本身,我使用了另一个 .apk 文件,其配置与我使用的相同,并且可以正常工作很好!

The problem is with the apk file itself, I used an other .apk file with the same configuration i have used and it works fine !

这篇关于使用 Appium 测试 Android 应用程序时无法创建新的远程会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆