Shell Scott
Shell Scott

Reputation: 1909

Appium with real device on docker container

trying to run appium tests using appium docker container and having an issue when running it. Starting docker image with

docker run --privileged -d -p 4723:4723  -e ANDROID_ADB_SERVER_ADDRESS=host.docker.internal  -v /dev/bus/usb:/dev/bus/usb --name appium-container appium/appium

then my setup looks like

DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability("appium:deviceName", "Android Device");
    cap.setCapability("appium:udid", getDeviceId());
    cap.setCapability("appium:platformName", "Android");
    cap.setCapability("appium:automationName", AutomationName.ANDROID_UIAUTOMATOR2);
    cap.setCapability("appium:appPackage", apkType());
    cap.setCapability("appium:appActivity", apkType() + ".activities.MainActivity");
    cap.setCapability("appium:noReset", "true");
    cap.setCapability("appium:remoteAdbHost", "host.docker.internal");
    cap.setCapability("appium:autoWebview", true);
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/"), cap);

then on docker I see logs saying

2024-12-01 11:42:04 [852bea52][ADB] Running '/opt/android/platform-tools/adb -H host.docker.internal -P 5037 -s R52WC098VEH forward tcp:10900 localabstract:webview_devtools_remote_25582'
2024-12-01 11:42:04 [852bea52][AndroidUiautomator2Driver@dde5] AxiosError: Request failed with status code 500

...
1 11:42:04     data: 'Host header is specified and is not an IP address or localhost.'
2024-12-01 11:42:04   },
2024-12-01 11:42:04   status: 500
2024-12-01 11:42:04 }

And logs in intelijidea

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 400. Message: No such context found. 

Such context should be present because when Im doing the same but without docker then all good, app has webcontext. Also tests are working with native context.

Guys from appium suggested to update uiAutomator version and use IP instead of host.docker.internal https://github.com/appium/appium/issues/20782#issuecomment-2503630659 so I've changed it to docker IP cap.setCapability("appium:remoteAdbHost", "172.17.0.2"); also updated UI automator but result is the same, any suggestions???

Upvotes: 0

Views: 61

Answers (0)

Related Questions