@redhat-developer/page-objects 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ type Constructor<T = object> = new (...args: any[]) => T;
24
24
  * The interface that a class is required to have in order to use the Webview mixin.
25
25
  */
26
26
  interface WebviewMixable extends AbstractElement {
27
- getViewToSwitchTo(handle: string): Promise<WebElement | undefined>;
27
+ getViewToSwitchTo(): Promise<WebElement | undefined>;
28
28
  }
29
29
  /**
30
30
  * The interface that is exposed by applying this mixin.
@@ -63,7 +63,7 @@ function default_1(Base) {
63
63
  if (!this.handle) {
64
64
  this.handle = await this.getDriver().getWindowHandle();
65
65
  }
66
- const view = await this.getViewToSwitchTo(this.handle);
66
+ const view = await this.getViewToSwitchTo();
67
67
  if (!view) {
68
68
  return;
69
69
  }
@@ -14,14 +14,14 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { WebElement } from 'selenium-webdriver';
17
+ import { Locator, WebElement } from 'selenium-webdriver';
18
18
  import { AbstractElement } from '../AbstractElement';
19
19
  /**
20
20
  * Page object representing a user-contributed panel implemented using a Webview.
21
21
  */
22
22
  declare class WebviewViewBase extends AbstractElement {
23
- constructor();
24
- getViewToSwitchTo(handle: string): Promise<WebElement | undefined>;
23
+ constructor(base?: Locator | WebElement, enclosingItem?: WebElement | Locator);
24
+ getViewToSwitchTo(): Promise<WebElement | undefined>;
25
25
  }
26
26
  export declare const WebviewView: new (...args: any[]) => WebviewViewBase & import("../WebviewMixin").WebviewMixinType;
27
27
  export type WebviewView = InstanceType<typeof WebviewView>;
@@ -22,16 +22,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.WebviewView = void 0;
23
23
  const AbstractElement_1 = require("../AbstractElement");
24
24
  const WebviewMixin_1 = __importDefault(require("../WebviewMixin"));
25
+ const locators_1 = require("../../locators/locators");
25
26
  /**
26
27
  * Page object representing a user-contributed panel implemented using a Webview.
27
28
  */
28
29
  class WebviewViewBase extends AbstractElement_1.AbstractElement {
29
- constructor() {
30
- super(WebviewViewBase.locators.Workbench.constructor);
30
+ constructor(base = WebviewViewBase.locators.Workbench.constructor, enclosingItem) {
31
+ super(base, enclosingItem);
31
32
  }
32
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
- async getViewToSwitchTo(handle) {
34
- return await this.getDriver().findElement(WebviewViewBase.locators.WebviewView.iframe);
33
+ async getViewToSwitchTo() {
34
+ const frames = await this.getDriver().findElements(WebviewViewBase.locators.WebView.iframe);
35
+ return (0, locators_1.findBestContainingElement)(await this.getRect(), frames);
35
36
  }
36
37
  }
37
38
  exports.WebviewView = (0, WebviewMixin_1.default)(WebviewViewBase);
@@ -20,7 +20,7 @@ import { Editor } from './Editor';
20
20
  * Page object representing an open editor containing a web view
21
21
  */
22
22
  declare class WebViewBase extends Editor {
23
- getViewToSwitchTo(handle: string): Promise<WebElement | undefined>;
23
+ getViewToSwitchTo(): Promise<WebElement | undefined>;
24
24
  }
25
25
  export declare const WebView: new (...args: any[]) => WebViewBase & import("../WebviewMixin").WebviewMixinType;
26
26
  export type WebView = InstanceType<typeof WebView>;
@@ -22,21 +22,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.WebView = void 0;
23
23
  const WebviewMixin_1 = __importDefault(require("../WebviewMixin"));
24
24
  const Editor_1 = require("./Editor");
25
+ const locators_1 = require("../../locators/locators");
25
26
  /**
26
27
  * Page object representing an open editor containing a web view
27
28
  */
28
29
  class WebViewBase extends Editor_1.Editor {
29
- async getViewToSwitchTo(handle) {
30
- const handles = await this.getDriver().getAllWindowHandles();
31
- for (const handle of handles) {
32
- await this.getDriver().switchTo().window(handle);
33
- if ((await this.getDriver().getTitle()).includes('Virtual Document')) {
34
- await this.getDriver().switchTo().frame(0);
35
- return;
36
- }
37
- }
38
- await this.getDriver().switchTo().window(handle);
39
- return await this.getDriver().findElement(WebViewBase.locators.WebView.iframe);
30
+ async getViewToSwitchTo() {
31
+ const frames = await this.getDriver().findElements(WebViewBase.locators.WebView.iframe);
32
+ return (0, locators_1.findBestContainingElement)(await this.getRect(), frames);
40
33
  }
41
34
  }
42
35
  exports.WebView = (0, WebviewMixin_1.default)(WebViewBase);
@@ -100,9 +100,10 @@ class ViewSection extends AbstractElement_1.AbstractElement {
100
100
  * @returns Promise resolving to array of ViewPanelAction objects
101
101
  */
102
102
  async getActions() {
103
+ await this.getDriver().actions().move({ origin: this }).perform(); // move mouse to bring auto-hided buttons visible
103
104
  const actions = await this.findElement(ViewSection.locators.ViewSection.actions).findElements(ViewSection.locators.ViewSection.button);
104
105
  return Promise.all(actions.map(async (action) => {
105
- const dropdown = await action.getAttribute('aria-haspopup');
106
+ const dropdown = (await action.getAttribute('aria-haspopup')) || (await action.getAttribute('aria-expanded'));
106
107
  if (dropdown) {
107
108
  return new ViewPanelActionDropdown(action, this);
108
109
  }
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { By, WebElement } from 'selenium-webdriver';
17
+ import { By, IRectangle, WebElement } from 'selenium-webdriver';
18
18
  import { PartialDeep } from 'type-fest';
19
19
  import { ViewSection } from '../components/sidebar/ViewSection';
20
20
  type WebElementFunction<E extends WebElement, T> = (element: E) => T | PromiseLike<T>;
@@ -214,8 +214,6 @@ export interface Locators {
214
214
  WebView: {
215
215
  iframe: By;
216
216
  activeFrame: By;
217
- container: (id: string) => By;
218
- attribute: string;
219
217
  };
220
218
  ExtensionEditorView: {
221
219
  constructor: By;
@@ -554,4 +552,5 @@ export declare function hasNotClass(klass: string, locator?: By): (el: WebElemen
554
552
  export declare function hasElement(locatorSelector: (l: Locators) => By): (el: WebElement, locators: Locators) => Promise<boolean>;
555
553
  export declare function fromAttribute(attribute: string, locator?: By): (el: WebElement) => Promise<string>;
556
554
  export declare function fromText(locator?: By): (el: WebElement) => Promise<string>;
555
+ export declare function findBestContainingElement(container: IRectangle, testElements: WebElement[]): Promise<WebElement | undefined>;
557
556
  export {};
@@ -22,6 +22,7 @@ exports.hasNotClass = hasNotClass;
22
22
  exports.hasElement = hasElement;
23
23
  exports.fromAttribute = fromAttribute;
24
24
  exports.fromText = fromText;
25
+ exports.findBestContainingElement = findBestContainingElement;
25
26
  function hasAttribute(attr, value, locator) {
26
27
  return async (el) => {
27
28
  el = locator ? await el.findElement(locator) : el;
@@ -64,4 +65,24 @@ function fromText(locator) {
64
65
  return await el.getText();
65
66
  };
66
67
  }
68
+ async function findBestContainingElement(container, testElements) {
69
+ const areas = await Promise.all(testElements.map(async (value) => {
70
+ const rect = await value.getRect();
71
+ const ax = Math.max(container.x, rect.x);
72
+ const ay = Math.max(container.y, rect.y);
73
+ const bx = Math.min(container.x + container.width, rect.x + rect.width);
74
+ const by = Math.min(container.y + container.height, rect.y + rect.height);
75
+ return (bx - ax) * (by - ay);
76
+ }));
77
+ let bestIdx = -1;
78
+ for (let i = 0; i < testElements.length; i++) {
79
+ if (areas[i] < 0) {
80
+ continue;
81
+ }
82
+ if (bestIdx === -1 || areas[i] > areas[bestIdx]) {
83
+ bestIdx = i;
84
+ }
85
+ }
86
+ return bestIdx === -1 ? undefined : testElements[bestIdx];
87
+ }
67
88
  //# sourceMappingURL=locators.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-developer/page-objects",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "Page Object API implementation for a VS Code editor used by ExTester framework.",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -41,11 +41,11 @@
41
41
  "clone-deep": "^4.0.1",
42
42
  "compare-versions": "^6.1.1",
43
43
  "fs-extra": "^11.3.0",
44
- "type-fest": "^4.35.0"
44
+ "type-fest": "^4.39.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "selenium-webdriver": ">=4.6.1",
48
48
  "typescript": ">=4.6.2"
49
49
  },
50
- "gitHead": "bf17db769fb699fe9a47325ff6e0c94dc821ae0f"
50
+ "gitHead": "006642fd809f6b11cc662ed0f190295efff61602"
51
51
  }