Behat docker and fake video/audio input

Behat docker and fake video/audio input

Mark van Hoek -
回帖数:3
Core developers的头像 Plugin developers的头像

I am trying to do Behat testing on a plugin that requires access to the webcam video and audio, but I can't get Selenium to pick up the media feed. Any suggestions?

I am using moodle-docker on Moodle 4.x.

I have done the following:

1. Mount audio and video files:
services:
  webserver:
    volumes:
      - /home/somewhere/mixkit-office-ambience-447.wav:/var/www/behatdata/fake_video.y4m
      - /home/somewhere/deadline_cif.y4m:/var/www/behatdata/fake_audio.wav


2. Verify they show up in the webserver filesystem

root@b87870f03247:/var/www/html# ls -latrh /var/www/behatdata/
-rw-rw-r--  1     1000 1000 200M Oct 16 03:44 fake_audio.wav
-rw-rw-r--  1     1000 1000 7.1M Oct 16 03:56 fake_video.y4m


3. Add chromeOptions to config.php and verify they are included correctly in the resulting array:

getenv('MOODLE_DOCKER_APP') && $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--disable-web-security';
getenv('MOODLE_DOCKER_APP') && $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--use-fake-ui-for-media-stream';
getenv('MOODLE_DOCKER_APP') && $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--use-fake-device-for-media-stream';
getenv('MOODLE_DOCKER_APP') && $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--use-file-for-fake-video-capture=/home/www/behatdata/fake_video.y4m';
getenv('MOODLE_DOCKER_APP') && $CFG->behat_profiles['default']['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--use-file-for-fake-audio-capture=/home/www/behatdata/fake_audio.wav';


4. Logs from the selenium container (formatted JSON for readability):
--

selenium-1  | Starting Selenium Grid Standalone...
selenium-1  | Tracing is disabled
selenium-1  | 22:56:52.480 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
selenium-1  | 22:56:52.483 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
selenium-1  | 22:56:52.779 INFO [NodeOptions.getSessionFactories] - Detected 12 available processors
selenium-1  | 22:56:52.803 INFO [NodeOptions.report] - Adding chrome for {"browserName": "chrome","browserVersion": "120.0","goog:chromeOptions": {"binary": "\u002fusr\u002fbin\u002fgoogle-chrome"},"platformName": "linux","se:noVncPort": 7900,"se:vncEnabled": true} 1 times
selenium-1  | 22:56:52.813 INFO [Node.<init>] - Binding additional locator mechanisms: relative
selenium-1  | 22:56:52.822 INFO [GridModel.setAvailability] - Switching Node 10c370c2-533a-49f9-b171-cc678f8f204b (uri: http://192.168.144.5:4444) from DOWN to UP
selenium-1  | 22:56:52.823 INFO [LocalDistributor.add] - Added node 10c370c2-533a-49f9-b171-cc678f8f204b at http://192.168.144.5:4444. Health check every 120s
selenium-1  | 22:56:52.898 INFO [Standalone.execute] - Started Selenium Standalone 4.17.0 (revision e52b1be057*): http://192.168.144.5:4444
selenium-1  | 23:00:57.552 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 

selenium-1  | 23:00:58.106 INFO [LocalNode.newSession] - Session created by the Node. Id: ebe40a0b0775851c9ed969757ffe0e2e, Caps: Capabilities 
{
    "acceptInsecureCerts":false,
    "browserName":"chrome",
    "browserVersion":120.0.6099.224,
    "chrome":{
       "chromedriverVersion":120.0.6099.109 (3419140ab66...,
       "userDataDir":"/tmp/.org.chromium.Chromium..."
    },
    "fedcm":"accounts":true,
    "goog":"chromeOptions":{
       "debuggerAddress":"localhost":45269
    },
    "networkConnectionEnabled":false,
    "pageLoadStrategy":"normal",
    "platformName":"linux",
    "proxy":"Proxy()",
    "se":"bidiEnabled":false,
    "se":"cdp":"ws"::4444/ses...,
    "se":"cdpVersion":120.0.6099.224,
    "se":"vnc":"ws"::4444/ses...,
    "se":"vncEnabled":true,
    "se":"vncLocalAddress":"ws"::7900,
    "setWindowRect":true,
    "strictFileInteractability":false,
    "timeouts":{
       "implicit":0,
       "pageLoad":300000,
       "script":30000
    },
    "unhandledPromptBehavior":"dismiss and notify",
    "webauthn":"extension":"credBlob":true,
    "webauthn":"extension":"largeBlob":true,
    "webauthn":"extension":"minPinLength":true,
    "webauthn":"extension":"prf":true,
    "webauthn":"virtualAuthenticators":true
 }
selenium-1  | 23:00:58.109 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: ebe40a0b0775851c9ed969757ffe0e2e 
selenium-1  |  Caps: Capabilities 
{
   "acceptInsecureCerts":false,
   "browserName":"chrome",
   "browserVersion":120.0.6099.224,
   "chrome":{
      "chromedriverVersion":120.0.6099.109 (3419140ab66...,
      "userDataDir":"/tmp/.org.chromium.Chromium..."
   },
   "fedcm":"accounts":true,
   "goog":"chromeOptions":{
      "debuggerAddress":"localhost":45269
   },
   "networkConnectionEnabled":false,
   "pageLoadStrategy":"normal",
   "platformName":"linux",
   "proxy":"Proxy()",
   "se":"bidiEnabled":false,
   "se":"cdp":"ws"::4444/ses...,
   "se":"cdpVersion":120.0.6099.224,
   "se":"vnc":"ws"::4444/ses...,
   "se":"vncEnabled":true,
   "se":"vncLocalAddress":"ws"::7900,
   "setWindowRect":true,
   "strictFileInteractability":false,
   "timeouts":{
      "implicit":0,
      "pageLoad":300000,
      "script":30000
   },
   "unhandledPromptBehavior":"dismiss and notify",
   "webauthn":"extension":"credBlob":true,
   "webauthn":"extension":"largeBlob":true,
   "webauthn":"extension":"minPinLength":true,
   "webauthn":"extension":"prf":true,
   "webauthn":"virtualAuthenticators":true
}

selenium-1  | 23:01:24.267 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: ebe40a0b0775851c9ed969757ffe0e2e
selenium-1  | 23:01:24.268 INFO [GridModel.release] - Releasing slot for session id ebe40a0b0775851c9ed969757ffe0e2e
selenium-1  | 23:01:24.268 INFO [SessionSlot.stop] - Stopping session ebe40a0b0775851c9ed969757ffe0e2e

回复Mark van Hoek

Re: Behat docker and fake video/audio input

Mark Johnson -
Core developers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Hi Mark, I dont want to derail this but I'm interested in what you are actually testing here? Bearing in mind Behat wont be able to see or hear the audio/video, what is your test verifying? I'm wondering if there's a simpler way to achieve the same result.

回复Mark Johnson

Re: Behat docker and fake video/audio input

Mark van Hoek -
Core developers的头像 Plugin developers的头像
It's this plugin https://moodle.org/plugins/block_integrityadvocate/ . As a student, even in demo mode, it requires webcam and microphone, but if I can fake the audio/video that should suffice. ATM the IA side does not have a way to bypass that requirement.
The current tests are at https://github.com/mwithheld/moodle-block_integrityadvocate/blob/main/tests/behat/add_integrityadvocate_block_quiz.feature
I want tests for some interactions that happen (1) When the proctoring logic (remote code) loads; (2) When the proctoring actually begins (which is after the webcam/audio check); (3) After the proctoring session ends (e.g. subsequent quiz navigation pages).