wait.js
4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*global casper*/
/*jshint strict:false*/
casper.test.begin('wait() tests', 1, function(test) {
var waitStart;
casper.start('tests/site/index.html', function() {
waitStart = new Date().getTime();
});
casper.wait(250, function() {
test.assert(new Date().getTime() - waitStart > 250,
'Casper.wait() can wait for a given amount of time');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitFor() tests', 2, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitFor(function() {
return this.evaluate(function() {
return document.querySelectorAll('li').length === 4;
});
}, function() {
test.pass('Casper.waitFor() can wait for something to happen');
}, function() {
test.fail('Casper.waitFor() can wait for something to happen');
});
casper.reload().waitFor(function(){
return false;
}, function() {
test.fail('waitFor() processes onTimeout callback');
}, function() {
test.pass('waitFor() processes onTimeout callback');
}, 1000);
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForResource() tests', 2, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitForResource('phantom.png', function() {
test.pass('Casper.waitForResource() waits for a resource');
}, function() {
test.fail('Casper.waitForResource() waits for a resource');
});
casper.reload().waitForResource(/phantom\.png$/, function() {
test.pass('Casper.waitForResource() waits for a resource using RegExp');
}, function() {
test.fail('Casper.waitForResource() waits for a resource using RegExp');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForSelector() tests', 1, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitForSelector('li:nth-child(4)', function() {
test.pass('Casper.waitForSelector() waits for a selector to exist');
}, function() {
test.fail('Casper.waitForSelector() waits for a selector to exist');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForText() tests', 3, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitForText('<li>four</li>', function() {
test.pass('Casper.waitForText() can wait for text');
}, function() {
test.fail('Casper.waitForText() can wait for text');
});
casper.reload().waitForText(/four/i, function() {
test.pass('Casper.waitForText() can wait for regexp');
}, function() {
test.fail('Casper.waitForText() can wait for regexp');
});
casper.reload().waitForText('Voilà', function() {
test.pass('Casper.waitForText() can wait for decoded HTML text');
}, function() {
test.fail('Casper.waitForText() can wait for decoded HTML text');
}, 1000);
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForSelectorTextChange() tests', 1, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitForSelectorTextChange('#textChange', function() {
test.pass('Casper.waitForSelectorTextChange() can wait for text on a selector to change');
}, function() {
test.fail('Casper.waitForSelectorTextChange() can wait for text on a selector to change');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitUntilVisible() tests', 2, function(test) {
casper.start('tests/site/waitFor.html');
casper.waitUntilVisible('li:nth-child(4)', function() {
test.pass('Casper.waitUntilVisible() waits for a selector being visible');
}, function() {
test.fail('Casper.waitUntilVisible() waits for a selector being visible');
});
casper.waitUntilVisible('p', function() {
test.pass('Casper.waitUntilVisible() waits for a selector being visible');
}, function() {
test.fail('Casper.waitUntilVisible() waits for a selector being visible');
});
casper.run(function() {
test.done();
});
});