From 2f85f34c6a8d57805dc3cb6c18f93eb0dc71d569 Mon Sep 17 00:00:00 2001 From: AlexanderMoskovkin Date: Mon, 23 Oct 2017 13:45:05 +0300 Subject: [PATCH] Pass options to derivative selectors (fixes #1907) --- src/client-functions/selectors/add-api.js | 7 +++- .../regression/gh-1907/pages/index.html | 22 ++++++++++ .../fixtures/regression/gh-1907/test.js | 18 ++++++++ .../gh-1907/testcafe-fixtures/index-test.js | 41 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/functional/fixtures/regression/gh-1907/pages/index.html create mode 100644 test/functional/fixtures/regression/gh-1907/test.js create mode 100644 test/functional/fixtures/regression/gh-1907/testcafe-fixtures/index-test.js diff --git a/src/client-functions/selectors/add-api.js b/src/client-functions/selectors/add-api.js index f6be1bed9cf..81396e49826 100644 --- a/src/client-functions/selectors/add-api.js +++ b/src/client-functions/selectors/add-api.js @@ -259,12 +259,17 @@ function createDerivativeSelectorWithFilter (getSelector, SelectorBuilder, selec filterNodes: filterNodes }; + var { boundTestRun, timeout, visibilityCheck } = collectionModeSelectorBuilder.options; + dependencies = assign(dependencies, additionalDependencies); var builder = new SelectorBuilder(selectorFn, { dependencies, customDOMProperties, - customMethods + customMethods, + boundTestRun, + timeout, + visibilityCheck }, { instantiation: 'Selector' }); return builder.getFunction(); diff --git a/test/functional/fixtures/regression/gh-1907/pages/index.html b/test/functional/fixtures/regression/gh-1907/pages/index.html new file mode 100644 index 00000000000..ebe5fc9083d --- /dev/null +++ b/test/functional/fixtures/regression/gh-1907/pages/index.html @@ -0,0 +1,22 @@ + + + + gh-1907 + + +
+
div +
child
+
+
+ + + + + + + diff --git a/test/functional/fixtures/regression/gh-1907/test.js b/test/functional/fixtures/regression/gh-1907/test.js new file mode 100644 index 00000000000..9c4cb9c08bb --- /dev/null +++ b/test/functional/fixtures/regression/gh-1907/test.js @@ -0,0 +1,18 @@ +var expect = require('chai').expect; + +describe('[Regression](GH-1907)', function () { + it('Base selector should pass the boundTestRun option to derivative selectors', function () { + return runTests('testcafe-fixtures/index-test.js', 'Check boundTestRun'); + }); + + it('Base selector should pass timeout and visibilityCheck options to derivative selectors', function () { + return runTests('testcafe-fixtures/index-test.js', 'Check timeout and visibilityCheck', { + selectorTimeout: 0, + shouldFail: true + }) + .catch(function (errs) { + expect(errs[0]).contains('Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.'); + expect(errs[0]).contains('> 40 | await t.expect(div.textContent).eql(\'Hidden\');'); + }); + }); +}); diff --git a/test/functional/fixtures/regression/gh-1907/testcafe-fixtures/index-test.js b/test/functional/fixtures/regression/gh-1907/testcafe-fixtures/index-test.js new file mode 100644 index 00000000000..c1e32b01d41 --- /dev/null +++ b/test/functional/fixtures/regression/gh-1907/testcafe-fixtures/index-test.js @@ -0,0 +1,41 @@ +import fs from 'fs'; +import { Selector } from 'testcafe'; + +fixture `GH-1907` + .page `http://localhost:3000/fixtures/regression/gh-1907/pages/index.html`; + +test('Check boundTestRun', async t => { + const div = Selector('#div', { boundTestRun: t }); + + return new Promise((resolve, reject) => { + fs.readFile('not/exists', async () => { + try { + await t + .expect(div.nth(0).exists).ok() + .expect(div.withText('div').exists).ok() + .expect(div.withAttribute('id', 'div').exists).ok() + .expect(div.filter(() => true).exists).ok() + .expect(div.find('#child').exists).ok() + .expect(div.parent().exists).ok() + .expect(div.child().exists).ok() + .expect(div.sibling().exists).ok() + .expect(div.nextSibling().exists).ok() + .expect(div.prevSibling().exists).ok(); + } + catch (err) { + reject(err); + return; + } + + resolve(); + }); + }); +}); + +test('Check timeout and visibilityCheck', async t => { + await t.click(Selector('#delay', { timeout: 2000 }).withText('Appears after delay')); + + const div = Selector('#hidden', { visibilityCheck: true }).withText('Hidden'); + + await t.expect(div.textContent).eql('Hidden'); +});