Skip to content

Commit

Permalink
Fallback to textContent for <option> element text selectors in Fi…
Browse files Browse the repository at this point in the history
…refox (fixes DevExpress#861) (DevExpress#862)

* Fallback to `textContent` for `<option>` element text selectors in Firefox (fixes DevExpress#861)

* Use utils method to determine <option>, fix linting error, isolate breaking dependency on node 10

* Fix comment
  • Loading branch information
inikulin authored and helen-dikareva committed Oct 12, 2016
1 parent b4e0bb4 commit 9b5e6bb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
40 changes: 22 additions & 18 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var spawn = require('cross-spawn');
var serveStatic = require('serve-static');
var Promise = require('pinkie');
var markdownlint = require('markdownlint');
var ghpages = require('gulp-gh-pages');
var prompt = require('gulp-prompt');
var nodeVer = require('node-version');
var functionalTestConfig = require('./test/functional/config');
Expand Down Expand Up @@ -472,9 +471,9 @@ gulp.task('preview-website', function () {
return new Promise(function (resolve) {
runSequence('build-website-development', 'serve-website', resolve);
})
.then(function () {
return opn('http://localhost:8080/testcafe');
});
.then(function () {
return opn('http://localhost:8080/testcafe');
});
});

function testWebsite (isTravis) {
Expand All @@ -483,22 +482,22 @@ function testWebsite (isTravis) {

runSequence(buildTask, 'serve-website', resolve);
})
.then(function () {
var WebsiteTester = require('./test/website/test.js');
var websiteTester = new WebsiteTester();

return websiteTester.checkLinks();
})
.then(function (failed) {
return new Promise(function (resolve, reject) {
websiteServer.close(function () {
if (failed)
reject('Broken links found!');
else
resolve();
.then(function () {
var WebsiteTester = require('./test/website/test.js');
var websiteTester = new WebsiteTester();

return websiteTester.checkLinks();
})
.then(function (failed) {
return new Promise(function (resolve, reject) {
websiteServer.close(function () {
if (failed)
reject('Broken links found!');
else
resolve();
});
});
});
});
}

gulp.task('test-website', function () {
Expand All @@ -510,6 +509,11 @@ gulp.task('test-website-travis', function () {
});

gulp.task('publish-website', ['build-website-production'], function () {
// NOTE: it's accidentally stopped being compatible with node 0.10 without
// major version bump due to https://github.com/floridoo/gulp-sourcemaps/issues/236,
// so we require it here.
var ghpages = require('gulp-gh-pages');

return gulp
.src('site/deploy/**/*')
.pipe(prompt.confirm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ function visible (el) {

function hasText (node, textRe) {
// Element
if (node.nodeType === 1)
return textRe.test(getInnerText(node));
if (node.nodeType === 1) {
var text = getInnerText(node);

// NOTE: In Firefox, <option> elements don't have `innerText`.
// So, we fallback to `textContent` in that case (see GH-861).
if (domUtils.isOptionElement(node)) {
var textContent = getTextContent(node);

if (!text && textContent)
text = textContent;
}

return textRe.test(text);
}

// Document and DocumentFragment
if (node.nodeType === 9 || node.nodeType === 11)
Expand Down
4 changes: 4 additions & 0 deletions test/functional/fixtures/api/es-next/selector/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,9 @@ describe('[API] Selector', function () {
it("Should execute successfully if derivative selector doesn't have options (GH-716)", function () {
return runTests('./testcafe-fixtures/selector-test.js', 'Derivative selector without options', { only: 'chrome' });
});

it('Should select <option> element by text in Firefox (GH-861)', function () {
return runTests('./testcafe-fixtures/selector-test.js', '<option> text selector', { only: 'firefox' });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,10 @@ test('Derivative selector without options', async () => {

await derivative();
});

test('<option> text selector', async () => {
const selector = Selector('#selectInput > option').with({ text: 'O2' });
const el = await selector();

expect(el.id).eql('option2');
});

0 comments on commit 9b5e6bb

Please sign in to comment.