java-client
java-client copied to clipboard
Screenshots get swapped between devices when two instances of AppiumDriver are executed in parallel
Description
I'm using two instances of AppiumDriver in separate threads for automating a mobile app on two Android devices in parallel. When a test case fails on both the devices, I'm trying to capture a screenshot of the devices using the following code snippet.
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
The screenshots are saved in different directories named after the device names, but sometimes (2 out of 3), the screenshots created get swapped between the devices. That means if I'm using a Tab and a Phone for testing, the screenshot of the Tab gets created inside the directory created for Phone and vice versa.
I'm pretty sure there are two separate instances of AppiumDriver running on different ports as the entire test suit (~100+ tests) runs smoothly on both the devices without a problem. Just the screenshots get swapped between the devices.
Any help or pointers in the right direction are much appreciated.
Environment
- Java client build version or git revision if you use some snapshot:
- Appium server version or git revision if you use some snapshot:
- Desktop OS/version used to run Appium if necessary:
- Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe:
- Mobile platform/version under test:
- Real device or emulator/simulator:
Source Code
Find a very brief (dirty) representation of my code flow here
Environment
- Appium version: 1.18.0
- Desktop OS/version: Mac OS Catalina 10.15.5
- Node.js version: v12.16.1
- Npm or Yarn package manager: Npm (v6.13.4)
- Real device or emulator/simulator: Real Devices
- Appium CLI or Appium.app|exe: Appium
When multiple devices need to specify different multiple ports, please make sure that the bootstrap-port port or the systemPort port is the same or is occupied!
appium -p 4723 -bp 4724
appium -p 4725 -bp 4726
In reference to @yuowo , you are able to use PortProber.findFreePort()
, works like a charm.
import org.openqa.selenium.net.PortProber;
So like this:
cap.setCapability(AndroidMobileCapabilityType.SYSTEM_PORT, PortProber.findFreePort());
Thanks @yuowo and @wulfihm. I'm stuck with some urgent stuff for the past couple of days. I'll give it a try tomorrow and let you know.
Seems like the issue is not related to systemPort or bootstrap-port. Because I can see 100+ tests executing successfully on both the devices in parallel without any problems. I was already providing different systemPorts. Now I tried providing separate bootstrap-ports as well but the screenshots still get swapped among the devices.
Did you check that the folder is definitely the correct one when you call the function to save the screenshot? Sounds like the problem is simply an errously made "name-swap" for some reason.
Make it so the test prints the current driver/Test and the folder it saves the screnshot in. Then compare.
@iamporus did you manage to progress or still stuck with the same problem? as we face similar issue
I get the same issue: while testing on multiple Android devices in parallel, the screenshots between those devices are mixed.
- Appium Java client 7.5.1
- Testing on real devices
Any update on this? Having the same issue.