Skip to content

Commit

Permalink
Restore SWR test timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianoertel committed Jan 15, 2025
1 parent 8bc8f43 commit 4b8c1d4
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions cypress/support/helper-functions/roar-swr/swrHelpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { languageOptions } from './languageOptions';

const baseTimeout = Cypress.env('timeout');

const CLEVER_SCHOOL_NAME = Cypress.env('CLEVER_SCHOOL_NAME');
const CLEVER_USERNAME = Cypress.env('CLEVER_USERNAME');
const CLEVER_PASSWORD = Cypress.env('CLEVER_PASSWORD');
Expand All @@ -22,19 +24,23 @@ export const playSWR = ({
cy.loginWithClever(CLEVER_SCHOOL_NAME, CLEVER_USERNAME, CLEVER_PASSWORD);
}

cy.waitForParticipantHomepage();
cy.selectAdministration(administration);

if (optional === true) {
cy.log('Switching to optional assessments.');
cy.switchToOptionalAssessments();
}

cy.get('.p-tabview').contains(languageOptions[language].gameTab).should('exist');
cy.get('.p-tabview', { timeout: baseTimeout }).contains(languageOptions[language].gameTab).should('exist');
cy.visit(languageOptions[language].url);

cy.waitForAssessmentReadyState();
cy.get('.jspsych-btn').click();
cy.get('.jspsych-btn', { timeout: 18 * baseTimeout })
.should('be.visible')
.click();

cy.wait(0.1 * baseTimeout);
Cypress.on('uncaught:exception', () => {
return false;
});
Expand All @@ -44,14 +50,13 @@ export const playSWR = ({

function playSWRGame(administration, language, optional = false) {
// play tutorial
cy.contains(languageOptions[language].introText);
cy.contains(languageOptions[language].introText, { timeout: baseTimeout });
for (let i = 0; i < 3; i++) {
cy.get('body').type('{leftarrow}');
cy.get('body', { timeout: baseTimeout }).type('{leftarrow}');
}

cy.waitUntil(() => cy.get('.jspsych-btn').should('be.visible'));
cy.get('.jspsych-btn').click();

cy.get('.jspsych-btn', { timeout: 10 * baseTimeout })
.should('be.visible')
.click();
Cypress.on('uncaught:exception', () => {
return false;
});
Expand All @@ -68,60 +73,66 @@ function playSWRGame(administration, language, optional = false) {

// check if game completed
cy.visit('/');
cy.wait(1);
cy.wait(0.2 * baseTimeout);

cy.waitForParticipantHomepage();
cy.selectAdministration(administration);

if (optional === true) {
cy.log('Switching to optional assessments.');
cy.switchToOptionalAssessments();
}
cy.get('.p-tabview').contains(languageOptions[language].gameTab).should('exist');
cy.get('.p-tabview', { timeout: baseTimeout }).contains(languageOptions[language].gameTab).should('exist');
}

function playIntro(language) {
for (let i = 0; i <= 5; i++) {
cy.log(i);
cy.wait(1);
cy.get('body').type('{leftarrow}{rightarrow}');
cy.wait(1);
cy.get('body').type('{leftarrow}{rightarrow}');
cy.wait(1);
cy.wait(0.2 * baseTimeout);
cy.get('body').type('{leftarrow}{rightarrow}', { timeout: 5 * baseTimeout });
cy.wait(0.2 * baseTimeout);
cy.get('body').type('{leftarrow}{rightarrow}', { timeout: 2 * baseTimeout });
cy.wait(0.2 * baseTimeout);
}
cy.get('.jspsych-btn').contains(languageOptions[language].continue).click();
cy.get('.jspsych-btn', { timeout: 5 * baseTimeout })
.contains(languageOptions[language].continue)
.click();
Cypress.on('uncaught:exception', () => {
return false;
});
}

function playSWRBlock(language, block_termination_phrase) {
cy.wait(Cypress.env('timeout'));
cy.get('body').then((body) => {
cy.wait(0.3 * baseTimeout);
cy.get('body', { timeout: 5 * baseTimeout }).then((body) => {
cy.log('entering stage: ', block_termination_phrase);
if (!body.find('.stimulus').length > 0) {
cy.get('body').type('{leftarrow}');
cy.get('.jspsych-btn').contains(languageOptions[language].continue).click();
cy.get('body', { timeout: baseTimeout }).type('{leftarrow}');
cy.get('.jspsych-btn', { timeout: 5 * baseTimeout })
.contains(languageOptions[language].continue, { timeout: 5 * baseTimeout })
.click();
Cypress.on('uncaught:exception', () => {
return false;
});
} else {
cy.get('body').type('{rightarrow}');
cy.get('body').type('{leftarrow}');
cy.get('body', { timeout: baseTimeout }).type('{rightarrow}');
cy.get('body', { timeout: baseTimeout }).type('{leftarrow}');
playSWRBlock(language, block_termination_phrase);
}
});
}

function finishSWR(block_termination_phrase) {
cy.wait(Cypress.env('timeout'));
cy.get('body').then((body) => {
cy.wait(0.3 * baseTimeout);
cy.get('body', { timeout: 5 * baseTimeout }).then((body) => {
if (!body.find('.stimulus').length > 0) {
assert(cy.contains(block_termination_phrase));
cy.wait(1);
cy.get('body').type('{leftarrow}');
cy.wait(0.2 * baseTimeout);
cy.get('body', { timeout: 5 * baseTimeout }).type('{leftarrow}');
} else {
// cy.get(".stimulus").should("be.visible");
cy.wait(1);
cy.get('body').type('{rightarrow}');
cy.wait(0.2 * baseTimeout);
cy.get('body', { timeout: 5 * baseTimeout }).type('{rightarrow}');
finishSWR(block_termination_phrase);
}
});
Expand Down

0 comments on commit 4b8c1d4

Please sign in to comment.