UNPKG

@badisi/wdio-harness

Version:

WebdriverIO support for Angular component test harnesses.

62 lines (61 loc) 2.49 kB
import { HarnessEnvironment } from '@angular/cdk/testing'; import logger from '@wdio/logger'; import { WebdriverIOTestElement } from './WebdriverIOTestElement.js'; import { green, magenta } from './utils'; /** Registers the environment logger. */ const log = logger('wdio-harness'); /** * A `HarnessEnvironment` implementation for WebdriverIO. */ export class WebdriverIOHarnessEnvironment extends HarnessEnvironment { /** * Keep a reference to the `document` element because `rawRootElement` * will be the root element of the harness's environment. */ documentRoot; constructor(rawRootElement, options) { super(rawRootElement); this.documentRoot = options.documentRoot; } /** Creates a `HarnessLoader` rooted at the document root. */ static async loader(documentRoot) { return new WebdriverIOHarnessEnvironment(documentRoot, { documentRoot }); } /** * Flushes change detection and async tasks captured in the Angular zone. * In most cases it should not be necessary to call this manually. However, there may be some edge * cases where it is needed to fully flush animation events. */ async forceStabilize() { /* await browser.executeAsyncScript(` const done = arguments[0]; window.requestAnimationFrame(done); `, []);*/ } async waitForTasksOutsideAngular() { throw new Error('Method not implemented.'); } /** Creates a `ComponentHarness` for the given harness type with the given raw host element. */ createComponentHarness(harnessType, element) { return super.createComponentHarness(harnessType, element); } /** Gets a list of all elements matching the given selector under this environment's root element. */ async getAllRawElements(selector) { log.info(`${magenta('GET_ALL_RAW_ELEMENTS')} ${green(selector.toString())}`); return [...(await this.rawRootElement.$$(selector).getElements())]; } /** Gets the root element for the document. */ getDocumentRoot() { return this.documentRoot; } /** Creates a `TestElement` from a raw element. */ createTestElement(element) { return new WebdriverIOTestElement(element); } /** Creates a `HarnessLoader` rooted at the given raw element. */ createEnvironment(element) { return new WebdriverIOHarnessEnvironment(element, { documentRoot: this.documentRoot }); } }