aldefouw / redcap_cypress

REDCap Cypress Test Framework
MIT License
30 stars 32 forks source link

Adjustments to CDISC ODM process #56

Open aldefouw opened 3 years ago

aldefouw commented 3 years ago

The process for creating a project from CDISC ODM is currently requiring a project ID.

See the method definition for more details: https://github.com/aldefouw/redcap_cypress/blob/master/cypress/support/commands.js#L390-L407

We should probably move towards something more robust.

It would be nice if we could specify the project name and then looked up the project ID in the database ... will require some thought.

AndrewPoppe commented 3 years ago

Would it make sense to return the pid from the custom method itself and then chain from the method call?

Cypress.Commands.add('create_cdisc_project', (project_name, project_type, cdisc_file) => {

    //Run through the steps to import the project via CDISC ODM
    cy.visit_base({url: 'index.php?action=create'})
    cy.get('input#app_title').type(project_name)
    cy.get('select#purpose').select(project_type)
    cy.get('input#project_template_radio2').click()
    cy.upload_file(cdisc_file, 'xml', 'input[name="odm"]')
    cy.get('button').contains('Create Project').click().then(() => {
        cy.location('search').then((searchString) => {
            let params = new URLSearchParams(searchString)
            return params.get('msg') === 'newproject' && params.get('pid')
        })
    })

})

and then, e.g.

cy.create_cdisc_project('Example Project Title', '0', 'cdisc_files/core/logging.xml').then( (pid) => {
    cy.log(pid)
})
aldefouw commented 3 years ago

@AndrewPoppe - I think that's a good idea. You interested in seeing if that's possible?

AndrewPoppe commented 3 years ago

It works as written above in my environment. I think I'd just be concerned about some edge case in which project creation failed but it still returned a pid. I tried to avoid that by short circuiting based on the msg=newproject being present in the query string.

aldefouw commented 3 years ago

That's awesome, Andrew! Thanks for your work on this.

Regarding edge cases where project creation fails ...

I think your short circuit should be a good mitigation for most cases.

Since there's always a possibility for failure when doing the CDISC import, can you catch those expected failures you're aware of and return something to alert the user working on the test? For instance, you could return an alert window to tell the user writing the script that something had gone wrong and provide whatever error feedback you're able to.

I think the most important thing here is to make it clear to the user writing the test (or running the test) that something has gone wrong so they can take action to rectify the problem.

Thanks.