|
1 | | -/* eslint-disable no-undef */ |
2 | | - |
3 | 1 | /** |
4 | | - * Retrieves a form footer button by its name and type. |
| 2 | + * Retrieves a form footer button by its text content and type using an object parameter. |
5 | 3 | * |
6 | | - * @param {string} name - The name or text content of the button. |
7 | | - * @param {string} [type='button'] - The HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'. |
| 4 | + * @param {Object} options - The options object. |
| 5 | + * @param {string} options.buttonText - The text content of the button (required). |
| 6 | + * @param {string} [options.buttonType='button'] - The HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'. |
8 | 7 | * @returns {Element} The matched button element. |
| 8 | + * @throws {Error} If buttonName is not provided. |
9 | 9 | * |
10 | 10 | * Example: |
11 | | - * cy.getFormFooterButtonByType('Save Changes'); |
12 | | - * cy.getFormFooterButtonByType('Reset', 'reset'); |
| 11 | + * cy.getFormFooterButtonByTypeWithText({ buttonText: 'Save Changes' }); |
| 12 | + * cy.getFormFooterButtonByTypeWithText({ buttonText: 'Submit', buttonType: 'submit' }); |
13 | 13 | */ |
14 | | -Cypress.Commands.add('getFormFooterButtonByType', (name, type = 'button') => |
15 | | - cy.contains(`#main-content .bx--btn-set button[type="${type}"]`, name) |
| 14 | +Cypress.Commands.add( |
| 15 | + 'getFormFooterButtonByTypeWithText', |
| 16 | + ({ buttonType = 'button', buttonText } = {}) => { |
| 17 | + if (!buttonText) { |
| 18 | + cy.logAndThrowError('buttonName is required'); |
| 19 | + } |
| 20 | + return cy.contains( |
| 21 | + `#main-content .bx--btn-set button[type="${buttonType}"]`, |
| 22 | + buttonText |
| 23 | + ); |
| 24 | + } |
16 | 25 | ); |
17 | 26 |
|
18 | 27 | /** |
19 | | - * Retrieves a form input field by its ID and type. |
| 28 | + * Retrieves a form input field by its ID and type using an object parameter. |
20 | 29 | * |
21 | | - * @param {string} inputId - The ID of the input field. |
22 | | - * @param {string} [type='text'] - The HTML input type (e.g., 'text', 'email', 'password'). Defaults to 'text'. |
| 30 | + * @param {Object} options - The options object. |
| 31 | + * @param {string} options.inputId - The ID of the input field (required). |
| 32 | + * @param {string} [options.inputType='text'] - The HTML input inputType (e.g., 'text', 'email', 'password'). Defaults to 'text'. |
23 | 33 | * @returns {Element} The matched input field element. |
| 34 | + * @throws {Error} If inputId is not provided. |
24 | 35 | * |
25 | 36 | * Example: |
26 | | - * cy.getFormInputFieldById('name'); |
27 | | - * cy.getFormInputFieldById('name', 'text'); |
| 37 | + * cy.getFormInputFieldByIdAndType({ inputId: 'name' }); |
| 38 | + * cy.getFormInputFieldByIdAndType({ inputId: 'password', inputType: 'password' }); |
28 | 39 | */ |
29 | | -Cypress.Commands.add('getFormInputFieldById', (inputId, type = 'text') => |
30 | | - cy.get(`#main-content .bx--form input#${inputId}[type="${type}"]`) |
| 40 | +Cypress.Commands.add( |
| 41 | + 'getFormInputFieldByIdAndType', |
| 42 | + ({ inputId, inputType = 'text' }) => { |
| 43 | + if (!inputId) { |
| 44 | + cy.logAndThrowError('inputId is required'); |
| 45 | + } |
| 46 | + return cy.get( |
| 47 | + `#main-content .bx--form input[id="${inputId}"][type="${inputType}"]` |
| 48 | + ); |
| 49 | + } |
31 | 50 | ); |
32 | 51 |
|
33 | 52 | /** |
34 | | - * Retrieves a form label associated with a specific input field by its ID. |
| 53 | + * Retrieves a form label associated with a specific input field by its 'for' attribute. |
35 | 54 | * |
36 | | - * @param {string} inputId - The ID of the input field. |
| 55 | + * @param {Object} options - The options object. |
| 56 | + * @param {string} options.forValue - The value of the 'for' attribute that matches the input field's ID (required). |
37 | 57 | * @returns {Element} The matched label element. |
| 58 | + * @throws {Error} If forValue is not provided. |
38 | 59 | * |
39 | 60 | * Example: |
40 | | - * cy.getFormLabelByInputId('name'); |
| 61 | + * cy.getFormLabelByForAttribute({ forValue: 'name' }); |
41 | 62 | */ |
42 | | -Cypress.Commands.add('getFormLabelByInputId', (inputId) => |
43 | | - cy.get(`#main-content .bx--form label[for="${inputId}"]`) |
44 | | -); |
| 63 | +Cypress.Commands.add('getFormLabelByForAttribute', ({ forValue }) => { |
| 64 | + if (!forValue) { |
| 65 | + cy.logAndThrowError('forValue is required'); |
| 66 | + } |
| 67 | + return cy.get(`#main-content .bx--form label[for="${forValue}"]`); |
| 68 | +}); |
45 | 69 |
|
46 | 70 | /** |
47 | | - * Retrieves a form select field by its ID. |
| 71 | + * Retrieves a form select field by its ID using an object parameter. |
48 | 72 | * |
49 | | - * @param {string} selectId - The ID of the select field. |
| 73 | + * @param {Object} options - The options object. |
| 74 | + * @param {string} options.selectId - The ID of the select field (required). |
50 | 75 | * @returns {Element} The matched select field element. |
| 76 | + * @throws {Error} If selectId is not provided. |
51 | 77 | * |
52 | 78 | * Example: |
53 | | - * cy.getFormSelectFieldById('select-scan-limit'); |
| 79 | + * cy.getFormSelectFieldById({ selectId: 'select-scan-limit' }); |
54 | 80 | */ |
55 | | -Cypress.Commands.add('getFormSelectFieldById', (selectId) => |
56 | | - cy.get(`#main-content .bx--form select#${selectId}`) |
57 | | -); |
| 81 | +Cypress.Commands.add('getFormSelectFieldById', ({ selectId }) => { |
| 82 | + if (!selectId) { |
| 83 | + cy.logAndThrowError('selectId is required'); |
| 84 | + } |
| 85 | + return cy.get(`#main-content .bx--form select[id="${selectId}"]`); |
| 86 | +}); |
| 87 | + |
| 88 | +/** |
| 89 | + * Retrieves a form textarea field by its ID using an object parameter. |
| 90 | + * |
| 91 | + * @param {Object} options - The options object. |
| 92 | + * @param {string} options.textareaId - The ID of the textarea field (required). |
| 93 | + * @returns {Element} The matched textarea field element. |
| 94 | + * @throws {Error} If textareaId is not provided. |
| 95 | + * |
| 96 | + * Example: |
| 97 | + * cy.getFormTextareaById({ textareaId: 'default.auth_key' }); |
| 98 | + */ |
| 99 | +Cypress.Commands.add('getFormTextareaById', ({ textareaId }) => { |
| 100 | + if (!textareaId) { |
| 101 | + cy.logAndThrowError('textareaId is required'); |
| 102 | + } |
| 103 | + return cy.get(`#main-content .bx--form textarea[id="${textareaId}"]`); |
| 104 | +}); |
0 commit comments