Skip to content

Commit

Permalink
Workaround for location.origin; fix regressions (DevExpress#2978, Dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBelym committed Oct 16, 2018
1 parent b28bfb3 commit 8c578f1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/client/automation/playback/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/test-run/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}};
Expand Down
2 changes: 1 addition & 1 deletion src/errors/render-forbidden-chars-list.js
Original file line number Diff line number Diff line change
@@ -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('');
}
21 changes: 11 additions & 10 deletions src/utils/check-file-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
position: absolute;
left: 500px;
top: 500px;
width: 20px;
height: 20px;
width: 200px;
height: 200px;
background-color: red;
}

#target2 {
position: absolute;
left: 2500px;
top: 2500px;
width: 20px;
height: 20px;
width: 200px;
height: 200px;
background-color: blue;
}

Expand Down
8 changes: 8 additions & 0 deletions test/functional/fixtures/regression/gh-1057/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
16 changes: 16 additions & 0 deletions test/server/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 8c578f1

Please sign in to comment.