如何确保 appium 节点只连接到一部手机? [英] How to make sure the appium node is connected to only one phone?

查看:31
本文介绍了如何确保 appium 节点只连接到一部手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行(全部在一台机器上)多个 appium 服务器作为节点连接到 selenium-grid 集线器,我有多个电话连接到端口 5555 上的 adb(在我的例子中是通过 WiFi).

I run (all on one machine) multiple appium servers connected as nodes to a selenium-grid hub and I have multiple phones connected to my adb on port 5555 (in my case via WiFi).

问题我对此的看法是三款手机中的两款具有匹配的功能(Android 7.1.1、Chrome 浏览器).因此,当我为 nexus 9 启动测试时,如果占用了 nexus 6 的网格节点.或者甚至相反,我要求在 nexus 6 上运行测试,这个测试被占用,但测试运行在nexus 9. 所以我想要/需要的是一种配置,我可以使用它来使其足够独特,以启动仅连接到一部手机的 appium 服务器.

The issue I have with this is that two of the three phones have capabilities that are matching (Android 7.1.1, Chrome browser). So when I fire up a test for the nexus 9, if occupies the grid node for nexus 6. Or even the other way around, I ask to run the test on the nexus 6, this one get occupied, but the test runs on the nexus 9. So what I want/need is a configuration I can use to make it unique enough to fire up an appium server that only connects to one phone.

我的设置

  • Windows 10 (x64)
  • Ruby v2.3.3(32 位)和 gems watir v6.8.4,selenium-webdriver v3.6.0
  • Selenium-Standalone-Server v3.6.0
  • Appium Desktop v1.2.5(服务器 v1.7.1)
  • 或者通过命令行 Appium 服务器 v1.6.5

测试设备

  • Nexus 5(手机)- Android 6.0.1 - 192.1.1.120:5555(在 adb 设备列表中)
  • Nexus 6(手机)- Android 7.1.1 - 192.1.1.63:5555(在 adb 设备列表中)
  • Nexus 9(平板电脑)- Android 7.1.1 - 192.1.1.55:5555(在 adb 设备列表中)

网格

java -jar selenium-standalone-server3.6.0.jar -role hub

通过命令行(或桌面应用程序)启动 appium 服务器

appium -a 0.0.0.0 -p 4723 -bp 4724 --nodeconfig node_nexus5.json

appium -a 0.0.0.0 -p 4725 -bp 4726 --nodeconfig node_nexus6.json

appium -a 0.0.0.0 -p 4727 -bp 4728 --nodeconfig node_nexus9.json

node_nexus6.json(节点5和节点9只有platformVersion、deviceName、udid和applicationName不同)

{
  "capabilities":[
    {
    "platform": "ANDROID",
    "platformName": "Android",
    "platformVersion": "7.1.1",
    "browserName": "chrome",
    "version": "6",
    "deviceName": "Nexus6",
    "udid": "192.1.1.63:5555",
    "applicationName": "Nexus6",
    "maxInstances": 1
    }
  ],
  "configuration":
    {
    "cleanUpCycle":2500,
    "timeout":30000,
    "maxSession": 1,
    "register": true,
    "registerCycle": 1000,
    "hubPort": 4444,
    "hubHost": "localhost"
    }
}

我尝试了什么

deviceName、applicationName、版本能力

browser = Watir::Browser.new :chrome, {
    url: "http://localhost:4444/wd/hub",  
    platformName: "Android",
    platformVersion: "7.1.1",
    browserName: "chrome",
    version: "6",
    deviceName: "Nexus6",
    applicationName: "Nexus6"
}

结果

仅使用设备名称时,结果最奇怪.在网格上,nexus 6 被占用.但是我看到我想响应nexus 5的服务器来接手工作,但是它在nexus 9上执行了

When only using the device name, the result was the weirdest. On the grid the nexus 6 was being occupied. But I saw the server I wanted to respond to the nexus 5 to take the job, but it got executed on the nexus 9

当我包含 applicationName 时,正确的网格节点被占用(nexus 6),我认为要响应的 appium 服务器确实响应了,但它再次在 nexus 9 设备上执行了测试.

When I included the applicationName, the correct grid node was occupied (nexus 6), the appium server I thought was going to respond did respond, but it again executed the test on the nexus 9 device.

版本与 applicationName 相同.

Version did the same as applicationName.

我没有尝试过,因为它会像超时一样覆盖此功能.

Udid I did not try because it will just overwrite this capability like a timeout.

主要问题

如何将 appium 服务器节点配置为只为一台特定的手机提供服务,而无需编写自定义功能匹配器?

How can I configure the appium server node to only serve one specific phone without the need for writing a custom capability matcher?

推荐答案

我很惊讶我之前尝试过的功能不起作用,因为在其他论坛帖子中它似乎对其他人有用(尽管通常不清楚他们是否使用硒网格).

I was surprised that the capabilities I tries before did not work since in other forum posts it seemed to have worked for others (although usually not clear if they use a selenium-grid).

到目前为止,我的解决方案是使用以下 appium 服务器(网格节点)配置(需要包含 udid 和 version)

My solution so far is to use the following appium server (grid node) config (both udid and version need to be included)

{
  "capabilities":[
    {
    "platform": "ANDROID",
    "platformName": "Android",
    "platformVersion": "7.1.1",
    "browserName": "chrome",
    "version": "6",
    "deviceName": "Nexus6",
    "udid": "192.1.1.63:5555",
    "maxInstances": 1
    }
  ],
  "configuration":
    {
    "cleanUpCycle":2500,
    "timeout":30000,
    "maxSession": 1,
    "register": true,
    "registerCycle": 1000,
    "hubPort": 4444,
    "hubHost": "localhost"
    }
}

对于启动会话,同样适用(包括 udid 和 version)

And for starting the session the same applies (include udid and version)

Watir::Browser.new :chrome, {
    url: "http://localhost:4444/wd/hub",  
    platformName: "Android",
    platformVersion: "7.1.1",
    browserName: "chrome",
    version: "6",
    deviceName: "Nexus6",
    udid: "192.1.1.63:5555"
}

知道为什么我尝试的上述解决方案不起作用仍然很好.从我读过的所有内容来看,我认为这就是原因.网格只查看平台名称、平台版本、浏览器名称、版本(浏览器版本)和设备名称(尽管最后一个被忽略).基于此,它将所有功能转发到匹配的 appium 节点.然后 udid 被 appium 节点识别为一种能力,并用于连接到我想要的手机.如果我省略了 udid,它将连接到匹配其他功能的电话,并忽略我在初始配置中设置的 udid.最后一点是我不明白为什么会这样,但对我来说这个设置(使用 udid)有效.

It would still be good to know why the above solutions I tried did not work. From all things I did read I assume this is the reason. The grid only looks at platformName, platformVersion, browserName, version(browserVersion) and deviceName (although this last one is being ignored). Based on that it will forward all capabilities to a matching appium node. Then udid is recognized as a capability by the appium node and used to make a connection to the phone I want. If I leave out the udid, it will connect to a phone that is matching the other capabilities and ignores the udid I set in the initial config. That last is what I don't understand why this is the case, but for me this setup (with udid) works.

这篇关于如何确保 appium 节点只连接到一部手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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