MOBILE-4270 behat: Support setting fields by label
This commit is contained in:
		
							parent
							
								
									874f47ebad
								
							
						
					
					
						commit
						a8e7e61e1e
					
				| @ -384,6 +384,34 @@ export class TestingBehatDomUtilsService { | ||||
|         return topContainers; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find a field. | ||||
|      * | ||||
|      * @param field Field name. | ||||
|      * @returns Field element. | ||||
|      */ | ||||
|     findField(field: string): HTMLElement | HTMLInputElement | undefined { | ||||
|         const input = this.findElementBasedOnText( | ||||
|             { text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime' }, | ||||
|             { onlyClickable: false, containerName: '' }, | ||||
|         ); | ||||
| 
 | ||||
|         if (input) { | ||||
|             return input; | ||||
|         } | ||||
| 
 | ||||
|         const label = this.findElementBasedOnText( | ||||
|             { text: field, selector: 'label' }, | ||||
|             { onlyClickable: false, containerName: '' }, | ||||
|         ); | ||||
| 
 | ||||
|         if (label) { | ||||
|             const inputId = label.getAttribute('for'); | ||||
| 
 | ||||
|             return (inputId && document.getElementById(inputId)) || undefined; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Function to find element based on their text or Aria label. | ||||
|      * | ||||
|  | ||||
| @ -422,7 +422,7 @@ export class TestingBehatRuntimeService { | ||||
|     async setField(field: string, value: string): Promise<string> { | ||||
|         this.log('Action - Set field ' + field + ' to: ' + value); | ||||
| 
 | ||||
|         const found = this.findField(field); | ||||
|         const found = TestingBehatDomUtils.findField(field); | ||||
| 
 | ||||
|         if (!found) { | ||||
|             return 'ERROR: No element matches field to set.'; | ||||
| @ -445,7 +445,7 @@ export class TestingBehatRuntimeService { | ||||
|     async fieldMatches(field: string, value: string): Promise<string> { | ||||
|         this.log('Action - Field ' + field + ' matches value: ' + value); | ||||
| 
 | ||||
|         const found = this.findField(field); | ||||
|         const found = TestingBehatDomUtils.findField(field); | ||||
| 
 | ||||
|         if (!found) { | ||||
|             return 'ERROR: No element matches field to set.'; | ||||
| @ -459,19 +459,6 @@ export class TestingBehatRuntimeService { | ||||
|         return 'OK'; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Find a field. | ||||
|      * | ||||
|      * @param field Field name. | ||||
|      * @returns Field element. | ||||
|      */ | ||||
|     protected findField(field: string): HTMLElement | HTMLInputElement | undefined { | ||||
|         return TestingBehatDomUtils.findElementBasedOnText( | ||||
|             { text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime' }, | ||||
|             { onlyClickable: false, containerName: '' }, | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the value of a certain field. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user