How to use to 2 apps sequentially in one session?

I am using Android simulator, Appium 1.3.4.1, on Windows 8 and using Javascript with Selenium 2.

I have a session for one app with the capabilities and the test works fine. But now i want to test 2 apps in one session and same emulator sequentially. How can I do this?? How to close one and open the other?

This is my script:

  caps1 = {
    platformName: "ANDROID",
    platformVersion: "4.4",
    deviceName: "emulator-5554",
    app: "/Users/adt-bundle-windows/sdk/platform-tools/Ox5-debug.apk"
  };

 caps2 = {
    platformName: "ANDROID",
    platformVersion: "4.4",
    deviceName: "emulator-5554", 
    app: "/Users/adt-bundle-windows/sdk/platform-tools/Rx5-debug.apk"
  };

init = function*() {
var e, sessions;
mobFarm = yiewd.remote(baseUrl);

try {
  console.log('Trying existing session');
  sessions = (yield mobFarm.sessions());
  if (sessions.length < 1) {
    throw new Error();
  }
  return (yield mobFarm.attach(sessions[0].id));
} catch (_error) {
  e = _error;
  console.log("Creating a new session");
  return (yield mobFarm.init(caps1));
}

try {
  console.log('Trying existing session');
  sessions = (yield mobFarm.sessions());
  if (sessions.length < 1) {
    throw new Error();
  }
  return (yield mobFarm.attach(sessions[0].id));
} catch (_error) {
  e = _error;
  console.log("Creating a new session");
  return (yield mobFarm.init(caps2));
}

};

I am new to this so hopefully I can get some help
Thanks

I think it is impossible to launch two apps at one session on the same device/emulator. Am I wrong? Please somebody show us the working example.

It depends on things which you want to check. For example you have to test two apps which can send messages to each other. So you can launch these apps on different devices/emulators. This gadgets/virtual devices can be connected to different remote computers.

Exactly, so now I am doing it with 2 emulators and 2 appium with different ports. It open both apps but doesn’t wait each to run the test, instead it close it right away to open the 2nd one. Some suggestion?

Oops… I have forgotten that there is a time out for the command waiting… :frowning:

Actually, the functionality which you need is going to be implemented:

1 Like

Hey @SergeyTichomirov thanks for your help. I manage to make it work. So apparently it was that i was not running 2 different instances of the emulators. I was running 2 emulators with different ports but not different instances, so appium was getting confuse and instead used the first emulator. So i just create different emulators instances and run it with different ports and it works :slight_smile:

@ladygirl88 Hi LadyGirl,

This is Joseph. I also want to run two different apps in same instance of Appium test. It would be great if you can assist me with How to set capabilities in appium.

1 Like

Hey @yeruva7

Ok sure follow these steps:

  1. You need 2 appium running with each different ports

    baseUrl_1 = “http://appiumAddress:4726/wd/hub”
    baseUrl_2 = “http:/appiumAddress:4725/wd/hub”

  2. You need to 2 different instances of android emulator. What I was doing before was running 2 emulators with same instances. So make sure you just run different emulators (what i mean it can be the same version everything but the 2nd one change the name). Apparently appium was getting confuse if i run it with the same.

  3. You need to set the capabilities for each emulator:

     caps1 = {
     platformName:"ANDROID",
     platformVersion: "4.4",
     deviceName: "emulator-5554",
     app: "app1Path.apk",
            browserName: "",
    

}

caps2 = {
platformName:“ANDROID”,
platformVersion: “4.4”,
deviceName: “emulator-5556”,
app: “app2Path.apk”,
browserName: “”
}

  1. So what i did was to write session for each app in a try catch separately

Then when you run your test 1 app is going to display on 1 emulator and the 2nd app with the 2nd emulator. That’s it everything else depends on your script or whatever environment you are using. I am using selenium webdriver with javascript. I hope this helps :wink:

1 Like

@ladygirl88 Thank for your reply. Since I am using it for first time, Can you share your code for where you wrote the sessions? I dont need your App but to get started with this It will be real help. or you can email at [email protected]

Thanks for help

hi ladygirl88,

I want to open two chrome browser instances parallel in real android device using appium. i have started two appium servers with two ports, but when i tried to start second session, first one is killing. :frowning:
Please help me in doing this.

hey @ladygirl88
you are using two appium servers here? i want to run same code on multiple devices i am using selenium grid , please help me here?

Dear friends,

In my case I need to launch an appication (Custom Launcher) and from that need to open another application and need to do some click events in second app. But I am not able to Click the views of the second app using IDs.

Please help to solve this issue. In Appium environment, can we open and perform some actions in an app which is opened from the app which we have mentioned in the capabilities section.

Thanks in advance,
NAGOOR.

In android it is possible.

Hi Priyank_Shah,

Can you please provide more details on how to perform some actions on the veiws of an app which is opened from the application which is mentioned in the Appium’s setup?

Thanks,
NAGOOR

@ladygirl88 @Priyank_Shah @SergeyTichomirov

just a quick question to everyone: Is it possible to run tests on two different apps, which are to communicate with each other, on two different devices, in one Appium Session? If yes, how so? please explain

if possible, two different apps, which are to communicate with each other, on two different devices, in one Appium Session? If yes, how so? please explain???

hi. we have same need and did it in following way:

  • we use testNG
  • in beforeSuite we starting two appium servers with two different ports
  • in beforeMethod we starting driver.
  • in each driver starting to needed appium server
  • in code there is “driver_1” and “driver_2”
  • we use google Page Object approach and thus each page can be initiated with different driver
  • so in code we opening driver to first phone
  • then opening driver to second phone
  • while any driver does nothing we wrote simple function that just pinging not used phone to avoid timeout
  • once we need phone we just stop it pinging and doing what is needed

our tests are like one client sending request another one responding like in chat way.

3 Likes

Hey,

Did you manage to find a solution yet?:slight_smile:

The way people make keema & kichidi with question, no one will get answer.

Hi Alekser ;

I am using the same approcah you mentioned but then test is initiated on one device
Steps:
1- Create two sessions on two different ports
2- create two drivers , for each mobile
3- run Base test
4- two sessions would start 1 on mobile 1 and 2nd on mobile2
5- but the test would continue on 1 machine

I am using pagefactory , could you please help ?

just write more about your problem. as far as we started 2 apps - we can do on one app then another then again on first. of course we cant do simultaneously at same time 2 commands in code (unless we really need it and in such case we need e.g. with java to do it in different threads)