microsoft / playwright-java

Java version of the Playwright testing and automation library
https://playwright.dev/java/
Apache License 2.0
1.14k stars 207 forks source link

[BUG] Cannot run test in cloud environment in firefox #1289

Closed Mauro1924 closed 1 year ago

Mauro1924 commented 1 year ago

System info

Source code


import com.microsoft.playwright.*;

 public void startDataTransfer(ApptrackSubmission apptrackSubmission) {
        LOGGER.info("Start startDataTransfer process of GIRO, submission with id {}", apptrackSubmission.getId());
        try (Playwright playwright = Playwright.create();
             Browser browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(true));
             Page page = browser.newPage()) {
            //select the URL for correct product
            String url = switch (productEnum) {
                case ONLINE_ACCOUNT, GOGREEN_ACCOUNT, RELAX_ACCOUNT -> giroAccountUrl;
                case STUDENTEN_KONTO -> studentAccountUrl;
                default -> throw new IllegalArgumentException("Wrong product type.");
                };
            page.navigate(url, new Page.NavigateOptions().setWaitUntil(WaitUntilState.DOMCONTENTLOADED));
            //fill first page
            chooseProduct(page, personalData);

public void chooseProduct(Page page, PersonalData personalData) throws InterruptedException {
        LOGGER.info("Start chooseProduct process");

        isDefined(apptrackSubmission.getApptrack().getProductId(), FieldSelector.GOGREEN_ACCOUNT_BUTTON);
        if (isLocatorVisible(page, FieldSelector.GOGREEN_ACCOUNT_BUTTON, null)) {
            if (productEnum.equals(ProductEnum.ONLINE_ACCOUNT)) {
                getLocatorByFieldSelector(page, FieldSelector.ONLINE_ACCOUNT_BUTTON, ProductEnum.ONLINE_ACCOUNT, null).click();
            } else if (productEnum.equals(ProductEnum.GOGREEN_ACCOUNT)) {
                getLocatorByFieldSelector(page, FieldSelector.GOGREEN_ACCOUNT_BUTTON, ProductEnum.ONLINE_ACCOUNT, null).click();
            } else {
                getLocatorByFieldSelector(page, FieldSelector.RELAX_ACCOUNT_BUTTON, ProductEnum.ONLINE_ACCOUNT, null).click();
            }
            getLocatorByFieldSelector(page, FieldSelector.NEW_MEMBER_BUTTON_GIRO, ProductEnum.ONLINE_ACCOUNT, null).click();
            getLocatorByFieldSelector(page, FieldSelector.STANDARD_CARD_BUTTON_GIRO, ProductEnum.ONLINE_ACCOUNT, null).click();
        } else {
            getLocatorByFieldSelector(page, FieldSelector.STUDENT_ACCOUNT_BUTTON, ProductEnum.ONLINE_ACCOUNT, null).click();
            getLocatorByFieldSelector(page, FieldSelector.NEW_MEMBER_BUTTON_STUDENT, ProductEnum.ONLINE_ACCOUNT, null).click();
            getLocatorByFieldSelector(page, FieldSelector.STANDARD_CARD_BUTTON_STUDENT, ProductEnum.ONLINE_ACCOUNT, null).click();
        }

        LOGGER.info("End chooseProduct process");
    }

Dockerfile:
FROM mcr.microsoft.com/playwright/java:v1.33.0-focal
RUN apt-get update && apt-get install -y --no-install-recommends git vim xvfb
RUN mkdir "/.cache"
#RUN mkdir "/tmp"
RUN chmod a+w -R /ms-playwright
RUN chmod a+w -R /.cache
RUN chmod a+w -R /tmp
ARG jar_module
ARG jar_path=$jar_module
ARG build_dir=target
ARG env

#ENV RUNASUSER pwuser
#ENV USERHOME /home/${RUNASUSER}
#RUN groupadd -g 1001 -r ${RUNASUSER} && useradd --no-log-init -m -r -g ${RUNASUSER} -u 1001 ${RUNASUSER}
#USER ${RUNASUSER}
#WORKDIR ${USERHOME}

ENV ENVIRONMENT=$env \
    JAVA_BASE_OPTS='-server -Dfile.encoding=UTF-8 -Duser.timezone=Europe/Berlin' \
    JAVA_ADDITIONAL_OPTS='\
       -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/nfs/system \
       -XX:NativeMemoryTracking=summary -XX:+UseContainerSupport \
       -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
       -Djava.rmi.server.hostname=127.0.0.1 \
       -Dcom.sun.management.jmxremote \
       -Dcom.sun.management.jmxremote.port=9090 \
       -Dcom.sun.management.jmxremote.rmi.port=9090 \
       -Dcom.sun.management.jmxremote.authenticate=false \
       -Dcom.sun.management.jmxremote.ssl=false \
       -Dcom.sun.management.jmxremote.local.only=false ' \
    JAVA_MEM_OPTS='-XX:InitialRAMPercentage=75 -XX:MaxRAMPercentage=75 -XshowSettings'
#COPY docker/pom.xml pom.xml
#RUN mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args='install --with-deps firefox'
USER pwuser
WORKDIR /home/pwuser
COPY ${jar_path}/${build_dir}/${jar_module}.jar /application.jar

RUN echo '#!/bin/bash \n xvfb-run --auto-servernum --server-num=1 java -Dspring.profiles.active=$ENVIRONMENT $JAVA_BASE_OPTS $JAVA_MEM_OPTS $JAVA_ADDITIONAL_OPTS -jar /$1 $2 $3 $4 $5 $6' > /home/pwuser/entrypoint.sh
RUN ["chmod", "+x", "entrypoint.sh"]

ENTRYPOINT ["/home/pwuser/entrypoint.sh", "application.jar"]

Issue
Error {
  message='Timeout 180000ms exceeded.
=========================== logs ===========================
<launching> /ms-playwright/firefox-1403/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-t2I5ZQ -juggler-pipe -silent
<launched> pid=318
[pid=318][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: glxtest: libpci missing (t=0.144323) [GFX1-]: glxtest: libpci missing
[pid=318][err] Unable to revert mtime: /ms-playwright/firefox-1403/firefox/fonts
[pid=318][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 58: Error: Can't find profile directory.
[pid=318][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 58: Error: Can't find profile directory.
[pid=318][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 58: Error: Can't find profile directory.
[pid=318][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 58: Error: Can't find profile directory.
[pid=318][err] 
[pid=318][err] (firefox-default:318): Gtk-WARNING **: 14:43:09.057: Error loading theme icon 'dialog-warning' for stock: Icon 'dialog-warning' not present in theme Yaru
[pid=318][err] ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
[pid=318][err] ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
[pid=318][err] ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
[pid=318][err] ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
[pid=318][err] ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
[pid=318][err] ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
[pid=318][err] ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
[pid=318][err] ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
[pid=318][err] JavaScript error: resource://gre/modules/XULStore.jsm, line 58: Error: Can't find profile directory.
============================================================

**Actual**
In local environment it rns through, but when I start it on cloud environment, it gives me this error message.
yury-s commented 1 year ago

Your debug log is for firefox. Looks like you are running the browser in headed mode in the docker container that doesn't have x server. Try removing .setHeadless(true) from the code. If you need further help please share a complete self-contained repro that we could run locally.

Mauro1924 commented 1 year ago

Sorry I added the old code in the new one I'm using firefox and in headless mode it works locally but running on cloud environment it gives me this error.

I'm using the xvfb-run --auto-servernum --server-num=1 for the x server or is this wrong implemented?

yury-s commented 1 year ago

I'm using the xvfb-run --auto-servernum --server-num=1 for the x server or is this wrong implemented?

--server-num=1 is redundant. In headless mode you don't need xvfb-run. But it's hard to tell what you are doing and what's not working without a reproducible example.

Mauro1924 commented 1 year ago

Sorry I can't give a repo for this, as this is my companies project.

When I run it in the cloud environment, it first said, "Couldn't find a X Server". Thats why I used the xvfb-run and then the error didn't show anymore. Is there anything I can show you from the project that would help you or does it have to be the full repo I need to give?

This is the message it gives me when I'm taking out the xvfb-run: `Error { message=' ╔════════════════════════════════════════════════════════════════════════════════════════════════╗ ║ Looks like you launched a headed browser without having a XServer running. ║ ║ Set either 'headless: true' or use 'xvfb-run ' before running Playwright. ║ ║ ║ ║ <3 Playwright Team ║ ╚════════════════════════════════════════════════════════════════════════════════════════════════╝ =========================== logs ===========================

/ms-playwright/firefox-1403/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-Gawu1C -juggler-pipe -silent pid=302 [pid=302][err] Error: no DISPLAY environment variable specified [pid=302] [pid=302] starting temporary directories cleanup ============================================================`
yury-s commented 1 year ago

You keep launching in headed mode for some reason, we normally recommend running in headless especially on CI. If you have to run in headed mode for some reason xvfb-run should handle that. If you need further help we need a full repro. Given that the problem is with browser launch it should be possible to extract a minimal repro that wouldn't contain any sensitive details. You can create a repro with our docker image.

Closing this request as we cannot help further without additional details. Please file a new issue with a repro and link it to this one.