python-client icon indicating copy to clipboard operation
python-client copied to clipboard

Parallel usage results in a "socket hang up" error. systemPort have set but still have the problem.

Open Underson888 opened this issue 2 years ago • 7 comments

Here's my code:

python

from appium import webdriver from appium.webdriver.common.touch_action import TouchAction import threading

Device 1's configuration

desired_caps1 = { "appium:appActivity": ".Settings", "appium:appPackage": "com.android.settings", "appium:automationName": "uiautomator2", "appium:udid": "xxxx", "platformName": "Android", "appium:systemPort": 8310 }

Device 2's configuration

desired_caps2 = { "appium:appActivity": ".Settings", "appium:appPackage": "com.android.settings", "appium:automationName": "uiautomator2", "appium:udid": "192.168.137.58:5555", "platformName": "Android", "appium:systemPort": 8322 }

def run_test_on_device(desired_caps): driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # Corrected URL

width = driver.get_window_size()["width"]
height = driver.get_window_size()["height"]

action = TouchAction(driver)
action.tap(x=width // 2, y=height // 2).perform()

driver.quit()

Use threading for parallel execution

thread1 = threading.Thread(target=run_test_on_device, args=(desired_caps1,)) thread2 = threading.Thread(target=run_test_on_device, args=(desired_caps2,))

thread1.start() thread2.start()

thread1.join() thread2.join()

I have set the different systemPort for each devices, but I still have the problem.

How can I sove that, I'm very need to be solved, thanks.

Underson888 avatar Aug 16 '23 11:08 Underson888

The error information is as follows: Exception in thread Thread-2: Traceback (most recent call last): File "D:\allAi\environments\tiktok\lib\threading.py", line 980, in _bootstrap_inner self.run() File "D:\allAi\environments\tiktok\lib\threading.py", line 917, in run self._target(*self._args, **self._kwargs) File "D:\tiktok\control\testParallel\test.py", line 33, in run_test_on_device driver = webdriver.Remote('http://127.0.0.1:4723', desired_caps) File "D:\allAi\environments\tiktok\lib\site-packages\appium\webdriver\webdriver.py", line 257, in init super().init( File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in init self.start_session(capabilities) File "D:\allAi\environments\tiktok\lib\site-packages\appium\webdriver\webdriver.py", line 346, in start_session response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps) File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute self.error_handler.check_response(response) File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up at UIA2Proxy.command (C:\Users\12624\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\jsonwp-proxy\proxy.js:355:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at AndroidUiautomator2Driver.commands.getDevicePixelRatio (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\commands\viewport.js:14:10) at AndroidUiautomator2Driver.fillDeviceDetails (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:256:28) at AndroidUiautomator2Driver.createSession (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:242:7) at AppiumDriver.createSession (C:\Users\12624\AppData\Roaming\npm\node_modules\appium\lib\appium.js:352:35) Exception in thread Thread-1: Traceback (most recent call last): File "D:\allAi\environments\tiktok\lib\threading.py", line 980, in _bootstrap_inner self.run() File "D:\allAi\environments\tiktok\lib\threading.py", line 917, in run self._target(*self._args, **self._kwargs) File "D:\tiktok\control\testParallel\test.py", line 33, in run_test_on_device driver = webdriver.Remote('http://127.0.0.1:4723', desired_caps) File "D:\allAi\environments\tiktok\lib\site-packages\appium\webdriver\webdriver.py", line 257, in init super().init( File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in init self.start_session(capabilities) File "D:\allAi\environments\tiktok\lib\site-packages\appium\webdriver\webdriver.py", line 346, in start_session response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps) File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute self.error_handler.check_response(response) File "D:\allAi\environments\tiktok\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up at UIA2Proxy.command (C:\Users\12624\AppData\Roaming\npm\node_modules\appium\node_modules@appium\base-driver\lib\jsonwp-proxy\proxy.js:355:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at AndroidUiautomator2Driver.commands.getDevicePixelRatio (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\commands\viewport.js:14:10) at AndroidUiautomator2Driver.fillDeviceDetails (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:256:28) at AndroidUiautomator2Driver.createSession (C:\Users\12624.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:242:7) at AppiumDriver.createSession (C:\Users\12624\AppData\Roaming\npm\node_modules\appium\lib\appium.js:352:35)

Underson888 avatar Aug 16 '23 11:08 Underson888

Could you share the appium log as well? (as GIST)

KazuCocoa avatar Aug 16 '23 15:08 KazuCocoa

Could you share the appium log as well? (as GIST)

Ok,bro. This is the link:https://gist.github.com/Underson888/8871bca07b3241d7aa6f810e9a7bc16c

Underson888 avatar Aug 16 '23 16:08 Underson888

Did they work with a single thread? The port config itself looks working

KazuCocoa avatar Aug 17 '23 08:08 KazuCocoa

Did they work with a single thread? The port config itself looks working

Yes,each device is controlled by a single thread,just like the code mentioned.

Underson888 avatar Aug 17 '23 08:08 Underson888

Did they work with a single thread? The port config itself looks working

thread1 = threading.Thread(target=run_test_on_device, args=(desired_caps1,)) thread2 = threading.Thread(target=run_test_on_device, args=(desired_caps2,))

thread1.start() thread2.start()

thread1.join() thread2.join()

Is it correct for the driver?

Underson888 avatar Aug 17 '23 08:08 Underson888