amrsa1 / Android-Emulator-image

The use of this Docker image simplifies the process of running an Android emulator within a Docker container
MIT License
82 stars 39 forks source link

Can we use headless mode for UI/Functional testing? #19

Open Akash-ramesh opened 4 months ago

Akash-ramesh commented 4 months ago

Hi @amrsa1 ,

Thanks in advance for the repo.

I am new to automation and I am trying to integrate my test scripts written in python and using appium technology to pipeline. Can we use headless mode for UI testing?

I am not able to launch emulator in headed mode. I am getting the following error :

_IINFO    | Storing crashdata in: , detection is enabled for process: 1668
INFO    | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
INFO    | Increasing RAM size to 3072MB
WARNING | File System is not ext4, disable QuickbootFileBacked feature
INFO    | Warning: could not connect to display  ((null):0, (null))
INFO    | Info: Could not load the Qt platform plugin "xcb" in "/opt/android/emulator/lib64/qt/plugins" even though it was found. ((null):0, (null))
Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.
 ((null):0, (null))
INFO    | Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.._

I am able to launch emulator in headless mode, but my test cases are failing with Element not found exception

 _File "/usr/local/lib/python3.9/dist-packages/appium/webdriver/webdriver.py", line 409, in find_element
          return self.execute(RemoteCommand.FIND_ELEMENT, {'using': by, 'value': value})['value']
        File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute
          self.error_handler.check_response(response)
        File "/usr/local/lib/python3.9/dist-packages/appium/webdriver/errorhandler.py", line 122, in check_response
          raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace))
      selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
      Stacktrace:
      NoSuchElementError: An element could not be located on the page using the given search parameters.
          at AndroidUiautomator2Driver.findElOrEls (/root/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:75:11)
          at processTicksAndRejections (node:internal/process/task_queues:95:5)
          at AndroidUiautomator2Driver.findElOrElsWithProcessing (/usr/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:60:12)
          at AndroidUiautomator2Driver.findElement (/usr/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:75:12)_
amrsa1 commented 4 months ago

@Akash-ramesh

how you are trying to run the emulator in headed mode ?, only way is Via vnc, you cant run it in headed mode using terminal. Regarding test failing best thing todo is to take screenshot on failure in order to be able to debug.

SachinNodeShell commented 2 weeks ago

Hi @Akash-ramesh I have been encountering the same issue as well, did you find any solution to it? NOTE Appium works fine on my own device locally on the emulator, however when I try to run it in headless mode it throws NoSuchElementError: An element could not be located on the page using the given search parameters. I tried adding a delay to ensure the emulator and the app launch were ready to run the tests, but I still got the same error!

@amrsa1 can you please confirm if we can run the unit tests in headless mode?

amrsa1 commented 2 weeks ago

Headless mode should be working fine but somtimes the android image is not stable in headless mode, neverthless you can still overcome the android crashing issue, follow up this article to resolve this issue

Check the debugging section https://webdriver.io/blog/2023/05/31/guied-for-xplatform-nativeMobile-app

SachinNodeShell commented 2 weeks ago

Thanks @amrsa1 for the quick response, I will check the article!