-
Notifications
You must be signed in to change notification settings - Fork 2
Using SharedBehaviors
Home - WebdriverIO testing - Creating a new WebdriverIO test - Using SharedBehaviors
SharedBehaviors provides a set of behaviors commonly needed to test a PsychoJS experiment. These behaviors are implemented as the following functions:
-
SharedBehaviors.performPavloviaPrelude(waitForCanvas = true, resourceTimeout = 20000)
Go through the experiment loading screen, click "OK", wait for the canvas to appear, and wait for any full-screen notifications to disappear. If you don't need to wait for the canvas, setwaitForCanvas
to false. If your experiment requires a lot of resources to be loaded, setresourceTimeout
to a higher number of milliseconds. This function returns a calibration object that can serve as rough calibration. -
SharedBehaviors.tapAtCoordinate(x, y)
Tap at a coordinate in the browser window. -
SharedBehaviors.waitForReport(value)
Wait for the data-report attribute of the document body to have the specified value. This is useful to have your bot wait for a particular PsychoPy routine. See Creating a new test experiment.
Since PsychoJS presents stimuli via a canvas element, you cannot use DOM selectors to have your bot tap a DOM element. Instead, you'll need to tap at coordinates on the screen. These coordinates can be calibrated in rough fashion or in a fine fashion. Below, both calibration procedures are illustrated, together with all of the other functions provided by SharedBehaviors.
The procedure below can be used if your taps do not need to be very accurate (i.e. tap somewhere in the center of the screen). This calibration procedure uses information returned by SharedBehaviors.performPavloviaPrelude()
. The procedure first starts your experiment, then calibrates.
run: () => {
// Go to the URL of your experiment (on your local webserver, staging server, or Pavlovia)
browser.url(browser.getExperimentUrl());
// Rough calibration
let calibration = SharedBehaviors.performPavloviaPrelude();
// Wait for the procedure called 'intro_trial'
document.body.setAttribute('data-report', 'intro_trial');
// Now we can tap roughly in the center of the screen as follows
SharedBehaviors.tapAtCoordinate(calibration.transformX(0), calibration.transformY(0));
}
The procedure below can be used if your taps do need to be accurate (i.e. tap at particular spot). This calibration procedure uses information obtained via a special calibration test (wdio_calibration). When you enable fine calibration in your test configuration file, the calibration test is automatically run before your test is run, with the fine calibration passed to the run
function. The procedure first calibrates, then starts your experiment.
run: (calibration = null) => {
// This experiment requires fine calibration; throw error if no calibration provided
if (calibration === null) {
throw new Error('test wdio_textbox requires fine calibration')
}
// Go to the URL of your experiment (on your local webserver, staging server, or Pavlovia)
browser.url(browser.getExperimentUrl());
// Wait for the procedure called 'intro_trial'
document.body.setAttribute('data-report', 'intro_trial');
// Tap at [0.25, 0.25] height coordinates
SharedBehaviors.tapAtCoordinate(calibration.transformX(0.25), calibration.transformY(0.25));
}