index.d.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import * as webdriver from 'selenium-webdriver';
  2. import { T as TestElement, M as ModifierKeys, a as TestKey, b as TextOptions, E as ElementDimensions, c as EventData, H as HarnessEnvironment, d as HarnessLoader } from '../../harness-environment.d-BbFzIFDE.js';
  3. /** A `TestElement` implementation for WebDriver. */
  4. declare class SeleniumWebDriverElement implements TestElement {
  5. readonly element: () => webdriver.WebElement;
  6. private _stabilize;
  7. constructor(element: () => webdriver.WebElement, _stabilize: () => Promise<void>);
  8. /** Blur the element. */
  9. blur(): Promise<void>;
  10. /** Clear the element's input (for input and textarea elements only). */
  11. clear(): Promise<void>;
  12. /**
  13. * Click the element at the default location for the current environment. If you need to guarantee
  14. * the element is clicked at a specific location, consider using `click('center')` or
  15. * `click(x, y)` instead.
  16. */
  17. click(modifiers?: ModifierKeys): Promise<void>;
  18. /** Click the element at the element's center. */
  19. click(location: 'center', modifiers?: ModifierKeys): Promise<void>;
  20. /**
  21. * Click the element at the specified coordinates relative to the top-left of the element.
  22. * @param relativeX Coordinate within the element, along the X-axis at which to click.
  23. * @param relativeY Coordinate within the element, along the Y-axis at which to click.
  24. * @param modifiers Modifier keys held while clicking
  25. */
  26. click(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
  27. /**
  28. * Right clicks on the element at the specified coordinates relative to the top-left of it.
  29. * @param relativeX Coordinate within the element, along the X-axis at which to click.
  30. * @param relativeY Coordinate within the element, along the Y-axis at which to click.
  31. * @param modifiers Modifier keys held while clicking
  32. */
  33. rightClick(relativeX: number, relativeY: number, modifiers?: ModifierKeys): Promise<void>;
  34. /** Focus the element. */
  35. focus(): Promise<void>;
  36. /** Get the computed value of the given CSS property for the element. */
  37. getCssValue(property: string): Promise<string>;
  38. /** Hovers the mouse over the element. */
  39. hover(): Promise<void>;
  40. /** Moves the mouse away from the element. */
  41. mouseAway(): Promise<void>;
  42. /**
  43. * Sends the given string to the input as a series of key presses. Also fires input events
  44. * and attempts to add the string to the Element's value.
  45. */
  46. sendKeys(...keys: (string | TestKey)[]): Promise<void>;
  47. /**
  48. * Sends the given string to the input as a series of key presses. Also fires input events
  49. * and attempts to add the string to the Element's value.
  50. */
  51. sendKeys(modifiers: ModifierKeys, ...keys: (string | TestKey)[]): Promise<void>;
  52. /**
  53. * Gets the text from the element.
  54. * @param options Options that affect what text is included.
  55. */
  56. text(options?: TextOptions): Promise<string>;
  57. /**
  58. * Sets the value of a `contenteditable` element.
  59. * @param value Value to be set on the element.
  60. */
  61. setContenteditableValue(value: string): Promise<void>;
  62. /** Gets the value for the given attribute from the element. */
  63. getAttribute(name: string): Promise<string | null>;
  64. /** Checks whether the element has the given class. */
  65. hasClass(name: string): Promise<boolean>;
  66. /** Gets the dimensions of the element. */
  67. getDimensions(): Promise<ElementDimensions>;
  68. /** Gets the value of a property of an element. */
  69. getProperty<T = any>(name: string): Promise<T>;
  70. /** Sets the value of a property of an input. */
  71. setInputValue(newValue: string): Promise<void>;
  72. /** Selects the options at the specified indexes inside of a native `select` element. */
  73. selectOptions(...optionIndexes: number[]): Promise<void>;
  74. /** Checks whether this element matches the given selector. */
  75. matchesSelector(selector: string): Promise<boolean>;
  76. /** Checks whether the element is focused. */
  77. isFocused(): Promise<boolean>;
  78. /**
  79. * Dispatches an event with a particular name.
  80. * @param name Name of the event to be dispatched.
  81. */
  82. dispatchEvent(name: string, data?: Record<string, EventData>): Promise<void>;
  83. /** Gets the webdriver action sequence. */
  84. private _actions;
  85. /** Executes a function in the browser. */
  86. private _executeScript;
  87. /** Dispatches all the events that are part of a click event sequence. */
  88. private _dispatchClickEventSequence;
  89. }
  90. /**
  91. * An Angular framework stabilizer function that takes a callback and calls it when the application
  92. * is stable, passing a boolean indicating if any work was done.
  93. */
  94. declare interface FrameworkStabilizer {
  95. (callback: (didWork: boolean) => void): void;
  96. }
  97. declare global {
  98. interface Window {
  99. /**
  100. * These hooks are exposed by Angular to register a callback for when the application is stable
  101. * (no more pending tasks).
  102. *
  103. * For the implementation, see: https://github.com/
  104. * angular/angular/blob/main/packages/platform-browser/src/browser/testability.ts#L30-L49
  105. */
  106. frameworkStabilizers: FrameworkStabilizer[];
  107. }
  108. }
  109. /** Options to configure the environment. */
  110. interface WebDriverHarnessEnvironmentOptions {
  111. /** The query function used to find DOM elements. */
  112. queryFn: (selector: string, root: () => webdriver.WebElement) => Promise<webdriver.WebElement[]>;
  113. }
  114. /** Waits for angular to be ready after the page load. */
  115. declare function waitForAngularReady(wd: webdriver.WebDriver): Promise<void>;
  116. /** A `HarnessEnvironment` implementation for WebDriver. */
  117. declare class SeleniumWebDriverHarnessEnvironment extends HarnessEnvironment<() => webdriver.WebElement> {
  118. /** The options for this environment. */
  119. private _options;
  120. /** Environment stabilization callback passed to the created test elements. */
  121. private _stabilizeCallback;
  122. protected constructor(rawRootElement: () => webdriver.WebElement, options?: WebDriverHarnessEnvironmentOptions);
  123. /** Gets the ElementFinder corresponding to the given TestElement. */
  124. static getNativeElement(el: TestElement): webdriver.WebElement;
  125. /** Creates a `HarnessLoader` rooted at the document root. */
  126. static loader(driver: webdriver.WebDriver, options?: WebDriverHarnessEnvironmentOptions): HarnessLoader;
  127. /**
  128. * Flushes change detection and async tasks captured in the Angular zone.
  129. * In most cases it should not be necessary to call this manually. However, there may be some edge
  130. * cases where it is needed to fully flush animation events.
  131. */
  132. forceStabilize(): Promise<void>;
  133. /** @docs-private */
  134. waitForTasksOutsideAngular(): Promise<void>;
  135. /** Gets the root element for the document. */
  136. protected getDocumentRoot(): () => webdriver.WebElement;
  137. /** Creates a `TestElement` from a raw element. */
  138. protected createTestElement(element: () => webdriver.WebElement): TestElement;
  139. /** Creates a `HarnessLoader` rooted at the given raw element. */
  140. protected createEnvironment(element: () => webdriver.WebElement): HarnessEnvironment<() => webdriver.WebElement>;
  141. /**
  142. * Gets a list of all elements matching the given selector under this environment's root element.
  143. */
  144. protected getAllRawElements(selector: string): Promise<(() => webdriver.WebElement)[]>;
  145. }
  146. export { SeleniumWebDriverElement, SeleniumWebDriverHarnessEnvironment, waitForAngularReady };
  147. export type { WebDriverHarnessEnvironmentOptions };