qentinelqi / qweb

Keyword driven automation for the web
https://github.com/qentinelqi/qweb
Apache License 2.0
40 stars 17 forks source link

Support QWeb running inside docker containers #57

Closed roblen45 closed 2 years ago

roblen45 commented 2 years ago

Is your feature request related to a problem? Please describe. We would like to run our QWeb tests in our ci pipeline inside a docker container.

Describe the solution you'd like We installed chromium in the docker image, but when we try to run the tests, we only get the following error message:

` ERROR ] Error in file '/robot/test.robot' on line 2: Importing library 'QWeb' failed: ImportError: this platform is not supported: ('failed to acquire X connection: Bad display name ""', DisplayNameError(''))

Try one of the following resolutions:

Test:

` Settings Library QWeb # Import library

Test Cases Basic interaction OpenBrowser https://qentinelqi.github.io/shop chrome chrome_path=/usr/lib/chromium/chromium # Open chrome and goto given url VerifyText The animal friendly clothing company # Assert heading text ClickText Scar the Lion # Click link text ClickText Add to cart # Click button with specific text DropDown Size Large # Select value (Large) from dropdown (Size)`

kalyncoose commented 2 years ago

Hi Robin, what CI pipeline product are you using? Also, could you provide what exact image/version the Docker container is using (straight Python or are you using something like Ubuntu?).

If you are using a Python-based Docker image, I don't think that will work since you need enough of a linux OS installed (Debian-based perhaps) to have a virtual screen. A virtual screen makes the image think that there is a monitor connected to it so that the chrome driver can properly load and "display".

I haven't tried this myself yet but I believe one way to do this is to use an Ubuntu image, then install "xvfb" and execute xvfb to enable the virtual display.

Example: Xvfb -ac :99 -screen 0 1920x1080x24 & export DISPLAY=:99

Reference: https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml

I'm not a QWeb developer, but I am interested in tackling this issue with you as I also need to run QWeb in Docker in GitLab CI pipelines/kubernetes at work.

roblen45 commented 2 years ago

Yes of course. We use github actions as CI pipeline and I tried the following image:

FROM python:3.9

WORKDIR /robot

RUN apt update

RUN apt install -y chromium

RUN pip install --upgrade pip

RUN pip install robotframework robotframework-jsonlibrary QWeb

tkoukkari commented 2 years ago

Well we are using GitHub actions as well to test QWeb + we are running it inside docker in many places. Maybe you could check our linux pipeline setup. Yes xvfb is needed as mentioned by @kalyncoose . Also window manager is needed if you want to control browser size etc. https://github.com/qentinelqi/qweb/blob/master/.github/workflows/linux_acceptance.yml

roblen45 commented 2 years ago

@tkoukkari Could you please provide me a Dockerfile with all dependencies I need? How do you start the xvfb server?

tkoukkari commented 2 years ago

Try this: RUN xvfb-run --auto-servernum --server-num=1

tkoukkari commented 2 years ago

Hi, were you able to solve this or do you need additional assistance?

roblen45 commented 2 years ago

Hi, no I were not able to solve this. Could you please provide me a full Dockerfile with all dependencies needed?

tkoukkari commented 2 years ago

Hi, No, unfortunately I'm not able to provide that nor is it in scope of this project. Sorry.

If you check our GitHub actions for linux, we are installing these: sudo apt-get install matchbox scrot

..and then setting the display and starting window manager:

  export DISPLAY=:88
  Xvfb $DISPLAY -screen 0 1920x1080x24 & sleep 1
  matchbox-window-manager -use_titlebar no &

before running tests normally: python -m robot whatever.robot

turunenm commented 2 years ago

Check this SO thread: https://stackoverflow.com/questions/32151043/xvfb-docker-cannot-open-display

You need to add something like this into your dockerfile:

RUN sudo apt-get install matchbox scrot
# QWeb pip dep "pyautogui" installs "python3-xlib" pip dep which can cause xlib Xauthority errors
RUN pip install python-xlib

ENV DISPLAY :99

ADD run.sh /run.sh
RUN chmod a+x /run.sh

CMD /run.sh

run.sh should look something like this:

Xvfb $DISPLAY -screen 0 1920x1080x24 & sleep 1
matchbox-window-manager -use_titlebar no &
python -m robot "your_test.robot"