Appium:无法在连接的多个Android设备上运行脚本 [英] Appium : unable to run script in multiple android device connected

查看:571
本文介绍了Appium:无法在连接的多个Android设备上运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

appium创建多个实例。 从控制台我运行:

Created multiple instance of appium. from console i run :

node . -p 4722 -U Z*****K --chromedriver-port 9
515 -bp 2251

node . -p 4723 -U T*****K --chromedriver-port 9
516 -bp 2252

实例是在两个设备上创建但是URL仅打开在所述第一设备的第二设备connected.Browser只是没有被打开的URL保持打开。

Instances are created on both the devices but the URL opens only on the second device connected.Browser in the first device just stays open without the url being opened.

code:

Specflow文件:

Specflow file :

Test.feature

  Scenario: Check Home Page
        Given I am on home page
        Then My title should be 'whatever'

Steps.cs

 [Given(@"I am on home page")]
            public void GivenIAmOnHofHomePage()
            {
                var testappium = new TestAppium();
                testappium.SetUp();
                testappium.OpenHomePage();
            }

TestAppium.cs

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Interfaces;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;


namespace Mobile.Tests.UIAutomation
{

    public class TestAppium
    {
        public static IWebDriver driver=null;

        public void SetUp()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability("device", "Android");
            capabilities.SetCapability("browserName", "chrome");
            capabilities.SetCapability("deviceName", "test");
            capabilities.SetCapability("platformName", "Android");
            capabilities.SetCapability("platformVersion", "5.0.1");
            capabilities.SetCapability("udid", EnvironmentVariables.nexus);

            driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4722/wd/hub"), capabilities, TimeSpan.FromSeconds(180));

            DesiredCapabilities capabilitiess = new DesiredCapabilities();

            capabilitiess.SetCapability("device", "Android");
            capabilitiess.SetCapability("browserName", "chrome");
            capabilitiess.SetCapability("deviceName", "Arpan Buch");
            capabilitiess.SetCapability("platformName", "Android");
            capabilitiess.SetCapability("platformVersion", "5.0.2");
            capabilitiess.SetCapability("udid", EnvironmentVariables.motog);

            driver = new RemoteWebDriver(new  Uri("http://127.0.0.1:4723/wd/hub"), capabilitiess, TimeSpan.FromSeconds(180));
       }

       public void OpenHomePage()
        {
            driver.Navigate().GoToUrl("http://www.google.com");

            Console.WriteLine("Page title is : " +driver.Title);
            Assert.IsTrue(driver.Title.Equals("Google")," Sorry , the website didnt open!!");
        }
     }
  }

实例是在两个设备上创建,但URL仅在连接第二装置打开。浏览器中的第一个设备只是没有被打开的URL保持打开状态。

Instances are created on both the devices but the URL opens only on the second device connected. Browser in the first device just stays open without the url being opened.

是对第一设备的被覆盖的驱动程序实例(?)。这里是作为一个测试人员,而不是开发者我的编程的限制。请帮忙! 在此先感谢!

Is the driver instance of the first device being overwritten (?). here is my programming limitation of being a tester and not a developer. Please Help! Thanks in advance!

推荐答案

Appium了这个问题,因为多个Android设备的支持是不是从一开始就支持​​的功能。

Appium had a problem with this as support for multiple Android devices was not a feature supported from the very beginning.

Appium团队实现了此功能从这个问题开始。相当长的螺纹:) 一个贡献者合并在code此修复程序来解决这个并实现这样的功能

Appium team worked on this feature starting from this issue. Quite long thread :) A contributor merged this fix in the code to solve this and implement such a feature.

该线程是有点混乱,但包含了大量的材料。我个人决定不使用Appium在这种情况下,因为不是那么可靠的时刻。但是我认为,在你的能力,你应该指定:

The thread is a bit confusing but contains a lot of material. Personally I decided not to use Appium in this scenario because is not so reliable at the moment. However I think that in your capabilities you should specify:

capabilitiess.SetCapability("udid", "<UDID>");
capabilitiess.SetCapability("devicePort", "<ADB-port-listening-to-device>");

最后一个能力是关键!线程解释了很多,但基本上你应该把那里,亚行通过听你的设备的端口号。如果您连接两个Android设备,你会得到两个不同的端口。

The last capability is the key! The thread explains a lot but basically you should place there the port number that ADB is using to listen to your device. If you connect two Android devices, you get two different ports.

您可能想尝试运行两个Appium服务器,如在同一个线程我之前链接解释。

You might want to try running two Appium servers like explained in the same thread I linked before.

appium -p 4725 -bp 4727 -U 02*************** --chromedriver-port 9515
appium -p 4724 -bp 4726 -U 07a************** --chromedriver-port 9516

考虑以下内容:

Considering the following:

node . -p <appium_port> -bp <device_port> -U <serial> -g <logfile>

您测试应该当然参阅Appium的在同一台机器上,但是两个不同的端口上运行的这两种不同的实例。在您的例子,记得为Chromedriver指定的不同的端口

Your tests should of course refer to these two different instances of Appium running on the same machine but on two different ports. In your example remember to specify different ports for Chromedriver!

这篇关于Appium:无法在连接的多个Android设备上运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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