MOBILE-4110 behat: Fix namespace
This commit is contained in:
		
							parent
							
								
									93cfcd4ae0
								
							
						
					
					
						commit
						e974912880
					
				| @ -14,12 +14,12 @@ | ||||
| 
 | ||||
| import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||||
| import { CoreAppProvider } from '@services/app'; | ||||
| import { TestsBehatBlockingService } from './services/behat-blocking'; | ||||
| import { BehatTestsWindow, TestsBehatRuntime } from './services/behat-runtime'; | ||||
| import { TestingBehatBlockingService } from './services/behat-blocking'; | ||||
| import { BehatTestsWindow, TestingBehatRuntime } from './services/behat-runtime'; | ||||
| 
 | ||||
| function initializeBehatTestsWindow(window: BehatTestsWindow) { | ||||
|     // Make functions publicly available for Behat to call.
 | ||||
|     window.behatInit = TestsBehatRuntime.init; | ||||
|     window.behatInit = TestingBehatRuntime.init; | ||||
| } | ||||
| 
 | ||||
| @NgModule({ | ||||
| @ -27,7 +27,7 @@ function initializeBehatTestsWindow(window: BehatTestsWindow) { | ||||
|         CoreAppProvider.isAutomated() | ||||
|             ? [ | ||||
|                 { provide: APP_INITIALIZER, multi: true, useValue: () => initializeBehatTestsWindow(window) }, | ||||
|                 TestsBehatBlockingService, | ||||
|                 TestingBehatBlockingService, | ||||
|             ] | ||||
|             : [], | ||||
| }) | ||||
|  | ||||
| @ -15,13 +15,13 @@ | ||||
| import { Injectable } from '@angular/core'; | ||||
| import { CoreUtils } from '@services/utils/utils'; | ||||
| import { makeSingleton, NgZone } from '@singletons'; | ||||
| import { BehatTestsWindow, TestsBehatRuntime } from './behat-runtime'; | ||||
| import { BehatTestsWindow, TestingBehatRuntime } from './behat-runtime'; | ||||
| 
 | ||||
| /** | ||||
|  * Behat block JS manager. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class TestsBehatBlockingService { | ||||
| export class TestingBehatBlockingService { | ||||
| 
 | ||||
|     protected waitingBlocked = false; | ||||
|     protected recentMutation = false; | ||||
| @ -48,7 +48,7 @@ export class TestsBehatBlockingService { | ||||
|         win.M.util = win.M.util ?? {}; | ||||
|         win.M.util.pending_js = win.M.util.pending_js ?? []; | ||||
| 
 | ||||
|         TestsBehatRuntime.log('Initialized!'); | ||||
|         TestingBehatRuntime.log('Initialized!'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -90,7 +90,7 @@ export class TestsBehatBlockingService { | ||||
|         } | ||||
|         this.pendingList.push(key); | ||||
| 
 | ||||
|         TestsBehatRuntime.log('PENDING+: ' + this.pendingList); | ||||
|         TestingBehatRuntime.log('PENDING+: ' + this.pendingList); | ||||
| 
 | ||||
|         return key; | ||||
|     } | ||||
| @ -105,7 +105,7 @@ export class TestsBehatBlockingService { | ||||
|         // Remove the key immediately.
 | ||||
|         this.pendingList = this.pendingList.filter((x) => x !== key); | ||||
| 
 | ||||
|         TestsBehatRuntime.log('PENDING-: ' + this.pendingList); | ||||
|         TestingBehatRuntime.log('PENDING-: ' + this.pendingList); | ||||
| 
 | ||||
|         // If the only thing left is DELAY, then remove that as well, later...
 | ||||
|         if (this.pendingList.length === 1) { | ||||
| @ -124,7 +124,7 @@ export class TestsBehatBlockingService { | ||||
|             // Only remove it if the pending array is STILL empty after all that.
 | ||||
|             if (this.pendingList.length === 1) { | ||||
|                 this.pendingList = []; | ||||
|                 TestsBehatRuntime.log('PENDING-: ' + this.pendingList); | ||||
|                 TestingBehatRuntime.log('PENDING-: ' + this.pendingList); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @ -221,16 +221,16 @@ export class TestsBehatBlockingService { | ||||
| 
 | ||||
|                 try { | ||||
|                 // Add to the list of pending requests.
 | ||||
|                     TestsBehatBlocking.block(key); | ||||
|                     TestingBehatBlocking.block(key); | ||||
| 
 | ||||
|                     // Detect when it finishes and remove it from the list.
 | ||||
|                     this.addEventListener('loadend', () => { | ||||
|                         TestsBehatBlocking.unblock(key); | ||||
|                         TestingBehatBlocking.unblock(key); | ||||
|                     }); | ||||
| 
 | ||||
|                     return realOpen.apply(this, args); | ||||
|                 } catch (error) { | ||||
|                     TestsBehatBlocking.unblock(key); | ||||
|                     TestingBehatBlocking.unblock(key); | ||||
|                     throw error; | ||||
|                 } | ||||
|             }); | ||||
| @ -239,4 +239,4 @@ export class TestsBehatBlockingService { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export const TestsBehatBlocking = makeSingleton(TestsBehatBlockingService); | ||||
| export const TestingBehatBlocking = makeSingleton(TestingBehatBlockingService); | ||||
|  | ||||
| @ -15,7 +15,7 @@ | ||||
| import { CorePromisedValue } from '@classes/promised-value'; | ||||
| import { CoreUtils } from '@services/utils/utils'; | ||||
| import { NgZone } from '@singletons'; | ||||
| import { TestBehatElementLocator } from './behat-runtime'; | ||||
| import { TestingBehatElementLocator, TestingBehatFindOptions } from './behat-runtime'; | ||||
| 
 | ||||
| // Containers that block containers behind them.
 | ||||
| const blockingContainers = ['ION-ALERT', 'ION-POPOVER', 'ION-ACTION-SHEET', 'CORE-USER-TOURS-USER-TOUR', 'ION-PAGE']; | ||||
| @ -23,7 +23,7 @@ const blockingContainers = ['ION-ALERT', 'ION-POPOVER', 'ION-ACTION-SHEET', 'COR | ||||
| /** | ||||
|  * Behat Dom Utils helper functions. | ||||
|  */ | ||||
| export class TestsBehatDomUtils { | ||||
| export class TestingBehatDomUtils { | ||||
| 
 | ||||
|     /** | ||||
|      * Check if an element is visible. | ||||
| @ -328,7 +328,7 @@ export class TestsBehatDomUtils { | ||||
|      * @param containerName Whether to search only inside a specific container. | ||||
|      * @return First found element. | ||||
|      */ | ||||
|     static findElementBasedOnText(locator: TestBehatElementLocator, containerName = ''): HTMLElement { | ||||
|     static findElementBasedOnText(locator: TestingBehatElementLocator, containerName = ''): HTMLElement { | ||||
|         return this.findElementsBasedOnText(locator, containerName, true)[0]; | ||||
|     } | ||||
| 
 | ||||
| @ -341,7 +341,7 @@ export class TestsBehatDomUtils { | ||||
|      * @return Found elements | ||||
|      */ | ||||
|     protected static findElementsBasedOnText( | ||||
|         locator: TestBehatElementLocator, | ||||
|         locator: TestingBehatElementLocator, | ||||
|         containerName = '', | ||||
|         stopWhenFound = false, | ||||
|     ): HTMLElement[] { | ||||
| @ -366,7 +366,7 @@ export class TestsBehatDomUtils { | ||||
|      * @return Found elements | ||||
|      */ | ||||
|     protected static findElementsBasedOnTextInContainer( | ||||
|         locator: TestBehatElementLocator, | ||||
|         locator: TestingBehatElementLocator, | ||||
|         topContainer: HTMLElement, | ||||
|     ): HTMLElement[] { | ||||
|         let container: HTMLElement | null = topContainer; | ||||
|  | ||||
| @ -12,8 +12,8 @@ | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { TestsBehatDomUtils } from './behat-dom'; | ||||
| import { TestsBehatBlocking } from './behat-blocking'; | ||||
| import { TestingBehatDomUtils } from './behat-dom'; | ||||
| import { TestingBehatBlocking } from './behat-blocking'; | ||||
| import { CoreCustomURLSchemes } from '@services/urlschemes'; | ||||
| import { CoreLoginHelperProvider } from '@features/login/services/login-helper'; | ||||
| import { CoreConfig } from '@services/config'; | ||||
| @ -34,15 +34,15 @@ import { CoreCoursesDashboardPage } from '@features/courses/pages/dashboard/dash | ||||
| /** | ||||
|  * Behat runtime servive with public API. | ||||
|  */ | ||||
| export class TestsBehatRuntime { | ||||
| export class TestingBehatRuntime { | ||||
| 
 | ||||
|     /** | ||||
|      * Init behat functions and set options like skipping onboarding. | ||||
|      * | ||||
|      * @param options Options to set on the app. | ||||
|      */ | ||||
|     static init(options?: TestsBehatInitOptions): void { | ||||
|         TestsBehatBlocking.init(); | ||||
|     static init(options?: TestingBehatInitOptions): void { | ||||
|         TestingBehatBlocking.init(); | ||||
| 
 | ||||
|         (window as BehatTestsWindow).behat = { | ||||
|             closePopup: TestsBehatRuntime.closePopup, | ||||
| @ -104,14 +104,14 @@ export class TestsBehatRuntime { | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     static async notificationClicked(data: CorePushNotificationsNotificationBasicData): Promise<void> { | ||||
|         const blockKey = TestsBehatBlocking.block(); | ||||
|         const blockKey = TestingBehatBlocking.block(); | ||||
| 
 | ||||
|         try { | ||||
|             await NgZone.run(async () => { | ||||
|                 await CorePushNotifications.notificationClicked(data); | ||||
|             }); | ||||
|         } finally { | ||||
|             TestsBehatBlocking.unblock(blockKey); | ||||
|             TestingBehatBlocking.unblock(blockKey); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -156,20 +156,20 @@ export class TestsBehatRuntime { | ||||
| 
 | ||||
|         switch (button) { | ||||
|             case 'back': | ||||
|                 foundButton = TestsBehatDomUtils.findElementBasedOnText({ text: 'Back' }); | ||||
|                 foundButton = TestingBehatDomUtils.findElementBasedOnText({ text: 'Back' }); | ||||
|                 break; | ||||
|             case 'main menu': // Deprecated name.
 | ||||
|             case 'more menu': | ||||
|                 foundButton = TestsBehatDomUtils.findElementBasedOnText({ | ||||
|                 foundButton = TestingBehatDomUtils.findElementBasedOnText({ | ||||
|                     text: 'More', | ||||
|                     selector: 'ion-tab-button', | ||||
|                 }); | ||||
|                 break; | ||||
|             case 'user menu' : | ||||
|                 foundButton = TestsBehatDomUtils.findElementBasedOnText({ text: 'User account' }); | ||||
|                 foundButton = TestingBehatDomUtils.findElementBasedOnText({ text: 'User account' }); | ||||
|                 break; | ||||
|             case 'page menu': | ||||
|                 foundButton = TestsBehatDomUtils.findElementBasedOnText({ text: 'Display options' }); | ||||
|                 foundButton = TestingBehatDomUtils.findElementBasedOnText({ text: 'Display options' }); | ||||
|                 break; | ||||
|             default: | ||||
|                 return 'ERROR: Unsupported standard button type'; | ||||
| @ -180,7 +180,7 @@ export class TestsBehatRuntime { | ||||
|         } | ||||
| 
 | ||||
|         // Click button
 | ||||
|         await TestsBehatDomUtils.pressElement(foundButton); | ||||
|         await TestingBehatDomUtils.pressElement(foundButton); | ||||
| 
 | ||||
|         return 'OK'; | ||||
|     } | ||||
| @ -206,7 +206,7 @@ export class TestsBehatRuntime { | ||||
|         backdrop.click(); | ||||
| 
 | ||||
|         // Mark busy until the click finishes processing.
 | ||||
|         TestsBehatBlocking.delay(); | ||||
|         TestingBehatBlocking.delay(); | ||||
| 
 | ||||
|         return 'OK'; | ||||
|     } | ||||
| @ -218,11 +218,11 @@ export class TestsBehatRuntime { | ||||
|      * @param containerName Whether to search only inside a specific container content. | ||||
|      * @return OK if successful, or ERROR: followed by message | ||||
|      */ | ||||
|     static find(locator: TestBehatElementLocator, containerName: string): string { | ||||
|     static find(locator: TestingBehatElementLocator, containerName: string): string { | ||||
|         this.log('Action - Find', { locator, containerName }); | ||||
| 
 | ||||
|         try { | ||||
|             const element = TestsBehatDomUtils.findElementBasedOnText(locator, containerName); | ||||
|             const element = TestingBehatDomUtils.findElementBasedOnText(locator, containerName); | ||||
| 
 | ||||
|             if (!element) { | ||||
|                 return 'ERROR: No element matches locator to find.'; | ||||
| @ -242,11 +242,11 @@ export class TestsBehatRuntime { | ||||
|      * @param locator Element locator. | ||||
|      * @return OK if successful, or ERROR: followed by message | ||||
|      */ | ||||
|     static scrollTo(locator: TestBehatElementLocator): string { | ||||
|     static scrollTo(locator: TestingBehatElementLocator): string { | ||||
|         this.log('Action - scrollTo', { locator }); | ||||
| 
 | ||||
|         try { | ||||
|             let element = TestsBehatDomUtils.findElementBasedOnText(locator); | ||||
|             let element = TestingBehatDomUtils.findElementBasedOnText(locator); | ||||
| 
 | ||||
|             if (!element) { | ||||
|                 return 'ERROR: No element matches element to scroll to.'; | ||||
| @ -316,13 +316,13 @@ export class TestsBehatRuntime { | ||||
|      * @param locator Element locator. | ||||
|      * @return YES or NO if successful, or ERROR: followed by message | ||||
|      */ | ||||
|     static isSelected(locator: TestBehatElementLocator): string { | ||||
|     static isSelected(locator: TestingBehatElementLocator): string { | ||||
|         this.log('Action - Is Selected', locator); | ||||
| 
 | ||||
|         try { | ||||
|             const element = TestsBehatDomUtils.findElementBasedOnText(locator); | ||||
|             const element = TestingBehatDomUtils.findElementBasedOnText(locator); | ||||
| 
 | ||||
|             return TestsBehatDomUtils.isElementSelected(element, document.body) ? 'YES' : 'NO'; | ||||
|             return TestingBehatDomUtils.isElementSelected(element, document.body) ? 'YES' : 'NO'; | ||||
|         } catch (error) { | ||||
|             return 'ERROR: ' + error.message; | ||||
|         } | ||||
| @ -334,17 +334,17 @@ export class TestsBehatRuntime { | ||||
|      * @param locator Element locator. | ||||
|      * @return OK if successful, or ERROR: followed by message | ||||
|      */ | ||||
|     static async press(locator: TestBehatElementLocator): Promise<string> { | ||||
|     static async press(locator: TestingBehatElementLocator): Promise<string> { | ||||
|         this.log('Action - Press', locator); | ||||
| 
 | ||||
|         try { | ||||
|             const found = TestsBehatDomUtils.findElementBasedOnText(locator); | ||||
|             const found = TestingBehatDomUtils.findElementBasedOnText(locator); | ||||
| 
 | ||||
|             if (!found) { | ||||
|                 return 'ERROR: No element matches locator to press.'; | ||||
|             } | ||||
| 
 | ||||
|             await TestsBehatDomUtils.pressElement(found); | ||||
|             await TestingBehatDomUtils.pressElement(found); | ||||
| 
 | ||||
|             return 'OK'; | ||||
|         } catch (error) { | ||||
| @ -394,7 +394,7 @@ export class TestsBehatRuntime { | ||||
|         this.log('Action - Get header'); | ||||
| 
 | ||||
|         let titles = Array.from(document.querySelectorAll<HTMLElement>('.ion-page:not(.ion-page-hidden) > ion-header h1')); | ||||
|         titles = titles.filter((title) => TestsBehatDomUtils.isElementVisible(title, document.body)); | ||||
|         titles = titles.filter((title) => TestingBehatDomUtils.isElementVisible(title, document.body)); | ||||
| 
 | ||||
|         if (titles.length > 1) { | ||||
|             return 'ERROR: Too many possible titles ('+titles.length+').'; | ||||
| @ -419,7 +419,7 @@ export class TestsBehatRuntime { | ||||
|     static async setField(field: string, value: string): Promise<string> { | ||||
|         this.log('Action - Set field ' + field + ' to: ' + value); | ||||
| 
 | ||||
|         const found: HTMLElement | HTMLInputElement = TestsBehatDomUtils.findElementBasedOnText( | ||||
|         const found: HTMLElement | HTMLInputElement = TestingBehatDomUtils.findElementBasedOnText( | ||||
|             { text: field, selector: 'input, textarea, [contenteditable="true"], ion-select' }, | ||||
|         ); | ||||
| 
 | ||||
| @ -427,7 +427,7 @@ export class TestsBehatRuntime { | ||||
|             return 'ERROR: No element matches field to set.'; | ||||
|         } | ||||
| 
 | ||||
|         await TestsBehatDomUtils.setElementValue(found, value); | ||||
|         await TestingBehatDomUtils.setElementValue(found, value); | ||||
| 
 | ||||
|         return 'OK'; | ||||
|     } | ||||
| @ -478,14 +478,14 @@ export type BehatTestsWindow = Window & { | ||||
|     behat?: unknown; | ||||
| }; | ||||
| 
 | ||||
| export type TestBehatElementLocator = { | ||||
| export type TestingBehatElementLocator = { | ||||
|     text: string; | ||||
|     within?: TestBehatElementLocator; | ||||
|     near?: TestBehatElementLocator; | ||||
|     within?: TestingBehatElementLocator; | ||||
|     near?: TestingBehatElementLocator; | ||||
|     selector?: string; | ||||
| }; | ||||
| 
 | ||||
| export type TestsBehatInitOptions = { | ||||
| export type TestingBehatInitOptions = { | ||||
|     skipOnBoarding?: boolean; | ||||
|     configOverrides?: Partial<EnvironmentConfig>; | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user