# How many devices can I handle in one session?

**URL:** <https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646>\
**Category:** Support\
**Created:** [July 10, 2023, 12:14pm UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646 "2023-07-10T12:14:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Min-gun\_Jung](https://discuss.appium.io/user_avatar/discuss.appium.io/min-gun_jung/32/11450_2.png) [@Min-gun\_Jung](https://discuss.appium.io/u/Min-gun_Jung)\
**Post date:** [July 10, 2023, 12:14pm UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/1 "2023-07-10T12:14:30Z")

</div>

Hello,

Thanks to your helps, I have managed to run some tests.  
My situtation is little bit uncommon since I need to all the test with real devices.

So my original code was like this  
Device 1: send message for a certain period  
Device 2: read pop-up window 10 seconds after the device 1 send a message and evaluate the value.

And I wanted to expand my test so I added a code for one more recieving device like below

capabilities1 = dict(  
platformName=‘Android’,  
automationName=‘uiautomator2’,  
udid=‘DID1’,  
newCommandTimeout=20  
)

capabilities2 = dict(  
platformName=‘Android’,  
automationName=‘uiautomator2’,  
udid=‘DID2’, # replace this with the actual UDID of the second device  
newCommandTimeout=20  
)

capabilities3 = dict(  
platformName=‘Android’,  
automationName=‘uiautomator2’,  
udid=‘DID3’, # replace this with the actual UDID of the second device  
newCommandTimeout=20  
)  
appium\_server\_url = ‘[http://localhost:4723](http://localhost:4723)’

class TestAppium(unittest.TestCase):  
def setUp(self) -\> None:  
self.driver1 = webdriver.Remote(appium\_server\_url, capabilities1)  
self.driver2 = webdriver.Remote(appium\_server\_url, capabilities2)  
self.driver3 = webdriver.Remote(appium\_server\_url, capabilities3)  
…

I also duplicate the code for window anaysis and change all the numbers accordingly(ex: self.driver3.)

window\_elements = self.driver2.find\_elements(by=AppiumBy.ID, value=“appname:id/btn\_window”)

```
    for el in window_elements:
        if el.text == "text1":
            self.count_green_1 += 1
        elif el.text == "text2.":
            self.count_yellow_1 += 1
        elif el.text == "text3":
            self.count_unknown_1 += 1
        elif el.text == "text4":
            self.count_red_1 += 1
   # Check for the presence of the image element and increase the count if it's present
    image_elements = self.driver2.find_elements(by=AppiumBy.ID, value="appname:id/apssp_native_ad_main_image1")
    if len(image_elements) > 0:
        self.count_image_1 += 1
    # Print the current counts to the terminal
    print(f'receiver 1 window: {self.count_tv_info_1}, ad: {self.count_view_advertisement_1}, image: {self.count_image_1}, green: {self.count_green_1}, yellow: {self.count_yellow_1}, red: {self.count_red_1}, grey: {self.count_unknown_1}')

```

but nothing happens and the terminal says that they passed the test.  
It does that even when the appium server is not running.  
Any advice please?

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [July 10, 2023, 7:51pm UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/2 "2023-07-10T19:51:14Z")

</div>

Each device should have it’s own Appium server. Here is a tutorial on running multiple devices, it includes code examples:

[https://appiumpro.com/editions/28-running-multiple-appium-tests-in-parallel](https://appiumpro.com/editions/28-running-multiple-appium-tests-in-parallel)

Hopefully that will help.

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [July 10, 2023, 8:36pm UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/3 "2023-07-10T20:36:48Z")

</div>

Actually both strategies are supported: it is possible to have multiple sessions in one server instance or multiple server instances having one session. The first option is preferable when it is necessary to save memory and CPU resources, but it would probably be harder to scan logs for different sessions and figure our what exactly went wrong in case of a failure.

Regarding the device amount per session - it is possible to only handle one and only one device per session. A new session must be created for each device.

Also if we are talking about Android real devices automation then the adb utility only allows to serve up to 16 devices on a single host.

---

<div class="post-metadata">

**Author:** ![Min-gun\_Jung](https://discuss.appium.io/user_avatar/discuss.appium.io/min-gun_jung/32/11450_2.png) [@Min-gun\_Jung](https://discuss.appium.io/u/Min-gun_Jung)\
**Post date:** [July 12, 2023, 8:30am UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/4 "2023-07-12T08:30:25Z")

</div>

Thx for the material! I didn’t know such things were there.

---

<div class="post-metadata">

**Author:** ![Min-gun\_Jung](https://discuss.appium.io/user_avatar/discuss.appium.io/min-gun_jung/32/11450_2.png) [@Min-gun\_Jung](https://discuss.appium.io/u/Min-gun_Jung)\
**Post date:** [July 12, 2023, 8:35am UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/5 "2023-07-12T08:35:54Z")

</div>

Thx for your detailed explanations.

The app I testing is a phone call app, so caller and recievers should work together, which means at least one of the strategies you mentioned is necessary.

I will study more about running multiple sessions by adding ports, as wreed’s material recommended.

---

<div class="post-metadata">

**Author:** ![Min-gun\_Jung](https://discuss.appium.io/user_avatar/discuss.appium.io/min-gun_jung/32/11450_2.png) [@Min-gun\_Jung](https://discuss.appium.io/u/Min-gun_Jung)\
**Post date:** [July 12, 2023, 1:03pm UTC](https://discuss.appium.io/t/how-many-devices-can-i-handle-in-one-session/39646/6 "2023-07-12T13:03:53Z")

</div>

I have tired the multi server thing, but something went wrong.

I have opened 3 ports by using seperatd windows terminal, but the 3rd one always have high latency and does not give any response.

Worse thing is, after the try, the original code that used to work for 2 devices does not work anymore. Even if I run it on codeVS, the server get nothing but python says that the test is passed. It doesn’t matter if Appium server is running.

Should I work on selenium grid perhahps? I really need to work with multiple device with percise timing.
