SAP/karma-ui5

Issues loading UI5 resources from UI5 Tooling via WebDriver Launcher

LukasHeimann opened this issue · 6 comments

In my project, I use karma-ui5, UI5 Tooling and run a pipeline using SAP's Project Piper on Azure DevOps.

Piper encourages you to use a special sidecar setup for executing karma tests: https://www.project-piper.io/steps/karmaExecuteTests/

The step is using the seleniumExecuteTest step to spin up two containers in a Docker network:

  • a Selenium/Chrome container (selenium/standalone-chrome)
  • a NodeJS container (node:lts-stretch)

I've done the necessary configuration in karma:

    customLaunchers: {
      ChromeSelenium: {
        base: "WebDriver",
        config: {
          hostname: process.env.PIPER_SELENIUM_WEBDRIVER_HOSTNAME,
          port: process.env.PIPER_SELENIUM_WEBDRIVER_PORT
        },
        browserName: "chrome",
        name: "Chrome"
      },
    },
    hostname: process.env.PIPER_SELENIUM_HOSTNAME,
  });

This, in fact, also works fine for our QUnit tests. However, launching the app for OPA5 Tests fails. To start up the full app, UI5 obviously needs to load a lot of library resources. This process randomly fails at individual libraries, without ever changing the code. The respective libraries are declared, installed and present and work when using the normal ui5 serve. Before the handful of failures, other resources from the libraries are loaded just fine.

A couple examples from different runs, with log level in browser and karma turned to debug

2022-03-07T07:48:01.1960042Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.195:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/CustomStyleClassSupport.js
2022-03-07T07:48:01.1961495Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.195:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/CustomStyleClassSupport.js
2022-03-07T07:48:01.1969917Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.195:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/BusyIndicatorUtils.js
2022-03-07T07:48:01.1971291Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.195:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/BusyIndicatorUtils.js
2022-03-07T07:48:01.2318131Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.230:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/BlockLayerUtils.js
2022-03-07T07:48:01.2326758Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.232:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/BlockLayerUtils.js
2022-03-07T07:48:01.2417707Z warn  karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) WARN: '2022-03-07 07:48:01.237300 retry loading JavaScript resource: sap/ui/core/CustomStyleClassSupport.js -  sap.ui.ModuleSystem'
2022-03-07T07:48:01.2444256Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.243:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/CustomStyleClassSupport.js
2022-03-07T07:48:01.2483613Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.247:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/CustomStyleClassSupport.js
2022-03-07T07:48:01.2512318Z warn  karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) WARN: '2022-03-07 07:48:01.244000 retry loading JavaScript resource: sap/ui/core/BusyIndicatorUtils.js -  sap.ui.ModuleSystem'
2022-03-07T07:48:01.2534566Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.252:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/BusyIndicatorUtils.js
2022-03-07T07:48:01.2543603Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.253:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/BusyIndicatorUtils.js
2022-03-07T07:48:01.2579714Z warn  karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) WARN: '2022-03-07 07:48:01.251000 retry loading JavaScript resource: sap/ui/core/BlockLayerUtils.js -  sap.ui.ModuleSystem'
2022-03-07T07:48:01.2614175Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.260:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/core/BlockLayerUtils.js
2022-03-07T07:48:01.2622824Z info  karmaExecuteTests - �[36m07 03 2022 07:48:01.261:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/core/BlockLayerUtils.js
2022-03-07T07:48:01.2783753Z error karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) ERROR: '2022-03-07 07:48:01.272600 failed to load JavaScript resource: sap/ui/core/CustomStyleClassSupport.js -  sap.ui.ModuleSystem'
2022-03-07T07:48:01.2859126Z error karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) ERROR: '2022-03-07 07:48:01.281500 failed to load JavaScript resource: sap/ui/core/BusyIndicatorUtils.js -  sap.ui.ModuleSystem'
2022-03-07T07:48:01.2891685Z error karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) ERROR: '2022-03-07 07:48:01.283100 failed to load JavaScript resource: sap/ui/core/BlockLayerUtils.js -  sap.ui.ModuleSystem'
2022-03-04T10:21:10.6178549Z info  karmaExecuteTests - �[36m04 03 2022 10:21:10.617:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/events/jquery/EventTriggerHook.js
2022-03-04T10:21:10.6186642Z info  karmaExecuteTests - �[36m04 03 2022 10:21:10.617:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/events/jquery/EventTriggerHook.js
2022-03-04T10:21:10.6198609Z error karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) ERROR: '2022-03-04 10:21:10.618600 failed to load JavaScript resource: sap/ui/test/matchers/_Busy.js -  sap.ui.ModuleSystem'
2022-03-04T10:21:10.6267472Z info  karmaExecuteTests - �[36m04 03 2022 10:21:10.626:DEBUG [middleware:source-files]: �[39mRequesting /base/webapp/resources/sap/ui/events/jquery/EventTriggerHook.js
2022-03-04T10:21:10.6272699Z info  karmaExecuteTests - �[36m04 03 2022 10:21:10.626:DEBUG [middleware:source-files]: �[39mFetching /home/vsts/work/1/s/webapp/resources/sap/ui/events/jquery/EventTriggerHook.js
2022-03-04T10:21:10.6320349Z error karmaExecuteTests - Chrome 98.0.4758.102 (Linux x86_64) ERROR: '2022-03-04 10:21:10.631000 failed to load JavaScript resource: sap/ui/events/jquery/EventTriggerHook.js -  sap.ui.ModuleSystem'

We were able to reproduce this behavior locally in docker, spinning up the containers and executing the run command manually.

I'm unsure how I can debug this any further. Please get into contact, so I can provide you with the full logs and a repo with a minimum broken example.

Thank you very much for your support!

Hey everyone,

we face the exact same problem. If you only need UI5 resources, it is sufficient to set the ui5.url to https://sapui5.hana.ondemand.com. Nevertheless, in case you have other resources which are not available via the CDN, they can still not be loaded. Any help is highly appreciated!

BR Robert

Same issue here. All my OPA tests running in karma are now failing.

matz3 commented

This is likely related to a memory issue when running Chrome within Docker.
See https://developers.google.com/web/tools/puppeteer/troubleshooting#tips

The karma-chrome-launcher adds the --disable-dev-shm-usage flag by default (karma-runner/karma-chrome-launcher@137005d).

I would have hoped the selenium docker image also did this by default... Do you know how to set this through the webdriver-launcher or wd?

This naive configuration attempt similar to the chrome launcher failed:

      ChromeSelenium: {
        base: "WebDriver",
        config: {
          hostname: process.env.PIPER_SELENIUM_WEBDRIVER_HOSTNAME,
          port: process.env.PIPER_SELENIUM_WEBDRIVER_PORT
        },
        flags: ["--disable-dev-shm-usage"],
        browserName: "chrome",
        name: "Chrome"
      },

Logs:

info  karmaExecuteTests - �[36m21 03 2022 15:02:03.369:DEBUG [WebDriver]: �[39mWebDriver config: {"hostname":"selenium","port":"4444"}
info  karmaExecuteTests - �[36m21 03 2022 15:02:03.369:DEBUG [WebDriver]: �[39mBrowser capabilities: {"platform":"ANY","testName":"Karma test","tags":[],"version":"","base":"WebDriver","flags":["--disable-dev-shm-usage"],"browserName":"chrome","name":"Chrome"}
...
error karmaExecuteTests - Chrome 99.0.4844.74 (Linux x86_64) ERROR: '2022-03-21 15:02:08.004199 failed to load JavaScript resource: sap/ui/test/pipelines/ActionPipeline.js -  sap.ui.ModuleSystem'
error karmaExecuteTests - Chrome 99.0.4844.74 (Linux x86_64) ERROR: '2022-03-21 15:02:08.010399 failed to load JavaScript resource: sap/ui/test/_ParameterValidator.js -  sap.ui.ModuleSystem'
matz3 commented

As the problem is not specific to this plugin, I'm closing this issue.

For anyone finding this issue: I have discovered a way to pass the required options:

      ChromeSelenium: {
        base: "WebDriver",
        browserName: "chrome",
        name: "Chrome",
        config: {
          hostname: process.env.PIPER_SELENIUM_WEBDRIVER_HOSTNAME,
          port: process.env.PIPER_SELENIUM_WEBDRIVER_PORT
        },
        "goog:chromeOptions": {
            args: [
                "--disable-gpu",
                "--no-sandbox",
                "--window.size=1920,1080",
                "--headless",
                "--disable-dev-shm-usage",
                "--disable-background-timer-throttling"
            ]
        }
      },

This way, the tests pass. I don't know, if there is some FAQ document this could be added to.