mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-73853 core_h5p: Improve behat tests, to avoid random errors
An improvement has been added to the H5P tests to avoid random errors due to the fact that H5P content needs a while to be displayed. Co-author: Ferran Recio <ferran@moodle.com>
This commit is contained in:
parent
288963e526
commit
f23fe5195a
@ -97,7 +97,24 @@ H5PEmbedCommunicator = (function() {
|
||||
return (window.postMessage && window.addEventListener ? new Communicator() : undefined);
|
||||
})();
|
||||
|
||||
document.onreadystatechange = function() {
|
||||
var getH5PObject = async (iFrame) => {
|
||||
var H5P = iFrame.contentWindow.H5P;
|
||||
if (H5P?.instances?.[0]) {
|
||||
return H5P;
|
||||
}
|
||||
|
||||
// In some cases, the H5P takes a while to be initialized (which causes some random behat failures).
|
||||
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
|
||||
let remainingAttemps = 10;
|
||||
while (!H5P?.instances?.[0] && remainingAttemps > 0) {
|
||||
await sleep(100);
|
||||
H5P = iFrame.contentWindow.H5P;
|
||||
remainingAttemps--;
|
||||
}
|
||||
return H5P;
|
||||
};
|
||||
|
||||
document.onreadystatechange = async() => {
|
||||
// Wait for instances to be initialize.
|
||||
if (document.readyState !== 'complete') {
|
||||
return;
|
||||
@ -108,10 +125,8 @@ document.onreadystatechange = function() {
|
||||
if (!iFrame || !iFrame.contentWindow) {
|
||||
return;
|
||||
}
|
||||
var H5P = iFrame.contentWindow.H5P;
|
||||
|
||||
// Check for H5P instances.
|
||||
if (!H5P || !H5P.instances || !H5P.instances[0]) {
|
||||
var H5P = await getH5PObject(iFrame);
|
||||
if (!H5P?.instances?.[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
@mod @mod_h5pactivity @core_h5p @_file_upload @_switch_iframe
|
||||
@mod @mod_h5pactivity @core_h5p @_file_upload @_switch_iframe @javascript
|
||||
Feature: Users can see the H5P recent activity from the recent activity block
|
||||
In order to quickly see the updates from H5P activity in my course
|
||||
As a user
|
||||
@ -31,6 +31,7 @@ Feature: Users can see the H5P recent activity from the recent activity block
|
||||
And I add the "Recent activity" block
|
||||
And I log out
|
||||
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1
|
||||
# The H5P content needs some time to be displayed (so better to wait for 1 second to avoid random errors).
|
||||
And I switch to "h5p-player" class iframe
|
||||
And I switch to "h5p-iframe" class iframe
|
||||
And I click on "Wrong one" "text" in the ".h5p-question-content" "css_element"
|
||||
@ -38,6 +39,7 @@ Feature: Users can see the H5P recent activity from the recent activity block
|
||||
And I switch to the main frame
|
||||
And I log out
|
||||
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student2
|
||||
# The H5P content needs some time to be displayed (so better to wait for 1 second to avoid random errors).
|
||||
And I switch to "h5p-player" class iframe
|
||||
And I switch to "h5p-iframe" class iframe
|
||||
And I click on "Correct one" "text" in the ".h5p-question-content" "css_element"
|
||||
@ -45,7 +47,6 @@ Feature: Users can see the H5P recent activity from the recent activity block
|
||||
And I switch to the main frame
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: Student see only his own activity
|
||||
Given I am on the "Course 1" course page logged in as student1
|
||||
And I should see "H5P submitted:" in the "Recent activity" "block"
|
||||
@ -58,7 +59,6 @@ Feature: Users can see the H5P recent activity from the recent activity block
|
||||
And I should not see "Grade:"
|
||||
And I should not see "Student 2 - "
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher see each student activity
|
||||
Given I am on the "Course 1" course page logged in as teacher1
|
||||
And I should see "H5P submitted:" in the "Recent activity" "block"
|
||||
|
Loading…
x
Reference in New Issue
Block a user