budtmo / docker-android

Android in docker solution with noVNC supported and video recording
Other
8.81k stars 1.19k forks source link

[🐛 Bug ]: Appium inside docker container isn't working as expected #359

Closed vamvindev closed 1 year ago

vamvindev commented 1 year ago

Operating System

Windows 11

Docker Image

Appium inside docker container isn't working as expected

Expected behaviour

Appium server should be started on the designated port and should allow the Remote Driver to start and perform actions as per the script.

Actual behaviour

Appium server is not started and so the remote session isn't being initiated.

Logs

This is the docker command I’m using to start the container

docker run -d -p 6080:6080 -p 4723:4723 -p 5555:5555 -e EMULATOR_DEVICE=“Samsung Galaxy S10” -e WEB_VNC=true -e APPIUM=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0

Below is my test setup in local which works perfectly in local Android emulator.

@Test
public void signUpValidations() throws MalformedURLException, InterruptedException {

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“platformName”, “android”);

caps.setCapability(“appium:platformVersion”, “11”);
caps.setCapability(“appium:deviceName”,“emulator-5554”);
caps.setCapability(“appium:automationName”, “uiautomator2”);
caps.setCapability(“appium:deviceName”, “Samsung Galaxy S10”);
caps.setCapability(“appium:appPackage”, “com.wcs.witricity”);
caps.setCapability(“appium:appActivity”, “com.wcs.witricity.feature.main.MainActivity”);

try {
URL url = new URL(“http://127.0.0.1:4723/wd/hub”);
driver = new AppiumDriver<MobileElement>(url, caps);
driver = new AndroidDriver<MobileElement>(url, caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

And when the test is executed, this is the response in console

org.openqa.selenium.WebDriverException: Connection refused: no further information
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Local-Laptop', ip: '192.168.1.13', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '20.0.1'
Driver info: driver.version: AppiumDriver

    at io.appium.java_client.remote.AppiumCommandExecutor.lambda$5(AppiumCommandExecutor.java:251)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:336)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:98)
    at com.appiumtest.AppAccessValidations.signUpValidations(AppAccessValidations.java:40)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.net.ConnectException: Connection refused: no further information
    at java.base/sun.nio.ch.Net.pollConnect(Native Method)
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:673)
    at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:535)
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:585)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
    at java.base/java.net.Socket.connect(Socket.java:666)
    at okhttp3.internal.platform.Platform.connectSocket(Platform.java:129)
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
    at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
    at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:105)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    ... 35 more
alexgoryushkin commented 1 year ago

Appium v2 in image emulator_11.0_v2.0-p3 broken. Try use older versions of image: emulator_11.0_v2.0-p2 or emulator_11.0_v2.0-p1. It helped me. I also faced such problem in p3 (latest image):

GET http://0.0.0.0:4723/wd/hub/status

Result: {"status":9,"value":{"error":"unknown command","message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource","stacktrace":""}}

appium.stdout.log:

2023-06-13 07:54:36 INFO Application - Appium will be started without ui!
[Appium] Welcome to Appium v2.0.0-beta.71
[Appium] Attempting to load driver espresso...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-espresso-driver
[Appium] Attempting to load driver flutter...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-flutter-driver
[Appium] Attempting to load driver gecko...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-geckodriver
[Appium] Attempting to load driver uiautomator2...
[debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-uiautomator2-driver
(node:41) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[Appium] Available drivers:
[Appium]   - espresso@2.23.1 (automationName 'Espresso')
[Appium]   - flutter@1.14.4 (automationName 'Flutter')
[Appium]   - gecko@1.1.9 (automationName 'Gecko')
[Appium]   - uiautomator2@2.25.2 (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [HTTP] No route found for /wd/hub/status
[HTTP] <-- GET /wd/hub/status 404 12 ms - 211
[HTTP] 
[HTTP] <-- GET /favicon.ico 200 2 ms - 1150
[HTTP] 
vamvindev commented 1 year ago

Hey @alexgoryushkin ,

Thank you so much for reaching out and your suggestion.

So, I tried the lower version, using the below command

docker run -d -p 6080:6080 -p 4723:4723 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true -e APPIUM=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0_v2.0-p2

And also with the latest version docker run -d -p 6080:6080 -p 4723:4723 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true -e APPIUM=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0

I did a GET http://0.0.0.0:4723/wd/hub/status which resulted in the same error message you shared

{
    "status": 9,
    "value":
    {
        "error": "unknown command",
        "message": "The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource",
        "stacktrace": ""
    }
}

image

image

Below are the appium.stdout.log for both v2.0-p2 and v2.0-p3 - It's exactly the same.

2023-06-28 02:38:14 INFO Application - Appium will be started without ui! [Appium] Welcome to Appium v2.0.0-beta.63 [Appium] Attempting to load driver espresso... [debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-espresso-driver [Appium] Attempting to load driver flutter... [debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-flutter-driver [Appium] Attempting to load driver gecko... [debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-geckodriver [Appium] Attempting to load driver uiautomator2... [debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-uiautomator2-driver (node:43) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit (Use node --trace-warnings ... to show where the warning was created) [Appium] Appium REST http interface listener started on 0.0.0.0:4723 [Appium] Available drivers: [Appium] - espresso@2.20.1 (automationName 'Espresso') [Appium] - flutter@1.14.3 (automationName 'Flutter') [Appium] - gecko@1.1.9 (automationName 'Gecko') [Appium] - uiautomator2@2.14.0 (automationName 'UiAutomator2') [Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use. [HTTP] --> GET /wd/hub/status [HTTP] {} [debug] [HTTP] No route found for /wd/hub/status [HTTP] <-- GET /wd/hub/status 404 9 ms - 211 [HTTP] [HTTP] [HTTP] <-- GET /favicon.ico 200 6 ms - 1150 [HTTP]

Meaning, Appium server is running but we are unable to get a response when my Appium is tying to hit the URL : "http://0.0.0.0:4723/wd/hub".

Any thoughts on why this is happening @budtmo ?

Would love to know if you did try to run an Appium script from your local that would be running on the emulator inside the docker container @alexgoryushkin

vamvindev commented 1 year ago

I think I found a solution for this issue.

I have the version 1.22.3 in my local, so the URL with 0.0.0.0:4723/wd/hub works just fine.

However with Appium 2.0 they no longer provide the base, so the URL is just 0.0.0.0:4723. Here's the issue discussing it - https://github.com/appium/appium/issues/15261

So, when I did a GET to just 0.0.0.0:4723/status, it did give me the response as expected image

Also, my remote session is now created perfectly fine

[debug] [AppiumDriver@e144] Calling AppiumDriver.getStatus() with args: [] [debug] [AppiumDriver@e144] Responding to client with driver.getStatus() result: {"build":{"version":"2.0.0-beta.71"}} [HTTP] <-- GET /status 200 10 ms - 47 [HTTP] [HTTP] --> POST /session [HTTP] {"desiredCapabilities":{"appium:appActivity":"com.wcs.witricity.feature.main.MainActivity","appium:deviceName":"Samsung Galaxy S10 30","platformName":"Android","appium:automationName":"uiautomator2","appium:platformVersion":"11","appium:appPackage":"com.wcs.witricity"},"capabilities":{"firstMatch":[{"appium:appActivity":"com.wcs.witricity.feature.main.MainActivity","appium:appPackage":"com.wcs.witricity","appium:automationName":"uiautomator2","appium:deviceName":"Samsung Galaxy S10 30","appium:platformVersion":"11","platformName":"android"}]}} [debug] [AppiumDriver@e144] Calling AppiumDriver.createSession() with args: [{"appium:appActivity":"com.wcs.witricity.feature.main.MainActivity","appium:deviceName":"Samsung Galaxy S10 30","platformName":"Android","appium:automationName":"uiautomator2","appium:platformVersion":"11","appium:appPackage":"com.wcs.witricity"},null,{"firstMatch":[{"appium:appActivity":"com.wcs.witricity.feature.main.MainActivity","appium:appPackage":"com.wcs.witricity","appium:automationName":"uiautomator2","appium:deviceName":"Samsung Galaxy S10 30","appium:platformVersion":"11","platformName":"android"}]}] [debug] [AppiumDriver@e144] Event 'newSessionRequested' logged at 1687924016034 (03:46:56 GMT+0000 (Coordinated Universal Time)) [Appium] Attempting to find matching driver for automationName 'uiautomator2' and platformName 'android' [Appium] The 'uiautomator2' driver was installed and matched caps. [Appium] Will require it at /home/androidusr/.appium/node_modules/appium-uiautomator2-driver [debug] [Appium] Requiring driver at /home/androidusr/.appium/node_modules/appium-uiautomator2-driver [AppiumDriver@e144] Appium v2.0.0-beta.71 creating new AndroidUiautomator2Driver (v2.25.2) session [AppiumDriver@e144] Checking BaseDriver versions for Appium and AndroidUiautomator2Driver [AppiumDriver@e144] Appium's BaseDriver version is 9.3.10 [AppiumDriver@e144] AndroidUiautomator2Driver's BaseDriver version is 9.3.10 [debug] [AndroidUiautomator2Driver@4d21] Creating session with W3C capabilities: { [debug] [AndroidUiautomator2Driver@4d21] "alwaysMatch": { [debug] [AndroidUiautomator2Driver@4d21] "platformName": "android", [debug] [AndroidUiautomator2Driver@4d21] "appium:appActivity": "com.wcs.witricity.feature.main.MainActivity", [debug] [AndroidUiautomator2Driver@4d21] "appium:appPackage": "com.wcs.witricity", [debug] [AndroidUiautomator2Driver@4d21] "appium:automationName": "uiautomator2", [debug] [AndroidUiautomator2Driver@4d21] "appium:deviceName": "Samsung Galaxy S10 30", [debug] [AndroidUiautomator2Driver@4d21] "appium:platformVersion": "11" [debug] [AndroidUiautomator2Driver@4d21] }, [debug] [AndroidUiautomator2Driver@4d21] "firstMatch": [ [debug] [AndroidUiautomator2Driver@4d21] {} [debug] [AndroidUiautomator2Driver@4d21] ] [debug] [AndroidUiautomator2Driver@4d21] } [AndroidUiautomator2Driver@4d21 (1fe72b84)] Session created with session id: 1fe72b84-210a-46fa-aa1e-ac80318cfe44 . . . . .

@alexgoryushkin

@budtmo I'm closing this issue.