Appium : unable to run script in multiple android device connected
Asked Answered
K

1

1

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

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 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!!");
        }
     }
  }

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!

Kappa answered 27/2, 2015 at 15:27 Comment(3)
are you getting any error message?Infallibilism
No error message. The script passes successfully.Kappa
i think this has been a persistent issue (or maybe feature request), old thread from google groups, another so question regarding multi device support and on github alsoBrayton
G
0

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

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.

What to do

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>");

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.

More Appium instances

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>

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!

Galvano answered 2/3, 2015 at 12:41 Comment(3)
So please try this, I am also trying to get better insights on this, will update the post with more info later :)Galvano
Did you set the correct port by using ADB as explained in the blog post?Galvano
Ok, what about chromedriver ports? It is the latest edit in my answer, you did set the same chromedriver port, trying setting different onesGalvano

© 2022 - 2024 — McMap. All rights reserved.