使用 Appium 测试 Android 应用程序时无法创建新的远程会话

2024-01-15

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

appium --address 127.0.0.1

我在用着

  • java-client-4.1.2.jar
  • 硒-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 日志文件:

    [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 的路径:

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

另外,我建议从 RemoteWebDriver 更改为 Android 驱动程序,因为您将拥有更多功能:

driver = new AndroidDriver(....)

ps:您可以将 java-client 更新到 4.1.2,将 testng 更新到 6.9.10

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Appium 测试 Android 应用程序时无法创建新的远程会话 的相关文章

随机推荐

  • 获取.NET中给定字符对和字体的字距调整偏移值

    如何获得给定的 2 个之间的间距调整char在 NET 中 在WPF应用程序中 例如 假设我有字体Times New Roman尺寸的22那是bold 字符将使用什么字距调整A and v 如何在我的 WPF 应用程序中获取该值 如果你徘徊
  • 在实践中如何使用 Ember 中的 findAll 和 peekAll ?

    From EmberJS 文档 http guides emberjs com v2 0 0 models finding records toc retrieving multiple records我有以下两种方法来检索给定类型的所有记
  • 编译OpenCV时出错,致命错误:stdlib.h:没有这样的文件或目录

    我正在尝试编译 OpenCV 我已经尝试过 master 分支 当前提交 dc9602e 和版本 标签 3 1 0 我使用的是Fedora 24 我首先尝试使用Fedora附带的gcc gcc GCC 6 2 1 20160916 Red
  • 检索权限列表

    我正在尝试检索设备中应用程序的权限 奇怪的是 对于某些应用程序 我确实得到了结果 而在其中一些应用程序中 我无法检索任何权限 也许为了获取应用程序的权限列表 应用程序必须设置一些特定的标志 因为如果我尝试以这种方式获取我的应用程序的权限列表
  • 如何在不设置系统范围属性的情况下将 HTTP 代理用于 JAX-WS 请求?

    我有一个应用程序需要向 Internet 上的系统发出 SOAP 客户端请求 因此它需要通过我们的 HTTP 代理 可以通过设置系统范围的值 例如系统属性 来做到这一点 Cowboy style Blow away anything any
  • 为什么 TableAdapter.Fill 数据源之间的性能差异

    我有一个 Windows 窗体应用程序DataGridView居住着一个TableAdapter 我正在使用Fill循环更新UI数据的方法Async像这样子 Private Async Sub updateUI Dim sw As New
  • 如何始终运行 Spyder 项目中的主文件

    我正在开发一个包含多个文件的Python项目 令人烦恼的是我必须在单击运行之前选择描述和调用main的文件 因为如果不是Spyder3 Anaconda 则运行当前选定的文件 如果打开并选择文件 如何从 mainPrjPy py 中的 ma
  • 将 LibTiff 安装到 Visual Studio 2010 [重复]

    这个问题在这里已经有答案了 可能的重复 在 Visual Studio 2010 中使用 LibTiff https stackoverflow com questions 4647791 using libtiff in visual s
  • 将按钮绑定到命令 (Windows Phone 7.5)

    我正在开发我的 Windows Phone 应用程序 它使用一些简单的数据绑定 我已经创建了一个基于 MvvM 编程方法的应用程序 我当前正在开发的应用程序也可以通过 MvvM 方法工作 因为我想让我的代码尽可能干净 所以我正在寻找一种方法
  • 如何与 NHibernate 映射一对多关系中的枚举?

    我有两张单独的桌子 users roles id user id value lt Represented by the enum 还有他们的模型 class User int id IList
  • 在word文档中插入图片

    这是我第一次在 Apache POI 上工作 我要问的问题已经在这个网站上提出了 但没有给出明确的答案 所以我别无选择 只能接受你们的帮助 我正在尝试编写一个java程序 它从一个文件夹中获取图像并将该图像插入到word文档中 我在这个程序
  • 如何将 Django 模型上的属性(虚拟字段)公开为 TastyPie ModelResource 中的字段

    我在 Django 模型中有一个属性 我想通过 TastyPie ModelResource 公开该属性 我的模型是 class UserProfile models Model genderChoices u M u Male u F u
  • Trie、后缀树、后缀数组

    哪种结构提供最佳的性能结果 trie 前缀树 后缀树还是后缀数组 还有其他类似的结构吗 这些结构的良好 Java 实现是什么 编辑 在这种情况下 我想在大型名称词典和大量自然语言文本之间进行字符串匹配 以便识别文本上词典的名称 特里树是第一
  • 在 chrome DevTools/Console 面板中复制文本无法正常工作

    描述错误 最近 在 macOS 版本 12 6 3 上使用 Chrome 版本 112 0 5615 49 时 我在从 DevTools 的控制台面板复制和粘贴时遇到了问题 选择一个单词并复制后 当我粘贴它时 它总是向后移动2个字符 这可能
  • 最好的 JavaScript 日期解析器和格式化器? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 使用 Zend_DB_Table 选择查询

    我有一个类似以下的代码 class Application Model Company extends Zend Db Table Abstract protected name companies private id private n
  • 为什么 rm 命令不删除文件? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 当我今天访问我的 Ubuntu 16 04 服务器并想要删除文件 test2 时 它根本没有被删除 我用过 rm test2 也 rm f
  • Nexus 7 (ME370T) 上的 BLE 与 Android 4.4.2

    我一直在尝试使用 sdk sdk samples android 18 legacy BluetoothLeGatt 中的示例将 BLE 设备与我的 Nexus 7 ME370T 配对 但我收到信息 不支持 Ble 我正在寻找解决方案 但我
  • XAML文件如何与cs文件关联?

    看来 XAML 文件在 C 项目中应该有相应的 cs 文件 我知道 Visual Studio 可以为我们做所有事情 我只是好奇它们是如何联系在一起的 我的意思是 它们是在项目文件中指定的 还是仅仅因为它们具有相同的名称 而且 App xa
  • 使用 Appium 测试 Android 应用程序时无法创建新的远程会话

    我正在尝试使用 Appium 在 Eclipse 中运行用 java 编码的测试脚本示例 我通过 npm 运行 Appium 我使用的是 Appium 1 6 3 我对 Appium 并不陌生 我之前在 Mac 和 Windows 上运行它