appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Screenshots get swapped between devices when two instances of AppiumDriver are executed in parallel #1381

Open iamporus opened 4 years ago

iamporus commented 4 years ago

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

Source Code

Find a very brief (dirty) representation of my code flow here

Environment

jongyu commented 4 years ago

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!

jongyu commented 4 years ago
appium -p 4723 -bp 4724
appium -p 4725 -bp 4726
hwulfmeyer commented 4 years ago

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());

iamporus commented 4 years ago

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.

iamporus commented 4 years ago

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.

hwulfmeyer commented 4 years ago

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.

nyaw commented 3 years ago

@iamporus did you manage to progress or still stuck with the same problem? as we face similar issue

carreinbert commented 3 years ago

I get the same issue: while testing on multiple Android devices in parallel, the screenshots between those devices are mixed.

fantpmas commented 3 years ago

Any update on this? Having the same issue.