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

fix(Selector Inspector): selectors parsing in experimental debug mode #7517

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/api/test-controller/execution-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function createRequire (filename) {

function createSelectorDefinition (testRun) {
return (fn, options = {}) => {
const { skipVisibilityCheck, collectionMode } = testRun.controller.getExecutionContext()[OPTIONS_KEY];
const { skipVisibilityCheck, collectionMode } = testRun.controller ?
testRun.controller.getExecutionContext()[OPTIONS_KEY] :
createExecutionContext(testRun)[OPTIONS_KEY];

if (skipVisibilityCheck)
options.visibilityCheck = false;
Expand Down
11 changes: 9 additions & 2 deletions src/test-run/execute-js-expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from '../../errors/runtime';

import { UncaughtErrorInCustomScript, UncaughtTestCafeErrorInCustomScript } from '../../errors/test-run';
import { setContextOptions, DEFAULT_CONTEXT_OPTIONS } from '../../api/test-controller/execution-context';
import {
setContextOptions,
DEFAULT_CONTEXT_OPTIONS,
createExecutionContext,
} from '../../api/test-controller/execution-context';

import {
ERROR_LINE_COLUMN_REGEXP,
Expand Down Expand Up @@ -78,7 +82,10 @@ function isRuntimeError (err) {
}

export function executeJsExpression (expression, testRun, options) {
const context = getExecutionContext(testRun.controller, options);
const context = testRun.controller ?
getExecutionContext(testRun.controller, options) :
createExecutionContext(testRun);

const errorOptions = createErrorFormattingOptions();

return runInContext(expression, context, errorOptions);
Expand Down
4 changes: 3 additions & 1 deletion test/functional/fixtures/ui/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ describe('TestCafe UI', () => {

runTestCafeTest('should fill the selectors list with the generated selectors');

runTestCafeTest('should indicate the correct number of elements matching the selector');
runTestCafeTest('should indicate the correct number of elements matching the css selector');

runTestCafeTest('should indicate the correct number of elements matching the TestCafe selector');

runTestCafeTest('should indicate if the selector is invalid on input');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test('should fill the selectors list with the generated selectors', async t => {
await t.debug();
});

test('should indicate the correct number of elements matching the selector', async t => {
test('should indicate the correct number of elements matching the css selector', async t => {
await ClientFunction(() => {
const { typeSelector, getMatchIndicatorInnerText, resumeTest } = window;

Expand All @@ -110,6 +110,23 @@ test('should indicate the correct number of elements matching the selector', asy
await t.debug();
});

test('should indicate the correct number of elements matching the TestCafe selector', async t => {
await ClientFunction(() => {
const { typeSelector, getMatchIndicatorInnerText, resumeTest } = window;

typeSelector("Selector('div')")
.then(() => {
return getMatchIndicatorInnerText();
})
.then(text => {
if (text === 'Found: 4')
resumeTest();
});
})();

await t.debug();
});

test('should indicate if the selector is invalid on input', async t => {
await ClientFunction(() => {
const { typeSelector, getMatchIndicatorInnerText, resumeTest } = window;
Expand Down