Skip to content

Commit a52b95a

Browse files
authored
Avoid sleep in tests (#16713)
* remove useless sleeps from SessionHandlingTest This change decrease execution time of `SessionHandlingTest` from ~28s to 7s. * Avoid `sleep(2000)` in hover tests Instead of wasting 2 second (which doesn't guarantee the result), just wait for the needed element that should appear as a result of hovering. * use much shorter polling interval to speed up the tests if the first try failed, wasting the whole 0.5 second is a huge waste of time. Let's try sooner! * Avoid `sleep` in drag'n'drop tests fix the test page usability: make the elements visible only after they are fully initialized. To force revealing potential flaky tests in the future, I've added a small pause for the initialization code. So the tests should wait until the element appears on the screen - then it's ready for manipulations. * Open a blank page before every test It's a good practice to avoid tests affecting each other: 1. Open "about:blank" page - this stops any current activity / background requests / animations on the previous page 2. Open an empty page which clears sessionStorage, localStorage and cookies. This technique allows reusing the browser between tests, while keeping the tests independent. * tiny cleanup in ExpectedConditions.java * fix potential NPE in tearDown methods Also, reset the link to static field after test run - to avoid holding heavy objects in memory till the end of all tests.
1 parent c481367 commit a52b95a

26 files changed

+460
-474
lines changed

common/src/web/dragAndDropTest.html

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
<body>
33

44
<style>
5-
<!--
6-
.dragme{position:relative;}
7-
-->
5+
.dragme{position:relative;}
6+
.hidden{visibility: hidden;}
87
</style>
9-
<script language="JavaScript1.2">
10-
<!--
8+
<script>
119

1210
var ie=document.all;
1311
var nn6=document.getElementById&&!document.all;
@@ -83,20 +81,27 @@
8381
}
8482
}
8583

86-
document.onmousedown=selectmouse;
87-
document.onmouseup=new Function("isdrag=false");
88-
89-
//-->
84+
document.onmousedown = selectmouse;
85+
document.onmouseup = new Function("isdrag=false");
9086
</script>
9187

9288

9389

94-
<img src="icon.gif" class="dragme" id="test1"><br>
95-
<img src="icon.gif" class="dragme" id="test2"><br>
90+
<img src="icon.gif" class="dragme hidden" id="test1"><br>
91+
<img src="icon.gif" class="dragme hidden" id="test2"><br>
9692
<b>"Hi there</b>
9793
<div style="position: absolute; left: 210px; top: 80px; height: 400px; width: 100px; padding: 10em;">
98-
<img src="icon.gif" class="dragme" id="test3"><br>
99-
<img src="icon.gif" class="dragme" id="test4"><br>
94+
<img src="icon.gif" class="dragme hidden" id="test3"><br>
95+
<img src="icon.gif" class="dragme hidden" id="test4"><br>
10096
</div>
97+
98+
<script>
99+
(() => {
100+
document.querySelectorAll('.hidden').forEach(item => {
101+
item.classList.remove('hidden');
102+
})
103+
})()
104+
</script>
105+
101106
</body>
102107
</html>

common/src/web/draggableLists.html

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,42 @@
1414
</style>
1515
<script type="text/javascript">
1616
$(function() {
17-
$("#sortable1, #sortable2").sortable({
18-
connectWith: '.connectedSortable'
19-
}).disableSelection();
17+
$("#sortable1, #sortable2").sortable({
18+
connectWith: '.connectedSortable'
19+
}).disableSelection();
2020

21-
var report_event = function(report_text) {
22-
var reportElement = $("#dragging_reports");
23-
var origText = reportElement.text();
24-
reportElement.text(origText + " " + report_text);
25-
}
26-
27-
$("#sortable2").droppable({
28-
out: function(event, ui) {
29-
report_event("DragOut");
30-
}
31-
});
21+
var report_event = function(report_text) {
22+
var reportElement = $("#dragging_reports");
23+
var origText = reportElement.text();
24+
reportElement.text(origText + " " + report_text);
25+
}
3226

33-
$("#sortable1").droppable({
34-
drop: function(event, ui) {
35-
report_event("DropIn " + ui.draggable.text());
36-
}
37-
});
27+
$("#sortable2").droppable({
28+
out: function(event, ui) {
29+
report_event("DragOut");
30+
}
3831
});
32+
33+
$("#sortable1").droppable({
34+
drop: function(event, ui) {
35+
report_event("DropIn " + ui.draggable.text());
36+
}
37+
});
38+
$("#sortable1, #sortable2").show();
39+
});
3940
</script>
4041
</head>
4142
<body>
4243
<div class="demo">
43-
<ul id="sortable1" class="connectedSortable">
44+
<ul id="sortable1" class="connectedSortable" style="display: none;">
4445
<li id="leftitem-1" class="ui-state-default">LeftItem 1</li>
4546
<li id="leftitem-2" class="ui-state-default">LeftItem 2</li>
4647
<li id="leftitem-3" class="ui-state-default">LeftItem 3</li>
4748
<li id="leftitem-4" class="ui-state-default">LeftItem 4</li>
4849
<li id="leftitem-5" class="ui-state-default">LeftItem 5</li>
4950
</ul>
5051

51-
<ul id="sortable2" class="connectedSortable">
52+
<ul id="sortable2" class="connectedSortable" style="display: none;">
5253
<li id="rightitem-1" class="ui-state-highlight">RightItem 1</li>
5354
<li id="rightitem-2" class="ui-state-highlight">RightItem 2</li>
5455
<li id="rightitem-3" class="ui-state-highlight">RightItem 3</li>

common/src/web/droppableItems.html

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,45 @@
1111
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
1212
</style>
1313
<script type="text/javascript">
14-
$(function() {
15-
$("#draggable").draggable();
16-
$("#droppable").droppable({
17-
drop: function(event, ui) {
18-
$(this).addClass('ui-state-highlight').find('p').html('Dropped!');
14+
$(function () {
15+
$("#draggable").draggable();
16+
$("#droppable").droppable({
17+
drop: function () {
18+
$(this).addClass('ui-state-highlight').find('p').html('Dropped!');
19+
}
20+
});
21+
22+
const report_event = function (report_text) {
23+
const reportElement = $("#drop_reports");
24+
const origText = reportElement.text();
25+
reportElement.text(origText + " " + report_text);
1926
}
20-
});
2127

22-
var report_event = function(report_text) {
23-
var reportElement = $("#drop_reports");
24-
var origText = reportElement.text();
25-
reportElement.text(origText + " " + report_text);
26-
}
28+
$('body').mousedown(function () {
29+
report_event('down');
30+
});
2731

28-
$('body').mousedown(function() {
29-
report_event('down');
30-
});
32+
$('body').mousemove(function () {
33+
report_event('move');
34+
});
3135

32-
$('body').mousemove(function() {
33-
report_event('move');
34-
});
36+
$('body').mouseup(function () {
37+
report_event('up');
38+
});
3539

36-
$('body').mouseup(function() {
37-
report_event('up');
38-
});
39-
});
40+
$("#droppable").show();
41+
$("#draggable").show();
42+
});
4043
</script>
4144
</head>
4245
<body>
4346
<div class="demo">
4447

45-
<div id="draggable" class="ui-widget-content">
48+
<div id="draggable" class="ui-widget-content" style="display: none;">
4649
<p>Drag me to my target</p>
4750
</div>
4851

49-
<div id="droppable" class="ui-widget-header">
52+
<div id="droppable" class="ui-widget-header" style="display: none;">
5053
<p>Drop here</p>
5154
</div>
5255

common/src/web/macbeth.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
</HEAD>
88
<body bgcolor="#ffffff" text="#000000">
99

10+
<h1>The Tragedy of Macbeth</h1>
11+
1012
<!-- Originally from http://shakespeare.mit.edu/macbeth/full.html -->
1113

1214
<a href="#5.8.86">Quick link to last speech</a>

0 commit comments

Comments
 (0)