diff --git a/lib/scope.js b/lib/scope.js index 91f87820..7b7fb97a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -260,16 +260,16 @@ module.exports = { * - Birthdate fields that will be showing up relatively soon * - Time fields? */ - let base64_name = await scope.base64( scope, var_name ); + let base64_var_name = await scope.base64( scope, var_name ); // Will catch some radio and checkbox inputs too, which will then be rejected // Note: I think `showif`s with `code` don't use `data-saveas` let to_manipulate = await Promise.race([ - scope.page.waitForSelector(`button[name="${base64_name}"][value="${value}"]`), // button - scope.page.waitForSelector(`:not(button)[name="${base64_name}"]`), // others (not showif) - scope.page.waitForSelector(`*[data-saveas="${base64_name}"] input`), // text input showif - scope.page.waitForSelector(`*[data-saveas="${base64_name}"] textarea`), // textarea showif - scope.page.waitForSelector(`*[data-saveas="${base64_name}"] select`), // select showif/hideif + scope.page.waitForSelector(`button[name="${base64_var_name}"][value="${value}"]`), // button + scope.page.waitForSelector(`:not(button)[name="${base64_var_name}"]`), // others (not showif) + scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] input`), // text input showif + scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] textarea`), // textarea showif + scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] select`), // select showif/hideif ]); // Throw error for checkboxes and radios @@ -353,36 +353,36 @@ module.exports = { let wants_to_sign = set_to === '/sign'; // All the possible variations of name attribute values - let base64_name = await scope.base64( scope, var_name ); - let base64_id_of_first_choice = base64_name + '_0'; + let base64_var_name = await scope.base64( scope, var_name ); + let base64_id_of_first_choice = base64_var_name + '_0'; let { name_attr_B, name_attr_R } = await scope.checkboxNameAttribute( scope, var_name, choice_name ); // Note: I think `showif`s with `code` don't use `data-saveas` // Note: Choices created without variable names cannot be language agnostic let selectors = [ - `button[name="${ base64_name }"][value="${ choice_name }"]`, // button - `button[name="${ base64_name }"][value="${ set_to }"]`, // button - `*[data-saveas="${ base64_name }"] input`, // text input showif - `*[data-saveas="${ base64_name }"] textarea`, // textarea showif - `*[data-saveas="${ base64_name }"] select`, // select showif/hideif + `button[name="${ base64_var_name }"][value="${ choice_name }"]`, // button + `button[name="${ base64_var_name }"][value="${ set_to }"]`, // button + `*[data-saveas="${ base64_var_name }"] input`, // text input showif + `*[data-saveas="${ base64_var_name }"] textarea`, // textarea showif + `*[data-saveas="${ base64_var_name }"] select`, // select/dropdown showif/hideif // Radios and checkboxes // radio: `name` = base64 var name, `choice_name` = var name of choice // `yesno`/`noyes` checkbox: `name` = base64 var name, choice always 'True' // checkbox: `name` = base64 var name + stuff + base64 choice var name + stuff (see function) - `input[name="${ base64_name }"][value="${ choice_name }"]`, // radio - `input[name="${ base64_name }"][value="${ set_to }"]`, // radio - `*[data-saveas="${ base64_name }"] input[value="${ choice_name }"]`, // radio showif - `*[data-saveas="${ base64_name }"] input[value="${ set_to }"]`, // radio showif - `input[name="${ base64_name }"][value="True"]`, // yesno/noyes checkbox - `*[data-saveas="${ base64_name }"] input[value="True"]`, // yesno/noyes checkbox showif + `input[name="${ base64_var_name }"][value="${ choice_name }"]`, // radio + `input[name="${ base64_var_name }"][value="${ set_to }"]`, // radio + `*[data-saveas="${ base64_var_name }"] input[value="${ choice_name }"]`, // radio showif + `*[data-saveas="${ base64_var_name }"] input[value="${ set_to }"]`, // radio showif + `input[name="${ base64_var_name }"][value="True"]`, // yesno/noyes checkbox + `*[data-saveas="${ base64_var_name }"] input[value="True"]`, // yesno/noyes checkbox showif // Finds the group by looking for the first checkbox in the group using id, then works its way back out again // 'none of the above' checkbox showif??? `input[name="${ name_attr_B }"]`, // checkbox `input[name="${ name_attr_R }"]`, // checkbox alt ]; - let handle = await scope.page.evaluateHandle(({ selectors, base64_id_of_first_choice, base64_name }) => { + let handle = await scope.page.evaluateHandle(({ selectors, base64_id_of_first_choice, base64_var_name }) => { for ( let selector of selectors ) { // `set_to` may sometimes not be appropriate for some of the selectors. // It's a bit of a wild child, but we need to stay true to it so it'll @@ -404,7 +404,7 @@ module.exports = { } // others (not showif) - let other = document.querySelector(`:not(button)[name="${ base64_name }"]`); + let other = document.querySelector(`:not(button)[name="${ base64_var_name }"]`); if ( other ) { return other; } // signature page will need special treatment @@ -412,7 +412,7 @@ module.exports = { if ( is_signature_page ) { return 'signature'; } return null; - }, { selectors, base64_id_of_first_choice, base64_name }); + }, { selectors, base64_id_of_first_choice, base64_var_name }); // can take longer to load. All online signature pages have canvases. if ( handle.constructor.name !== 'ElementHandle' ) { @@ -463,7 +463,18 @@ module.exports = { await scope.afterStep(scope); // No showifs for this one? }, SELECT: async function ( scope, { handle, set_to }) { - await handle.select( set_to ); + // A dropdown's option value can be one of two things + // Try to find the element using the first value + let option = await scope.page.$(`option[value="${ set_to }"]`); + if ( option ) { + await handle.select( set_to ); // And use that value to set it + + // If that value isn't on the page, it should be the second type of value + } else { + let base64_name = await scope.base64( scope, set_to ); + await handle.select( base64_name ); + } + await scope.afterStep(scope, { waitForShowIf: true }); }, CANVAS: async function ( scope, { handle, set_to }) { diff --git a/package.json b/package.json index b1144a72..d0929348 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docassemble-cucumber", - "version": "1.2.2", + "version": "1.2.2-hf-object-dropdowns.1", "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.", "main": "lib/index.js", "scripts": {