From 98197de44c243dd3c9ecd9f17f9b8a7dcb20fe3e Mon Sep 17 00:00:00 2001 From: Andrey Belym Date: Tue, 16 Oct 2018 16:47:20 +0300 Subject: [PATCH] Workaround for location.origin; fix regressions (#2978, #2975) --- src/client/automation/playback/scroll.js | 4 ++-- src/client/test-run/index.js.mustache | 4 ++++ src/errors/render-forbidden-chars-list.js | 2 +- src/utils/check-file-path.js | 21 ++++++++++--------- .../gh-1057/pages/hiddenByFixedParent.html | 8 +++---- .../fixtures/regression/gh-1057/test.js | 8 +++++++ .../testcafe-fixtures/hiddenByFixedParent.js | 8 +++++++ test/server/runner-test.js | 16 ++++++++++++++ test/server/test-run-error-formatting-test.js | 2 +- 9 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/client/automation/playback/scroll.js b/src/client/automation/playback/scroll.js index 646206fb85a..7a76fdd7a94 100644 --- a/src/client/automation/playback/scroll.js +++ b/src/client/automation/playback/scroll.js @@ -163,8 +163,8 @@ export default class ScrollAutomation { } _getChildPointAfterScroll (parentDimensions, childDimensions, left, top) { - const x = Math.round(childDimensions.left + parentDimensions.scroll.left - left + childDimensions.width / 2); - const y = Math.round(childDimensions.top + parentDimensions.scroll.top - top + childDimensions.height / 2); + const x = Math.round(childDimensions.left + parentDimensions.scroll.left - left + this.offsetX); + const y = Math.round(childDimensions.top + parentDimensions.scroll.top - top + this.offsetY); return { x, y }; } diff --git a/src/client/test-run/index.js.mustache b/src/client/test-run/index.js.mustache index c3ccd082d24..c612ae40751 100644 --- a/src/client/test-run/index.js.mustache +++ b/src/client/test-run/index.js.mustache @@ -4,6 +4,10 @@ var origin = location.origin; + // NOTE: location.origin doesn't exist in IE11 on Windows 10.10240 LTSB + if (!origin) + origin = location.protocol + '//' + location.host + (location.port ? ':' + location.port : ''); + var testRunId = {{{testRunId}}}; var browserId = {{{browserId}}}; var selectorTimeout = {{{selectorTimeout}}}; diff --git a/src/errors/render-forbidden-chars-list.js b/src/errors/render-forbidden-chars-list.js index a4619f4c7ec..00cd701cb43 100644 --- a/src/errors/render-forbidden-chars-list.js +++ b/src/errors/render-forbidden-chars-list.js @@ -1,3 +1,3 @@ export default function (forbiddenCharsList) { - return forbiddenCharsList.map(charInfo => `\t"${charInfo.char}" at index ${charInfo.index}\n`).join(''); + return forbiddenCharsList.map(charInfo => `\t"${charInfo.chars}" at index ${charInfo.index}\n`).join(''); } diff --git a/src/utils/check-file-path.js b/src/utils/check-file-path.js index 420973f31b1..d58495b4410 100644 --- a/src/utils/check-file-path.js +++ b/src/utils/check-file-path.js @@ -3,31 +3,32 @@ import { win as isWin } from 'os-family'; import sanitizeFilename from 'sanitize-filename'; +const SAFE_CHAR = '_'; +const ALLOWED_CHARS_LIST = [path.win32.sep, path.posix.sep, '.', '..']; + + function correctForbiddenCharsList (forbiddenCharsList, filePath) { const isWinAbsolutePath = isWin && path.isAbsolute(filePath); - const hasDriveSeparatorInList = forbiddenCharsList.length && forbiddenCharsList[0].char === ':' && forbiddenCharsList[0].index === 1; + const hasDriveSeparatorInList = forbiddenCharsList.length && forbiddenCharsList[0].chars === ':' && forbiddenCharsList[0].index === 1; if (isWinAbsolutePath && hasDriveSeparatorInList) forbiddenCharsList.shift(); } -function addForbiddenCharToList (forbiddenCharsList, forbiddenCharInfo) { - const { char } = forbiddenCharInfo; +function addForbiddenCharsToList (forbiddenCharsList, forbiddenCharsInfo) { + const { chars } = forbiddenCharsInfo; - if (char === path.win32.sep || char === path.posix.sep) - return ''; + if (!ALLOWED_CHARS_LIST.includes(chars)) + forbiddenCharsList.push(forbiddenCharsInfo); - forbiddenCharsList.push(forbiddenCharInfo); - - return ''; + return SAFE_CHAR.repeat(chars.length); } - export default function (filePath) { const forbiddenCharsList = []; sanitizeFilename(filePath, { - replacement: (char, index) => addForbiddenCharToList(forbiddenCharsList, { char, index }) + replacement: (chars, index) => addForbiddenCharsToList(forbiddenCharsList, { chars, index }) }); correctForbiddenCharsList(forbiddenCharsList, filePath); diff --git a/test/functional/fixtures/regression/gh-1057/pages/hiddenByFixedParent.html b/test/functional/fixtures/regression/gh-1057/pages/hiddenByFixedParent.html index c148f5cf277..cad9ce838f3 100644 --- a/test/functional/fixtures/regression/gh-1057/pages/hiddenByFixedParent.html +++ b/test/functional/fixtures/regression/gh-1057/pages/hiddenByFixedParent.html @@ -13,8 +13,8 @@ position: absolute; left: 500px; top: 500px; - width: 20px; - height: 20px; + width: 200px; + height: 200px; background-color: red; } @@ -22,8 +22,8 @@ position: absolute; left: 2500px; top: 2500px; - width: 20px; - height: 20px; + width: 200px; + height: 200px; background-color: blue; } diff --git a/test/functional/fixtures/regression/gh-1057/test.js b/test/functional/fixtures/regression/gh-1057/test.js index 297469e13f8..3d9d27d5aa7 100644 --- a/test/functional/fixtures/regression/gh-1057/test.js +++ b/test/functional/fixtures/regression/gh-1057/test.js @@ -6,6 +6,14 @@ describe('[Regression](GH-1057) - hidden by fixed parent', function () { skip: 'iphone,ipad,android' }); }); + + it('The target element should not be under the element with position:fixed after scroll when using custom offsets', function () { + return runTests('testcafe-fixtures/hiddenByFixedParent.js', 'gh-1057 with custom offsets', { + // NOTE: https://github.com/DevExpress/testcafe/issues/1237 + // TODO: Android disabled because of https://github.com/DevExpress/testcafe/issues/1492 + skip: 'iphone,ipad,android' + }); + }); }); describe('[Regression](GH-1057) - hidden by fixed ancestor', function () { diff --git a/test/functional/fixtures/regression/gh-1057/testcafe-fixtures/hiddenByFixedParent.js b/test/functional/fixtures/regression/gh-1057/testcafe-fixtures/hiddenByFixedParent.js index da59badf27a..302bdf06ee6 100644 --- a/test/functional/fixtures/regression/gh-1057/testcafe-fixtures/hiddenByFixedParent.js +++ b/test/functional/fixtures/regression/gh-1057/testcafe-fixtures/hiddenByFixedParent.js @@ -12,3 +12,11 @@ test('gh-1057', async t => { .click('#target1') .expect(targetsClicked()).ok(); }); + +test('gh-1057 with custom offsets', async t => { + // NOTE: scrolling has issues in iOS Simulator https://github.com/DevExpress/testcafe/issues/1237 + await t + .click('#target2', { offsetX: -1, offsetY: -1 }) + .click('#target1', { offsetX: 1, offsetY: 1 }) + .expect(targetsClicked()).ok(); +}); diff --git a/test/server/runner-test.js b/test/server/runner-test.js index f6565d778ef..7c9f83fd0c6 100644 --- a/test/server/runner-test.js +++ b/test/server/runner-test.js @@ -225,6 +225,22 @@ describe('Runner', () => { 'screenshots path pattern:\n \t":" at index 7\n'); }); }); + + it('Should allow to use relative paths in the screenshots base path and path patterns', () => { + const storedRunTaskFn = runner._runTask; + + runner._runTask = function () { + runner._runTask = storedRunTaskFn; + + return Promise.resolve({}); + }; + + return runner + .browsers(connection) + .screenshots('..', false, '${BROWSER}/./${TEST}') + .src('test/server/data/test-suites/basic/testfile2.js') + .run(); + }); }); describe('.src()', () => { diff --git a/test/server/test-run-error-formatting-test.js b/test/server/test-run-error-formatting-test.js index fcdfc39c836..d9983e08828 100644 --- a/test/server/test-run-error-formatting-test.js +++ b/test/server/test-run-error-formatting-test.js @@ -330,7 +330,7 @@ describe('Error formatting', () => { }); it('Should format "forbiddenCharactersInScreenshotPathError"', () => { - assertErrorMessage('forbidden-characters-in-screenshot-path-error', new ForbiddenCharactersInScreenshotPathError('/root/bla:bla', [{ char: ':', index: 9 }])); + assertErrorMessage('forbidden-characters-in-screenshot-path-error', new ForbiddenCharactersInScreenshotPathError('/root/bla:bla', [{ chars: ':', index: 9 }])); }); it('Should format "invalidElementScreenshotDimensionsError"', () => {