CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Codecept on ARM: How to change browser bin path

Open vipulgupta2048 opened this issue 4 years ago • 6 comments

What are you trying to achieve?

Trying to run Codecept on a raspberry pi4. All with a very basic setup, no changes to default configuration.

What do you get instead?

The browser crashes on startup, which is probably because the browser codecept default downloads and uses browser that might not be compatible with the ARM versions of those browsers. I have dealt with this situation quite a bit before and wanted to know if there is any way I can point Codecept to a path for the browser that I provide. I tried with all 3 browser alternatives that were available and they were giving similar errors. Below is the error from Firefox and Chromium.

Also, can I decide on NPM install for Codecept beforehand what to install in my system. I just want to make my script work with Chromium for, downloading other browsers isn't viable.

When running with Firefox

root@mymachine:/usr/src/core/codecept# npm run codeceptjs --verbose
npm info it worked if it ends with ok
npm verb cli [
npm verb cli   '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'run',
npm verb cli   'codeceptjs',
npm verb cli   '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'precodeceptjs', 'codeceptjs', 'postcodeceptjs' ]
npm info lifecycle [email protected]~precodeceptjs: [email protected]
npm info lifecycle [email protected]~codeceptjs: [email protected]

> [email protected] codeceptjs /usr/src/core/codecept
> codeceptjs run --steps

CodeceptJS v3.0.2
Using test root "/usr/src/core/codecept"

Wifi connect UI automation --
  ✖ "before all" hook: codeceptjs.beforeSuite for "Testing Wifi Connect captive portal" in 748ms
Error: browserType.launch: Protocol error (Browser.enable): Target closed.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/firefox-1205/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-ijc0N
E -juggler-pipe -silent
<launched> pid=4023
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 1: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: ELF: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 2: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: @8: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 3: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: @@@@0ppp�: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 4: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: �: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 5: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 8�: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 6: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: Syntax error: word unexpected (expe
cting ")")
<process did exit: exitCode=2, signal=null>
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.

-- FAILURES:

  1) Wifi connect UI automation
       "before all" hook: codeceptjs.beforeSuite for "Testing Wifi Connect captive portal":
     browserType.launch: Protocol error (Browser.enable): Target closed.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/firefox-1205/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-ijc0N
E -juggler-pipe -silent
<launched> pid=4023
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 1: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: ELF: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 2: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: @8: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 3: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: @@@@0ppp�: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 4: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: �: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 5: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 8�: not found
[err] /root/.cache/ms-playwright/firefox-1205/firefox/firefox: 6: /root/.cache/ms-playwright/firefox-1205/firefox/firefox: Syntax error: word unexpected (expe
cting ")")
<process did exit: exitCode=2, signal=null>
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
  browserType.launch: Protocol error (Browser.enable): Target closed.
  =========================== logs ===========================
  <launching> /root/.cache/ms-playwright/firefox-1205/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-ijc
0NE -juggler-pipe -silent
  
  


  FAIL  | 0 passed, 1 failed   // 770ms
Run with --verbose flag to see complete NodeJS stacktrace
npm verb lifecycle [email protected]~codeceptjs: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~codeceptjs: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/usr/src/core/codecept/node_module
s/.bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle [email protected]~codeceptjs: CWD: /usr/src/core/codecept
npm info lifecycle [email protected]~codeceptjs: Failed to exec codeceptjs script
npm verb stack Error: [email protected] codeceptjs: `codeceptjs run --steps`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
npm verb stack     at EventEmitter.emit (events.js:314:20)
npm verb stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:314:20)
npm verb stack     at maybeClose (internal/child_process.js:1021:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm verb pkgid [email protected]
npm verb cwd /usr/src/core/codecept
npm verb Linux 4.19.118
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "codeceptjs" "--verbose"
npm verb node v12.19.0
npm verb npm  v6.14.8
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] codeceptjs: `codeceptjs run --steps`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] codeceptjs script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm timing npm Completed in 4670ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-17T22_57_22_056Z-debug.log

When running with Chromium

root@ea6af1d8fbf8:/usr/src/core/codecept# npm run codeceptjs --verbose
npm info it worked if it ends with ok
npm verb cli [
npm verb cli   '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'run',
npm verb cli   'codeceptjs',
npm verb cli   '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'precodeceptjs', 'codeceptjs', 'postcodeceptjs' ]
npm info lifecycle [email protected]~precodeceptjs: [email protected]
npm info lifecycle [email protected]~codeceptjs: [email protected]

> [email protected] codeceptjs /usr/src/core/codecept
> codeceptjs run --steps

CodeceptJS v3.0.2
Using test root "/usr/src/core/codecept"

Wifi connect UI automation --
  ✖ "before all" hook: codeceptjs.beforeSuite for "Testing Wifi Connect captive portal" in 483ms
Error: browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInPr
ocess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-com
ponent-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTre
es,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disabl
e-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --pa
ssword-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-gZFGj7 --remote-debugging-pipe --no-sandbox --no-startup-window
<launched> pid=4132
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: ELF: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 2: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Ŭ: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 3: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Ŭ: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �
                                                                                                                                          : not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 8: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 
                                                                                                                                         ��@���
[err] �Ŭ
[err] �Ŭ
[err] �@��
          �
           �
            �R�td���
[err] �Ŭ
[err] �Ŭ
[err] �Hl@JlP�td$w�$w�$w�,80,80Q�td���XX/lib64/ld-linux-x86-64.so.2GNU INFOCrashpad�
[err] 
     NU�t�y��dBa p � �"�������9@EJOU[jp~����������
                                                  (/7?EKRYbiv��������������
[err] -39@Ghpw�������������
                           $: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 33: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Hl�Hl
                                                                                                                                                ������: not fo
und
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: Syntax error: word un
expected (expecting ")")
<process did exit: exitCode=2, signal=null>
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.

-- FAILURES:

  1) Wifi connect UI automation
       "before all" hook: codeceptjs.beforeSuite for "Testing Wifi Connect captive portal":
     browserType.launch: Protocol error (Browser.getVersion): Target closed.
=========================== logs ===========================
<launching> /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInPr
ocess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-com
ponent-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTre
es,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disabl
e-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --pa
ssword-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-gZFGj7 --remote-debugging-pipe --no-sandbox --no-startup-window
<launched> pid=4132
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: ELF: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 2: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Ŭ: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 3: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Ŭ: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �
                                                                                                                                          : not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 8: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 
                                                                                                                                         ��@���
[err] �Ŭ
[err] �Ŭ
[err] �@��
          �
           �
            �R�td���
[err] �Ŭ
[err] �Ŭ
[err] �Hl@JlP�td$w�$w�$w�,80,80Q�td���XX/lib64/ld-linux-x86-64.so.2GNU INFOCrashpad�
[err] 
     NU�t�y��dBa p � �"�������9@EJOU[jp~����������
                                                  (/7?EKRYbiv��������������
[err] -39@Ghpw�������������
                           $: not found
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 33: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: �Hl�Hl
                                                                                                                                                ������: not fo
und
[err] /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: 1: /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome: Syntax error: word un
expected (expecting ")")
<process did exit: exitCode=2, signal=null>
============================================================
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
  browserType.launch: Protocol error (Browser.getVersion): Target closed.
  =========================== logs ===========================
  <launching> /root/.cache/ms-playwright/chromium-827102/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceIn
Process --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-c
omponent-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyT
rees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disa
ble-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --
password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-gZFGj7 --remote-debugging-pipe --no-sandbox --no-startup-window
  
  


  FAIL  | 0 passed, 1 failed   // 504ms
Run with --verbose flag to see complete NodeJS stacktrace
npm verb lifecycle [email protected]~codeceptjs: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~codeceptjs: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/usr/src/core/codecept/node_module
s/.bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle [email protected]~codeceptjs: CWD: /usr/src/core/codecept
npm info lifecycle [email protected]~codeceptjs: Failed to exec codeceptjs script
npm verb stack Error: [email protected] codeceptjs: `codeceptjs run --steps`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
npm verb stack     at EventEmitter.emit (events.js:314:20)
npm verb stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:314:20)
npm verb stack     at maybeClose (internal/child_process.js:1021:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
npm verb pkgid [email protected]
npm verb cwd /usr/src/core/codecept
npm verb Linux 4.19.118
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "codeceptjs" "--verbose"
npm verb node v12.19.0
npm verb npm  v6.14.8
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] codeceptjs: `codeceptjs run --steps`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] codeceptjs script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm timing npm Completed in 4375ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-17T22_59_48_399Z-debug.log

Provide test source code if related

The test file is navigating to google.com, nothing special there.

Details

  • CodeceptJS version: 3.0.2
  • NodeJS Version: v12.19.0
  • Operating System: Debian Buster (armv7hf)
  • puppeteer
  • Configuration file:
const { setHeadlessWhen } = require('@codeceptjs/configure');

// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

exports.config = {
  tests: 'src/*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      url: 'http://localhost',
      show: true,
      browser: 'firefox'
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'codecept',
  plugins: {
	retryFailedStep: {
		enabled: true
	},
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  }
}

vipulgupta2048 avatar Dec 17 '20 23:12 vipulgupta2048

What version of playwright do you use?

elukoyanov avatar Dec 21 '20 14:12 elukoyanov

@elukoyanov I am using 1.7.0 Couple of strategies I have explored/yet to explore. What do you think would have the best chance?

  1. Set manualStart=true and write a codecept helper to make sure the right browser is started (Playwright wouldn't like that probably because they are downloading binaries of chromium, rather than debian ARM package of Chromium)
  2. Use the right executable as playwright maintainers mention here https://github.com/microsoft/playwright/issues/2834
  3. Replace the chromium-browser that playwright downloads with the latest chromium Linux_ARM_cross_compile using the build script they provide here

I am going with the 3rd approach on my raspberrypi3

They also had this issue https://github.com/microsoft/playwright/issues/1243

vipulgupta2048 avatar Dec 22 '20 07:12 vipulgupta2048

We tried all 3 ways, can you confirm that there are just 3 objects available for use inside the Playwright API with this I.usePlaywrightTo command.

I.usePlaywrightTo('emulate offline mode', async ({ browser, context, page }) => {
  // use browser, page, context objects inside this function
  await context.setOffline(true);
});

There seems to be no way to access, browsertype.executablePath() API of playwright using codecept.

vipulgupta2048 avatar Dec 22 '20 14:12 vipulgupta2048

@elukoyanov Any ideas here? I be to happy to try more things if you can suggest.

vipulgupta2048 avatar Jan 10 '21 08:01 vipulgupta2048

Hey @vipulgupta2048, not sure this is still relevant, as the question is a year old, but I'm posting anyways in case it helps someone. We're also running CodeceptJS on a raspberry pi 4 and I remember struggling with an incorrect path to the browser binary, as well. We ended up just symlinking to the binary that it wanted. This is our Dockerfile:

FROM node:14

LABEL maintainer="Hanna Becker" \
      description="Cosonify CI image" \
      version="0.1.0"

RUN apt-get update && apt-get upgrade -y
RUN apt-get install chromium chromium-l10n awscli -y
RUN ln -s /usr/bin/chromium /usr/bin/chromium-browser    # <-- symlinking to working Chromium binary
[...]

Having said that, it was about half a year ago that we struggled with this, so things may have been fixed by now.

Note: We're using CodeceptJS with Puppeteer.

hanna-becker avatar Feb 21 '22 03:02 hanna-becker

@hanna-becker Thanks for reaching out, I appreciate you mentioning the solution on the thread to help others. Symlinking the binary is a great solution, especially when you start using node-alpine where the location of the chromium binary is different than on ubuntu. We use that as a solution in several places when using puppeteer, especially when building cross-platform applications: https://github.com/balena-io-playground/meetbot/blob/fd6c4619e63210f84bb710d9afea2f6bc370af12/src/browser.ts#L27-L31

This however doesn't help our usecase where path to binaries were pre-determined by the framework (Playwright) and couldn't be changed. Playwright has since changed and works like a charm.

vipulgupta2048 avatar Feb 23 '22 21:02 vipulgupta2048