diff --git a/package.json b/package.json index 6e7d53fbec8..2201502190b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "testcafe", "description": "Automated browser testing for the modern web development stack.", "license": "MIT", - "version": "1.20.1-rc.1", + "version": "1.20.1-rc.2", "author": { "name": "Developer Express Inc.", "url": "https://www.devexpress.com/" @@ -137,7 +137,7 @@ "source-map-support": "^0.5.16", "strip-bom": "^2.0.0", "testcafe-browser-tools": "2.0.23", - "testcafe-hammerhead": "24.6.0", + "testcafe-hammerhead": "24.7.2", "testcafe-legacy-api": "5.1.4", "testcafe-reporter-dashboard": "1.0.0-rc.3", "testcafe-reporter-json": "^2.1.0", diff --git a/src/client/core/utils/position.ts b/src/client/core/utils/position.ts index 0f4b7629213..a049c07fc2d 100644 --- a/src/client/core/utils/position.ts +++ b/src/client/core/utils/position.ts @@ -127,6 +127,53 @@ export function containsOffset (el: HTMLElement, offsetX?: number, offsetY?: num (typeof offsetY === 'undefined' || offsetY >= 0 && maxY >= offsetY); } +export function getEventAbsoluteCoordinates (ev: MouseEvent): AxisValues { + const el = ev.target || ev.srcElement; + const pageCoordinates = getEventPageCoordinates(ev); + const curDocument = domUtils.findDocument(el); + let xOffset = 0; + let yOffset = 0; + + if (domUtils.isElementInIframe(curDocument.documentElement)) { + const currentIframe = domUtils.getIframeByElement(curDocument); + + if (currentIframe) { + const iframeOffset = getOffsetPosition(currentIframe); + const iframeBorders = styleUtils.getBordersWidth(currentIframe); + + xOffset = iframeOffset.left + iframeBorders.left; + yOffset = iframeOffset.top + iframeBorders.top; + } + } + + return new AxisValues(pageCoordinates.x + xOffset, pageCoordinates.y + yOffset); +} + +export function getEventPageCoordinates (ev: MouseEvent): AxisValues { + const curCoordObject = /^touch/.test(ev.type) && (ev as unknown as TouchEvent).targetTouches ? (ev as unknown as TouchEvent).targetTouches[0] || (ev as unknown as TouchEvent).changedTouches[0] : ev; + + const bothPageCoordinatesAreZero = curCoordObject.pageX === 0 && curCoordObject.pageY === 0; + const notBothClientCoordinatesAreZero = curCoordObject.clientX !== 0 || curCoordObject.clientY !== 0; + + if ((curCoordObject.pageX === null || bothPageCoordinatesAreZero && notBothClientCoordinatesAreZero) && + curCoordObject.clientX !== null) { + const currentDocument = domUtils.findDocument(ev.target || ev.srcElement); + const html = currentDocument.documentElement; + const body = currentDocument.body; + + return new AxisValues( + Math.round(curCoordObject.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - + (html.clientLeft || 0)), + Math.round(curCoordObject.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - + (html.clientTop || 0)) + ); + } + return new AxisValues( + Math.round(curCoordObject.pageX), + Math.round(curCoordObject.pageY) + ); +} + export function getIframePointRelativeToParentFrame (pos: AxisValues, iframeWin: Window): AxisValues { const iframe = domUtils.findIframeByWindow(iframeWin); const iframeOffset = getOffsetPosition(iframe); diff --git a/test/client/fixtures/automation/click-test.js b/test/client/fixtures/automation/click-test.js index cdd55e3d418..470ff493238 100644 --- a/test/client/fixtures/automation/click-test.js +++ b/test/client/fixtures/automation/click-test.js @@ -1161,9 +1161,11 @@ $(document).ready(function () { .then(function () { ok($area.data('clicked'), 'area element was clicked'); notOk($img.data('clicked'), 'img element was not clicked'); + startNext(); }); - }, TEST_RESULT_TIMEOUT); + // This test under Firefox MacOS takes a little more time. + }, TEST_RESULT_TIMEOUT + 200); }); module('touch devices test'); diff --git a/test/client/fixtures/core/page-unload-barrier-test.js b/test/client/fixtures/core/page-unload-barrier-test.js index 2929e36738f..aa935a9cb8e 100644 --- a/test/client/fixtures/core/page-unload-barrier-test.js +++ b/test/client/fixtures/core/page-unload-barrier-test.js @@ -79,7 +79,7 @@ $(document).ready(function () { const iframeDocument = iframe.contentDocument; const link = iframeDocument.createElement('a'); - link.href = '/xhr-test/750'; + link.href = '/xhr-test/650'; link.textContent = 'link'; iframeDocument.body.appendChild(link); diff --git a/test/functional/fixtures/api/es-next/request-hooks/test.js b/test/functional/fixtures/api/es-next/request-hooks/test.js index 0e9e386b78c..3cfa36d3956 100644 --- a/test/functional/fixtures/api/es-next/request-hooks/test.js +++ b/test/functional/fixtures/api/es-next/request-hooks/test.js @@ -26,6 +26,10 @@ describe('Request Hooks', () => { expect(testReport.errs[0]).contains('Error in the "respond" method'); }); }); + + it('Should not raise an error if response has 500 status code (GH-7213)', () => { + return runTests('./testcafe-fixtures/request-mock/500-status-code.js', null, { only: 'chrome' }); + }); }); describe('RequestLogger', () => { diff --git a/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/request-mock/500-status-code.js b/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/request-mock/500-status-code.js new file mode 100644 index 00000000000..83865074af0 --- /dev/null +++ b/test/functional/fixtures/api/es-next/request-hooks/testcafe-fixtures/request-mock/500-status-code.js @@ -0,0 +1,13 @@ +import { RequestMock } from 'testcafe'; + +fixture `Fixture`; + +test + .requestHooks( + RequestMock() + .onRequestTo(/d/) + .respond('', 500) + ) + ('should pass', async t => { + await t.expect(true).ok(); + });