How many devices can I handle in one session?

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

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?

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

Hopefully that will help.

1 Like

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.

1 Like

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

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.

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.