Test involving two emulators - deviceName doesn't differentiate between emulators

I’m trying to put up an automated test that involves two emulators.

Scenario is

  1. First Emulator User Sends an Email to Second One.
  2. Second emulator user waits for the email and then replies to his mail.
  3. First Emulator User checks the reply and quits.

My Two Emulators running are
emulator-5556
emulator-5554

Challenge is, following code launches up email client on emulator-5554 by ignoring the device name given below. (Documentation also suggest that this setting is ignored on android - http://appium.io/slate/en/master/?ruby#appium-server-capabilities)

        DesiredCapabilities dc = new DesiredCapabilities();
        dc.SetCapability(MobileCapabilityType.DeviceName, "emulator-5556");
        dc.SetCapability(MobileCapabilityType.BrowserName, "");
        dc.SetCapability(AndroidMobileCapabilityType.AppPackage, appPackage);
        dc.SetCapability(AndroidMobileCapabilityType.AppActivity, appActivity);

What’s the best way to accomplish the goal of automation of this scenario with two emulators in deterministic way?

Regards,
Sandeep.

I have setup selenium grid for parallel execution on two emulators. hope this will help :slight_smile: happy testing…

But mine is single test that needs to interact with two emulators.

This is not two parallel tests in grid setup. I believe One Appium Server can help us talk to two emulators simultaneously from a single test.

we need same! here are steps:

  1. start 2 appium servers on same machine BUT different ports. e.g. from our logs:
 start appium as: [appium, --log-level, error, --port, 4725, --session-override]
 start appium_2 as: [appium, --log-level, error, --port, 4726, --session-override]
  1. create 2 driver variables in tests
  2. start each driver when needed to different appium ports

PS if you use pageObject remember initialise each page correctly with needed driver variable before do something

Start two Appium server on different post lets say
appium -p 4723 -U emulator-5554
appium -p 4725 -U emulator-5556

Now you have two test written in your testng test class
write a BeforeTest method which accept two parameter (port,device) and pameterize your capability and port.

test1 - sending email
test2- replying email

Create a testng.xml file with two test nodes

test node 1:
parameter: port =4723 , device emulator-5554
parameter: port =4725 , device emulator-5556

include test method 1 – sending email and exclude replying email

test node 2:
parameter: port =4725 , device emulator-5556
include test method 2 - replying email and exclude sending email

Now run tesng.xml sequentially… it works for me… hope it help you too

1 Like

Yeah, That worked fine.

But my understanding was One Appium Server (since this is an HTTP REST Server in NodeJS) can handle multiple parallel sessions. Like a Selenium Grid Server will do. Then why should one be forced to start two separate appium servers on different ports. That’s why posted this question.

Am I missing something or above understanding is wrong?

Thanks Aleksei. I’m looking for a way to control two emulators using Single Appium server. I believe it is possible to do that if the code starts honoring deviceName on Android.

why you need ONLY 1 server?

In Selenium Grid scenarios as well we user only single HUB with multiple NODES and our tests talk to HUB by telling it the DESIRED CAPABILITIES. That’s what we use quite commonly.

My Current Scenario is Two User scenario - But may extend to FOUR users in future. Now Every time starting four different appium servers won’t make much sense.

Even in selenium grid if you observe you are launching different browser instance however this is not apparently visible because that functionality abstracted by WebDriver framework. Mobile is different, if you do not want to launch server manually then you can use AppliumLocalService which launch server from your java code.

Priyank - If we compare it with Web Scenario…

Browser (Represented by WebDriver object in code) ====== Emulator (Represented by WebDriver object in code)

Selenium Grid Hub ========= Appium Server

Now I can automate a single test that launches two browsers and can send commands to them one by one.

@Test
public void twoBrowserWebTest()
{
WebDriver chrome = new ChromeDriver(new URL(gridServerUrl), dc);
WebDriver firefox = new FirefoxDriver(new URL(gridServerUrl), dc);

 chrome.get("http://google.com");
 firefox.get("http://microsoft.com");

}

Above test works perfectly fine as Grid Directs commands to the right browser window. But in case of two android emulators… This scenario is broken.

Hope that explains my problem better.

I might be wrong in assuming that one APPIUM Server is equivalent to HUB in Selenium GRID… If that is the case - Can someone please confim?

Selenium Grid hub != AppiumServer , AppiumServer that managed by SeleniumGrid. So for parallel execution you need to pass grid port number. your grid will delegate webdriver commands to connected device through AppiumServers. Since you are using selenium WebDriver (Firefox/chromeDrivers) here actually you do not need to launch server. but this not the case with mobile applications, where you need to launch two separate server instances.

Hope this helps you to understand.