Skip to content

Commit

Permalink
Merge pull request #129 from MichaelPesce/parameter-sweep-test
Browse files Browse the repository at this point in the history
Update E2E testing to run parameter sweep tests for all flowsheets
  • Loading branch information
MichaelPesce authored Jul 31, 2024
2 parents bac49e9 + b8c20a4 commit 70678be
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:

- name: Cypress e2e tests
working-directory: electron/ui
timeout-minutes: 15
timeout-minutes: 45
run: npx cypress run

- name: Upload artifact for screenshots & videos
Expand Down
2 changes: 1 addition & 1 deletion electron/ui/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ module.exports = defineConfig({
on('task', {downloadFile});
},
baseUrl: 'http://localhost:3000',
video: true
video: false
},
});
196 changes: 97 additions & 99 deletions electron/ui/cypress/e2e/FlowsheetTesting.cy.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,55 @@

import { flowsheets } from "./Flowsheets"
describe('WaterTAP UI Testing', () => {
it('tests flowsheets-list page', () => {
cy.load_flowsheets_list()
cy.screenshot('loaded flowsheet list page')

//locate heading
// verify that heading and table headers are present
cy.findByRole('heading', { name: /flowsheets/i})

//locate table headers
cy.findByRole('columnheader', { name: /flowsheet name/i})
cy.findByRole('columnheader', { name: /last run/i})
cy.screenshot('end-list-page-test')

})

it('tests individual optimization', () => {
cy.load_flowsheets_list()
cy.screenshot('loaded flowsheet list page')

cy.load_ro_flowsheet()
cy.screenshot('loaded RO flowsheet');

cy.set_ro_flowrate('0.96')
cy.set_ro_flowrate('0.96')
cy.screenshot('set flowrate to 0.96')


cy.set_ro_flowrate('0.96')
cy.set_ro_flowrate('0.96')
cy.screenshot('set flowrate to 0.96')


cy.solve_flowsheet()
cy.screenshot("solved flowshet")


// Click save configuration button
cy.findByRole('button', {name: /save configuration/i}).click()
cy.wait(1000)
cy.screenshot('pre saveConfig')


// Clear preset name and enter new name
cy.wait(1000)
cy.get('.MuiInput-input').should('be.visible')
cy.get('.MuiInput-input', {timeout: 10000}).clear({force: true})
cy.get('.MuiInput-input', {timeout: 10000}).type('new_test_configuration', {force: true})
cy.screenshot('saveConfig')


// Click on save (config) and wait for api response
cy.save_configuration()
cy.screenshot('saved config')


// Click compare tab
cy.findByRole('tab', {name: /compare/i}).click()
cy.wait(5000)

// Verify that new name is shown in comparison table
cy.findAllByRole('tabpanel', {name: /compare/i})

cy.screenshot('end-solve-test')
cy.screenshot('end-list-page-test')
})

it('tests invalid inputs', () => {
cy.load_flowsheets_list()
cy.screenshot('loaded flowsheet list page')

cy.load_ro_flowsheet()
// load flowsheet
cy.load_flowsheet("RO with energy recovery flowsheet")
cy.screenshot('loaded RO flowsheet');

// set invalid text input. do it twice to ensure it registers in slow windows runner
cy.set_ro_flowrate('dfas');
cy.wait(1000)
cy.set_ro_flowrate('dfas');
cy.wait(1000)
cy.screenshot('invalid-text-input');

// solve flowsheet
cy.solve_flowsheet()
cy.screenshot('error-message');
cy.get('.error-message').should('be.visible')

cy.set_ro_flowrate('-10');
cy.screenshot('invalid-negative-input');

cy.solve_flowsheet()
// verify that error message is there
cy.screenshot('error-message');

cy.get('.error-message').should('be.visible')

// reset flowsheet
cy.reset_flowsheet()
cy.screenshot('end-invalid-input-test');

})

it('tests logging panel', () => {
cy.load_flowsheets_list()
cy.wait(2000)
cy.screenshot('loaded flowsheet list page')

// open logging panel
cy.open_logging_panel()
cy.screenshot('opened_logs')

// check that a log line of type info, warning, are present
// verify that a log line of type info and warning are present
cy.get('.log-line').contains('INFO')
cy.get('.log-line').contains('WARNING')

cy.screenshot('end-logging-test')
})

Expand All @@ -114,9 +63,9 @@ describe('WaterTAP UI Testing', () => {
cy.downloadFile(modelFile,'cypress/downloads','testModelFile.py')
cy.downloadFile(exportFile,'cypress/downloads','testModelFile_ui.py')

// click new flowsheet button
cy.findByRole('button', {name: /new flowsheet +/i}).click()
cy.wait(500)

cy.screenshot("clicked new flowsheet")

// select both files
Expand All @@ -128,50 +77,99 @@ describe('WaterTAP UI Testing', () => {
action: 'drag-drop',
force: true
})

cy.wait(500)
cy.screenshot("dragged and dropped files")

// click upload
cy.get('.upload-flowsheet-button').click()

cy.wait(1000)
cy.screenshot("uploaded files")

// verify that flowsheet is now in list
cy.get('.flowsheet-name').contains(/test custom flowsheet/i)
cy.screenshot('end-new-flowsheet-test')

})

it('tests parameter sweep', () => {
cy.load_flowsheets_list()
cy.screenshot('loaded flowsheet list page')

cy.load_ro_flowsheet()
cy.screenshot('loaded RO flowsheet')

// set solve type to sweep
cy.get('#solve-sweep-select').click()
cy.wait(100)
cy.get('#sweep-option').click()
cy.wait(1000)

// set sweep variable
cy.get('.Watermassflowrate_fixed-free-select').click()
cy.wait(100)
cy.findByRole('option', { name: /sweep/i }).click()
cy.wait(100)

// enter lower and upper bounds
cy.enter_text('class', 'Watermassflowrate_lower_input', '0.7')
cy.enter_text('class', 'Watermassflowrate_upper_input', '0.8')

// run sweep
cy.solve_flowsheet()
cy.wait(5000)
cy.screenshot("ran parameter sweep")
flowsheets.forEach((flowsheet) => {
it('tests optimization for '+flowsheet.name, () => {
cy.load_flowsheets_list()
cy.wait(2000)
cy.screenshot('loaded flowsheet list page')

// load flowsheet
cy.load_flowsheet(flowsheet.name)
cy.screenshot('loaded '+flowsheet.name);

// if model has build options, it must be manually built
if (flowsheet.buildRequired) {
cy.build_flowsheet()
cy.screenshot("built "+flowsheet.name)
}

// solve flowsheet
cy.solve_flowsheet()
cy.screenshot("solved "+flowsheet.name)

// Click save configuration button
cy.findByRole('button', {name: /save configuration/i}).click()
cy.wait(1000)
cy.screenshot('pre saveConfig for '+flowsheet.name)

// Clear preset name and enter new name
cy.wait(1000)
cy.get('.MuiInput-input').should('be.visible')
cy.get('.MuiInput-input', {timeout: 10000}).clear({force: true})
cy.get('.MuiInput-input', {timeout: 10000}).type('new_test_configuration', {force: true})
cy.screenshot('saveConfig')

// Click on save (config) and wait for api response
cy.save_configuration()
cy.screenshot('saved config for '+flowsheet.name)

// Click compare tab
cy.findByRole('tab', {name: /compare/i}).click()
cy.wait(5000)

// Verify that new name is shown in comparison table
cy.findAllByRole('tabpanel', {name: /compare/i})
cy.screenshot('end-solve-'+flowsheet.name)
})
})

//test that sweep was successful
cy.get('.parameter-sweep-output-table').should('be.visible')
flowsheets.forEach((flowsheet) => {
it('tests parameter sweep '+flowsheet.name, () => {
cy.load_flowsheets_list()
cy.screenshot('loaded flowsheet list page')

// load flowsheet
cy.load_flowsheet(flowsheet.name)
cy.screenshot('loaded '+flowsheet.name)

// set solve type to sweep
cy.get('#solve-sweep-select').click()
cy.wait(100)
cy.get('#sweep-option').click()
cy.wait(1000)

// set sweep variable
cy.get('.'+flowsheet.sweepVariable+'_fixed-free-select').click()
cy.wait(100)
cy.findByRole('option', { name: /sweep/i }).click()
cy.wait(100)

// enter lower and upper bounds
cy.enter_text('class', flowsheet.sweepVariable+'_lower_input', flowsheet.sweepValues[0])
cy.enter_text('class', flowsheet.sweepVariable+'_upper_input', flowsheet.sweepValues[1])

// run sweep
cy.solve_flowsheet()
cy.wait(5000)
cy.screenshot('ran parameter sweep '+flowsheet.name)

// verify that sweep was successful
cy.get('.parameter-sweep-output-table').should('be.visible')

})
})
})
68 changes: 68 additions & 0 deletions electron/ui/cypress/e2e/Flowsheets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export const flowsheets = [
{
name: 'NF-DSPM-DE flowsheet',
buildRequired: true,
sweepVariable: 'Volumetricflowrate',
sweepValues: ['3500', '3600']
},
{
name: 'BSM2 flowsheet',
buildRequired: false,
sweepVariable: 'Feedvolumetricflowrate',
sweepValues: ['20000', '21000'],
},
{
name: 'BSM2_P_extension flowsheet',
buildRequired: false,
sweepVariable: 'Feedvolumetricflowrate',
sweepValues: ['20000', '21000'],
},
{
name: 'Dye Desalination flowsheet',
buildRequired: false,
sweepVariable: 'Volumetricflowrate',
sweepValues: ['270', '290'],
},
{
name: 'Mechanical vapor compression flowsheet',
buildRequired: false,
sweepVariable: 'Feedmassflow',
sweepValues: ['35','45'],
},
{
name: 'RO with energy recovery flowsheet',
buildRequired: false,
sweepVariable: 'Watermassflowrate',
sweepValues: ['0.7','0.8'],
},
{
name: 'OARO flowsheet',
buildRequired: true,
sweepVariable: 'Watermassflowrate',
sweepValues: ['5','6'],
},
{
name: 'Granular Activated Carbon (GAC) flowsheet',
buildRequired: true,
sweepVariable: 'Apparentdensity',
sweepValues: ['700','800'],
},
{
name: 'Electrodialysis with concentrate recirculation flowsheet',
buildRequired: false,
sweepVariable: 'Feedsolutionvolumeflowrate',
sweepValues: ['0.001','0.002'],
},
{
name: 'LSRRO flowsheet',
buildRequired: true,
sweepVariable: 'Pump1outletpressure',
sweepValues: ['80','90'],
},
{
name: 'Generic treatment train flowsheet',
buildRequired: false,
sweepVariable: 'Desal1waterrecovery',
sweepValues: ['80','90'],
},
]
Loading

0 comments on commit 70678be

Please sign in to comment.