Skip to content

Commit

Permalink
chore: remove old proxyless implementation 4 (#7133)
Browse files Browse the repository at this point in the history
* 1

* 2

* 2

* 4

* 5

* 6

* 7

* 8

* 10

* 9

* 11

* 12

* 13

* fix lint

* fix legacy tests

* 14

* fix build again

* 14

* 15

* one more changes

* make error more clean

* fix tests 2

* fix test in ie

* fix tests again
  • Loading branch information
miherlosev committed Jul 18, 2022
1 parent 52bed25 commit 10eef98
Show file tree
Hide file tree
Showing 101 changed files with 866 additions and 1,502 deletions.
2 changes: 1 addition & 1 deletion src/api/test-controller/execution-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext } from 'vm';
import Module from 'module';
import path from 'path';
import exportableLib from '../exportable-lib';
import NODE_MODULES from '../../shared/node-modules-folder-name';
import NODE_MODULES from '../../utils/node-modules-folder-name';

const OPTIONS_KEY = Symbol('options');

Expand Down
7 changes: 0 additions & 7 deletions src/client/automation/cursor.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
import { CursorUI } from './types';
import AxisValues, { AxisValuesData } from '../utils/values/axis-values';
import { SharedWindow } from '../types';
import { CursorUI } from '../types';
import AxisValues, { AxisValuesData } from '../../core/utils/values/axis-values';
// @ts-ignore
import { Promise } from '../../client/driver/deps/hammerhead';
import { Promise } from '../../driver/deps/hammerhead';

export default class Cursor<W extends SharedWindow> {
private _activeWindow: W;
export default class Cursor {
private _activeWindow: Window;
private _x: number;
private _y: number;
private readonly _ui: CursorUI;

public constructor (activeWin: W, ui: CursorUI) {
public constructor (activeWin: Window, ui: CursorUI) {
this._ui = ui;

// NOTE: the default position should be outside of the page (GH-794)
// NOTE: the default position should be outside the page (GH-794)
this._x = -1;
this._y = -1;

this._activeWindow = activeWin;
}

private _ensureActiveWindow (win: W): void {
private _ensureActiveWindow (win: Window): void {
if (this._activeWindow === win || this._activeWindow === win.parent)
return;

if (this._activeWindow.parent !== win)
this._activeWindow = win;
}

public isActive (currWin: W): boolean {
public isActive (currWin: Window): boolean {
this._ensureActiveWindow(currWin);

return this._activeWindow === currWin;
}

public setActiveWindow (win: W): void {
public setActiveWindow (win: Window): void {
this._activeWindow = win;
}

public getActiveWindow (currWin: W): W {
public getActiveWindow (currWin: Window): Window {
this._ensureActiveWindow(currWin);

return this._activeWindow;
Expand Down
7 changes: 7 additions & 0 deletions src/client/automation/cursor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import testCafeUI from '../deps/testcafe-ui';
import isIframeWindow from '../../../utils/is-window-in-iframe';
import Cursor from './cursor';

const cursorUI = !isIframeWindow(window) ? testCafeUI.cursorUI : testCafeUI.iframeCursorUI;

export default new Cursor(window.top, cursorUI);
107 changes: 0 additions & 107 deletions src/client/automation/get-element.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { adapter } from '../adapter';
import isIframeWindow from './utils/is-window-iframe';
import { AxisValuesData } from '../utils/values/axis-values';
import { SharedWindow } from '../types';
import { AxisValuesData } from '../core/utils/values/axis-values';
// @ts-ignore
import { Promise, utils } from '../../client/driver/deps/hammerhead';
// @ts-ignore
import * as domUtils from '../../client/core/utils/dom';
import { Promise, utils } from '../driver/deps/hammerhead';
import * as domUtils from '../core/utils/dom';
import * as positionUtils from '../core/utils/position';
import getElementExceptUI from './utils/get-element-except-ui';

function ensureImageMap<E> (imgElement: E, areaElement: E): Promise<E> {
function ensureImageMap (imgElement: Element, areaElement: Element): Promise<HTMLElement> {
return Promise.resolve(domUtils.closest(areaElement, 'map'))
.then((mapElement: HTMLMapElement) => {
return mapElement && mapElement.name === domUtils.getImgMapName(imgElement) ? areaElement : imgElement;
});
}

function findElementOrNonEmptyChildFromPoint<E> (point: AxisValuesData<number>, element?: E): Promise<E | null> {
return Promise.resolve(adapter.position.getElementFromPoint(point))
function findElementOrNonEmptyChildFromPoint (point: AxisValuesData<number>, element?: HTMLElement): Promise<HTMLElement | null> {
return Promise.resolve(positionUtils.getElementFromPoint(point))
.then((topElement: HTMLElement) => {
return Promise.resolve(domUtils.containsElement(element, topElement))
.then((containsEl: HTMLElement) => containsEl && domUtils.getNodeText(topElement))
.then((isNonEmptyChild: HTMLElement) => isNonEmptyChild || topElement && domUtils.isNodeEqual(topElement, element) ? topElement : null);
});
}

function correctTopElementByExpectedElement<E> (topElement: E, expectedElement?: E): Promise<E> | E {
function correctTopElementByExpectedElement (topElement: Element, expectedElement?: HTMLElement): Promise<HTMLElement> | HTMLElement {
if (!expectedElement || !topElement || domUtils.isNodeEqual(topElement, expectedElement))
return topElement;

Expand Down Expand Up @@ -56,24 +54,24 @@ function correctTopElementByExpectedElement<E> (topElement: E, expectedElement?:
if (!shouldSearchForMultilineLink)
return topElement;

return Promise.resolve(adapter.position.getClientDimensions(expectedElement))
return Promise.resolve(positionUtils.getClientDimensions(expectedElement))
.then((linkRect: any) => findElementOrNonEmptyChildFromPoint({ x: linkRect.right - 1, y: linkRect.top + 1 }, expectedElement)
.then((el: any) => el || findElementOrNonEmptyChildFromPoint({ x: linkRect.left + 1, y: linkRect.bottom - 1 }, expectedElement))
.then((el: any) => el || topElement));
});
}

export default function getElementFromPoint<E, W extends SharedWindow> (point: AxisValuesData<number>, win: W, expectedEl?: E): Promise<E> {
return adapter.getElementExceptUI(point)
.then((topElement: E) => {
export default function getElementFromPoint (point: AxisValuesData<number>, win?: Window, expectedEl?: HTMLElement): Promise<HTMLElement> {
return getElementExceptUI(point)
.then((topElement: HTMLElement) => {
// NOTE: when trying to get an element by elementFromPoint in iframe and the target
// element is under any of shadow-ui elements, you will get null (only in IE).
// In this case, you should hide a top window's shadow-ui root to obtain an element.
let resChain = Promise.resolve(topElement);

if (!topElement && isIframeWindow(win) && point.x > 0 && point.y > 0)
resChain = resChain.then(() => adapter.getElementExceptUI(point, true));
if (!topElement && utils.dom.isIframeWindow(win || window) && point.x > 0 && point.y > 0)
resChain = resChain.then(() => getElementExceptUI(point, true));

return resChain.then((element: E) => correctTopElementByExpectedElement(element, expectedEl));
return resChain.then((element: HTMLElement) => correctTopElementByExpectedElement(element, expectedEl));
});
}
11 changes: 4 additions & 7 deletions src/client/automation/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// NOTE: Initializer should be the first
import './shared-adapter-initializer';

import hammerhead from './deps/hammerhead';
import DispatchEventAutomation from './playback/dispatch-event';
import SetScrollAutomation from './playback/set-scroll';
import ScrollIntoViewAutomation from './playback/scroll-into-view';
import ClickAutomation from '../../shared/actions/automations/click';
import ClickAutomation from './playback/click';
import SelectChildClickAutomation from './playback/click/select-child';
import DblClickAutomation from './playback/dblclick';
import DragToOffsetAutomation from './playback/drag/to-offset';
Expand All @@ -22,16 +19,16 @@ import {
ClickOptions,
TypeOptions,
} from '../../test-run/commands/options';
import AutomationSettings from '../../shared/actions/automations/settings';
import { getOffsetOptions } from '../../shared/actions/utils/offsets';
import AutomationSettings from './settings';
import { getOffsetOptions } from '../core/utils/offsets';
import { getNextFocusableElement } from './playback/press/utils';
import SHORTCUT_TYPE from './playback/press/shortcut-type';
import { getSelectionCoordinatesByPosition } from './playback/select/utils';
import getElementFromPoint from './get-element';
import calculateSelectTextArguments from './playback/select/calculate-select-text-arguments';
import ERROR_TYPES from '../../shared/errors/automation-errors';
import cursor from './cursor';
import MoveAutomation from '../../shared/actions/automations/move';
import MoveAutomation from './move';


const exports = {};
Expand Down

0 comments on commit 10eef98

Please sign in to comment.