Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: debug with selector option added #8066

Merged
merged 9 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add: debug with selector option added
  • Loading branch information
Bayheck committed Nov 2, 2023
commit dd8305338962596188d6496a72cdedf8685c1e87
7 changes: 4 additions & 3 deletions src/api/test-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
AddRequestHooksCommand,
RemoveRequestHooksCommand,
ReportCommand,
DebugCommand,
} from '../../test-run/commands/actions';

import {
Expand All @@ -67,7 +68,7 @@ import {
MaximizeWindowCommand,
} from '../../test-run/commands/browser-manipulation';

import { WaitCommand, DebugCommand } from '../../test-run/commands/observation';
import { WaitCommand } from '../../test-run/commands/observation';
import { createExecutionContext as createContext } from './execution-context';
import { isSelector } from '../../client-functions/types';

Expand Down Expand Up @@ -602,8 +603,8 @@ export default class TestController {
return new Assertion(actual, this, callsite);
}

[delegatedAPI(DebugCommand.methodName)] () {
return this.enqueueCommand(DebugCommand);
[delegatedAPI(DebugCommand.methodName)] (selector) {
return this.enqueueCommand(DebugCommand, { selector });
}

[delegatedAPI(SetTestSpeedCommand.methodName)] (speed) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,10 @@ export default class Driver extends serviceUtils.EventEmitter {
});
}

_onSetBreakpointCommand ({ isTestError }) {
_onSetBreakpointCommand ({ isTestError, selector }) {
const showDebuggingStatusPromise = this.statusBar.showDebuggingStatus(isTestError);

this.selectorInspectorPanel.show();
this.selectorInspectorPanel.show(selector);

showDebuggingStatusPromise.then(debug => {
const stopAfterNextAction = debug === STATUS_BAR_DEBUG_ACTION.step;
Expand Down
10 changes: 6 additions & 4 deletions src/client/ui/selector-inspector-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ export default class SelectorInspectorPanel {
this.element = createElementFromDescriptor(panel);

const pickButton = new PickButton();
const selectorInputContainer = new SelectorInputContainer();
const copyButton = new CopyButton(selectorInputContainer);
const container = new MainContainer(pickButton.element, selectorInputContainer.element, copyButton.element);

Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
this.selectorInputContainer = new SelectorInputContainer();
const copyButton = new CopyButton(this.selectorInputContainer);
const container = new MainContainer(pickButton.element, this.selectorInputContainer.element, copyButton.element);
const hideButton = new HideButton(this.element);

this.element.appendChild(container.element);
this.element.appendChild(hideButton.element);
}

show () {
show (selector) {
this.selectorInputContainer._debugSelector(selector);
if (!this.element.parentElement)
uiRoot.insertFirstChildToPanelsContainer(this.element);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import hammerhead from './../deps/hammerhead';
import testCafeCore from './../deps/testcafe-core';

import { createElementFromDescriptor } from './utils/create-element-from-descriptor';
import { getElementsBySelector } from './utils/get-elements-by-selector';
import { getElementsBySelector, executeSelector } from './utils/get-elements-by-selector';

import * as descriptors from './descriptors';
import { elementPicker, ELEMENT_PICKED } from './element-picker';
Expand Down Expand Up @@ -159,4 +159,16 @@ export class SelectorInputContainer {
this._indicateMatches(elements);
this._highlightElements(elements);
}

async _debugSelector (selector) {
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
highlighter.stopHighlighting();
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
const selectorValue = selector.apiFnChain.join('');
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved

this.value = selectorValue;
let elements = await executeSelector(selector).catch(() => null);
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved

elements = nativeMethods.isArray(elements) ? elements : [elements];
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
this._indicateMatches(elements);
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
this._highlightElements(elements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function parseSelector (selector) {
return browser.parseSelector(communicationUrls.parseSelector, createNativeXHR, selector);
}

async function executeSelector (parsedSelector) {
export async function executeSelector (parsedSelector) {
const startTime = nativeMethods.date();
const selectorExecutor = new SelectorExecutor(parsedSelector, GLOBAL_TIMEOUT, startTime, createNotFoundError, createIsInvisibleError);
const elements = await selectorExecutor.getResult();
Expand Down
18 changes: 18 additions & 0 deletions src/test-run/commands/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ export class ClickCommand extends ActionCommandBase {
}
}

export class DebugCommand extends ActionCommandBase {
static methodName = camelCase(TYPE.debug);

constructor (obj, testRun,) {
super(obj, testRun, TYPE.debug);
}

getAssignableProperties () {
return [
{ name: 'selector', init: (name, val, options) => {
return initSelector(name, val, Object.assign({}, options,
{ skipVisibilityCheck: true, collectionMode: true }
));
}, required: false },
];
}
}

export class RightClickCommand extends ActionCommandBase {
static methodName = camelCase(TYPE.rightClick);

Expand Down
1 change: 1 addition & 0 deletions src/test-run/commands/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class CommandBase {
public constructor(obj?: object, testRun?: TestRun, type?: string, validateProperties?: boolean);
public actionId: string;
public type: string;
public selector: object;
[key: string]: unknown;
public getAssignableProperties(): { name: string }[];
public getAllAssignableProperties(): { name: string }[];
Expand Down
3 changes: 2 additions & 1 deletion src/test-run/commands/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export class HideAssertionRetriesStatusCommand {
}

export class SetBreakpointCommand {
constructor (isTestError) {
constructor (isTestError, selector) {
this.type = TYPE.setBreakpoint;
this.isTestError = isTestError;
this.selector = selector;
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test-run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export default class TestRun extends AsyncEventEmitter {
if (this.errs.length && this.debugOnFail) {
const errStr = this.debugReporterPluginHost.formatError(this.errs[0]);

await this._enqueueSetBreakpointCommand(void 0, errStr);
await this._enqueueSetBreakpointCommand(void 0, null, errStr);
}

await this.emit('before-done');
Expand Down Expand Up @@ -821,11 +821,11 @@ export default class TestRun extends AsyncEventEmitter {
return this.cookieProvider.deleteCookies(cookies, urls);
}

private async _enqueueSetBreakpointCommand (callsite: CallsiteRecord | undefined, error?: string): Promise<void> {
private async _enqueueSetBreakpointCommand (callsite: CallsiteRecord | undefined, selector?: object | null, error?: string): Promise<void> {
if (this.debugLogger)
this.debugLogger.showBreakpoint(this.session.id, this.browserConnection.userAgent, callsite, error);

this.debugging = await this._internalExecuteCommand(new serviceCommands.SetBreakpointCommand(!!error), callsite) as boolean;
this.debugging = await this._internalExecuteCommand(new serviceCommands.SetBreakpointCommand(!!error, selector), callsite) as boolean;
}

private _removeAllNonServiceTasks (): void {
Expand Down Expand Up @@ -1154,7 +1154,7 @@ export default class TestRun extends AsyncEventEmitter {
const canDebug = !this.browserConnection.isHeadlessBrowser();

if (canDebug)
return await this._enqueueSetBreakpointCommand(callsite as CallsiteRecord, void 0);
return await this._enqueueSetBreakpointCommand(callsite as CallsiteRecord, command?.selector, void 0);

this.debugging = false;

Expand Down