Appium: unable to run script on multiple connected Android devices

Multiple instances of appium created. from the console, I run:

node . -p 4722 -UZ*****K --chromedriver-port 9 515 -bp 2251 node . -p 4723 -UT*****K --chromedriver-port 9 516 -bp 2252 

Instances are created on both devices, but the URL only opens on the second connected device. The browser on the first device remains open without opening a URL.

The code:

Specflow File:

Test.feature

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

Stepss.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 devices, but the URL only opens on the second connected device. The browser on the first device remains open without opening a URL.

Is the driver instance of the first device overwritten (?). here my programming is limited to be a tester, not a developer. Please help! Thanks in advance!

+1
android selenium-webdriver appium selendroid
source share
1 answer

Appium had a problem with this, as support for multiple Android devices was not supported from the start.

The Appium team has been working on this feature since this issue . A pretty long thread :) In this case, the developer combined this patch in this code to solve this problem and implement such a function.

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 at the moment it is not so reliable. However, I think that in your capabilities you should indicate:

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

The last opportunity is the key! This thread explains a lot, but basically you should specify the port number that ADB uses to listen on your device. If you connect two Android devices, you get two different ports.

Additional Appium instances

You might want to run two Appium servers, as described in the same thread that I linked earlier.

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

Given the following:

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

Of course, your tests should relate to these two different instances of Appium running on the same computer, but on two different ports. In your example, do not forget to specify different ports for Chromedriver !

0
source share

All Articles