Skip to content

Commit

Permalink
test: fixed tests for mobile safari (#7869)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->
[closes DevExpress/testcafe-private#218]

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
_Provide a link to the existing issue(s), if any._

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
Aleksey28 authored Jul 12, 2023
1 parent 34a4f36 commit 9e6b1fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
16 changes: 9 additions & 7 deletions test/client/fixtures/automation/click-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const cursor = testCafeAutomation.cursor;

testCafeCore.preventRealEvents();

const isSafariGreaterThan15 = browserUtils.isSafari && parseFloat(browserUtils.fullVersion) >= '15.0';
const isMobileSafari = browserUtils.isSafari && featureDetection.isTouchDevice;
const nextTestDelay = browserUtils.isIE ? 30 : 200;
const TEST_RESULT_TIMEOUT = featureDetection.isTouchDevice ? 2500 : 500;
const IS_SAFARI_GREATER_THAN_15 = browserUtils.isSafari && parseFloat(browserUtils.fullVersion) >= '15.0';
const IS_MOBILE_SAFARI = browserUtils.isSafari && featureDetection.isTouchDevice;
const NEXT_TEST_DELAY = IS_MOBILE_SAFARI ? 200 : 30;
const TEST_RESULT_TIMEOUT = featureDetection.isTouchDevice ? 2500 : 500;

QUnit.config.testTimeout = 30000;

$(document).ready(function () {
let $el = null;
Expand Down Expand Up @@ -76,9 +78,9 @@ $(document).ready(function () {
};

const startNext = function () {
if (browserUtils.isIE || isMobileSafari) {
if (browserUtils.isIE || IS_MOBILE_SAFARI) {
removeTestElements();
window.setTimeout(start, nextTestDelay);
window.setTimeout(start, NEXT_TEST_DELAY);
}
else
start();
Expand Down Expand Up @@ -1040,7 +1042,7 @@ $(document).ready(function () {

// NOTE: We turn off some tests due to an issue in Safari 15.
// Need to check these tests on the next Safari versions (15.3 and later).
if (!isSafariGreaterThan15) {
if (!IS_SAFARI_GREATER_THAN_15) {
asyncTest('T224332 - TestCafe problem with click on links in popup menu (click on link with span inside without offset)', function () {
const $box = $('<div></div>').css('width', '128px').appendTo($('body'));
const $link = $('<a href="javascript:void(0);"></a>').appendTo($box);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const domUtils = testCafeCore.domUtils;
const textSelection = testCafeCore.textSelection;
const parseKeySequence = testCafeCore.parseKeySequence;

const isMobileSafari = browserUtils.isSafari && featureDetection.isTouchDevice;
const nextTestDelay = isMobileSafari ? 200 : 30;
const IS_MOBILE_SAFARI = browserUtils.isSafari && featureDetection.isTouchDevice;
const NEXT_TEST_DELAY = IS_MOBILE_SAFARI ? 200 : 30;

testCafeCore.preventRealEvents();

QUnit.config.testTimeout = 30000;

$(document).ready(function () {
// NOTE: https://github.com/DevExpress/testcafe/issues/2008
// Remove this condition when the issue will be fixed.
Expand All @@ -40,8 +42,8 @@ $(document).ready(function () {
let sixthElementInnerHTML = null;
let seventhElementInnerHTML = null;

const startNext = function () {
window.setTimeout(start, nextTestDelay);
const startNext = function (delay) {
window.setTimeout(start, delay || NEXT_TEST_DELAY);
};

const firstNotWhiteSpaceSymbolIndex = function (value) {
Expand Down Expand Up @@ -157,7 +159,7 @@ $(document).ready(function () {
ok(clicked, 'click raised');
checkSelection($parent, $el[0].childNodes[0], 10, $el[0].childNodes[0], 10);

startNext();
startNext(IS_MOBILE_SAFARI && 700);
});
});

Expand All @@ -181,7 +183,7 @@ $(document).ready(function () {
ok(clicked, 'click raised');
checkSelection($parent, $parent[0].childNodes[5].childNodes[3].childNodes[0], 1, $parent[0].childNodes[5].childNodes[3].childNodes[0], 1);

startNext();
startNext(IS_MOBILE_SAFARI && 700);
});
});

Expand Down
14 changes: 9 additions & 5 deletions test/client/fixtures/automation/drag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const hammerhead = window.getTestCafeModule('hammerhead');
const browserUtils = hammerhead.utils.browser;
const featureDetection = hammerhead.utils.featureDetection;

const isMobileSafari = browserUtils.isSafari && featureDetection.isTouchDevice;
const TEST_RESULT_TIMEOUT = featureDetection.isTouchDevice ? 2500 : 500;
const IS_MOBILE_SAFARI = browserUtils.isSafari && featureDetection.isTouchDevice;

QUnit.config.testTimeout = 30000;

Expand All @@ -22,7 +22,7 @@ $(document).ready(function () {
$('body').css('border', '0px');

// NOTE: prevent auto scrolling
if (browserUtils.isSafari && featureDetection.isTouchDevice) {
if (IS_MOBILE_SAFARI) {
const $meta = $('<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, shrink-to-fit=no">');

$('head').append($meta);
Expand All @@ -34,6 +34,10 @@ $(document).ready(function () {
//utils
const isTouchDevice = featureDetection.isTouchDevice;

const startNext = function (delay) {
window.setTimeout(start, delay);
};

const createDraggable = function (left, top, withGloballCoord) {
const $draggable = $('<div></div>')
.css({
Expand Down Expand Up @@ -138,7 +142,7 @@ $(document).ready(function () {
.run()
.then(function () {
ok(isInTarget(draggable, target), 'element is in the target');
start();
startNext(IS_MOBILE_SAFARI && 700);
});
}, TEST_RESULT_TIMEOUT);
});
Expand Down Expand Up @@ -167,7 +171,7 @@ $(document).ready(function () {
// This issue is not reproduced in real devices (checked with the devices from BrowserStack).
// It can be partially fixed using the minimal test speed. But in this case, the test is still unstable.
// We are forced to turn off it for mobile Safari. Try to turn on it in the future.
if (!isMobileSafari) {
if (!IS_MOBILE_SAFARI) {
asyncTest('overlapped during dragging', function () {
window.setTimeout(function () {
const draggable = createDraggable(100, 100)[0];
Expand All @@ -194,7 +198,7 @@ $(document).ready(function () {
// This issue is not reproduced in real devices (checked with the devices from BrowserStack).
// It can be partially fixed using the minimal test speed. But in this case, the test is still unstable.
// We are forced to turn off it for mobile Safari. Try to turn on it in the future.
if (!isMobileSafari) {
if (!IS_MOBILE_SAFARI) {
asyncTest('B253930 - Wrong playback of drag action on http://jqueryui.com/droppable/ in IE9', function () {
const $draggable = createDraggable(10, 10, true);
const center = getCenter($draggable[0]);
Expand Down
12 changes: 6 additions & 6 deletions test/client/fixtures/automation/regression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const PressAutomation = testCafeAutomation.Press;
const getOffsetOptions = testCafeAutomation.getOffsetOptions;
const cursor = testCafeAutomation.cursor;

const IS_MOBILE_SAFARI = browserUtils.isSafari && featureDetection.isTouchDevice;

testCafeCore.preventRealEvents();

$(document).ready(function () {
Expand Down Expand Up @@ -141,11 +143,9 @@ $(document).ready(function () {
return $draggable;
};

const startNext = function () {
if (browserUtils.isIE) {
removeTestElements();
window.setTimeout(start, 30);
}
const startNext = function (delay) {
if (delay)
window.setTimeout(start, delay);
else
start();
};
Expand Down Expand Up @@ -495,7 +495,7 @@ $(document).ready(function () {

runClickAutomation($b[0], {}, function () {
ok(clickRaised);
startNext();
startNext(IS_MOBILE_SAFARI && 500);
});
});

Expand Down

0 comments on commit 9e6b1fa

Please sign in to comment.