diff --git a/src/api/test-controller/execution-context.js b/src/api/test-controller/execution-context.js index d81593fd780..76d7a84ae13 100644 --- a/src/api/test-controller/execution-context.js +++ b/src/api/test-controller/execution-context.js @@ -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; diff --git a/src/test-run/execute-js-expression/index.js b/src/test-run/execute-js-expression/index.js index 6c98196ca3a..e7791e06f3b 100644 --- a/src/test-run/execute-js-expression/index.js +++ b/src/test-run/execute-js-expression/index.js @@ -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, @@ -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); diff --git a/test/functional/fixtures/ui/test.js b/test/functional/fixtures/ui/test.js index 56d3e31f299..c0740ecea6b 100644 --- a/test/functional/fixtures/ui/test.js +++ b/test/functional/fixtures/ui/test.js @@ -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'); diff --git a/test/functional/fixtures/ui/testcafe-fixtures/selector-inspector-test.js b/test/functional/fixtures/ui/testcafe-fixtures/selector-inspector-test.js index 3930aa24f11..16448480db7 100644 --- a/test/functional/fixtures/ui/testcafe-fixtures/selector-inspector-test.js +++ b/test/functional/fixtures/ui/testcafe-fixtures/selector-inspector-test.js @@ -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; @@ -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;