frames.js
5.33 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
139
140
141
142
143
/*eslint strict:0*/
casper.test.begin('handling frames', 37, function(test) {
casper.start('tests/site/frames.html');
casper.on("frame.reset", function(frameInfos) {
// console.log(frameInfos.join('-'), 'forceReloaded');
});
casper.viewport(800,600);
casper.then( function(){
casper.withFrame('frame1', function() {
test.assertTitle('CasperJS frame 1');
test.assertExists("#f1");
test.assertDoesntExist("#f2");
test.assertEval(function() {
return '__utils__' in window && 'getBinary' in __utils__;
}, '__utils__ object is available in child frame');
test.assertMatches(this.page.frameContent, /This is frame 1/);
test.assertMatches(this.getHTML(), /This is frame 1/);
});
casper.withFrame('frame2', function() {
test.assertTitle('CasperJS frame 2');
test.assertExists("#f2");
test.assertDoesntExist("#f1");
test.assertEval(function() {
return '__utils__' in window && 'getBinary' in __utils__;
}, '__utils__ object is available in other child frame');
this.clickLabel('frame 3');
});
casper.withFrame('frame2', function() {
test.assertTitle('CasperJS frame 3');
});
casper.withFrame(0, function() {
test.assertTitle('CasperJS frame 1');
test.assertExists("#f1");
test.assertDoesntExist("#f2");
});
casper.withFrame(1, function() {
test.assertTitle('CasperJS frame 3');
test.assertEquals( casper.getElementInfo('a').width,100,'read tag a position');
casper.mouse.move('a');
test.assertEquals( casper.getElementInfo('a').width,200,'read tag a position hovered');
});
casper.withFrame('frame4', function() {
casper.then(function(){
casper.withFrame('frame5', function() {
casper.clickLabel('_self');
// message three is unpresent on frame 5 but as frame 5 was clean
// casperJS search on its parent frame
casper.waitForText("three",function(){
test.assertMatches( this.getHTML(),/three/,'go on self frame');
});
});
});
});
});
casper.thenOpen("tests/site/frames.html", function(){
casper.withFrame('frame4', function() {
casper.then(function(){
casper.withFrame('frame5', function() {
casper.clickLabel('_parent');
});
casper.waitForText("three",function(){
test.assertMatches( this.getHTML(),/three/,'go on parent frame');
});
});
});
});
casper.thenOpen("tests/site/frames.html", function(){
casper.withFrame('frame4', function() {
casper.then(function(){
casper.withFrame('frame5', function() {
casper.clickLabel('_top');
// message three is unpresent on frame 5 but as frame 5 was clean
// casperJS search on its parent frame
});
});
});
casper.waitForText("three",function(){
test.assertMatches( this.getHTML(),/three/,'go on top frame');
});
});
casper.thenOpen("tests/site/frames.html", function() {
var expected = ['frame1','frame1', 'frame2', 'frame2'];
casper.page.switchToMainFrame();
casper.on('frame.changed', function (name, status) {
test.assertEquals(name, expected.shift());
});
casper.switchToFrame("frame1");
test.assertTitle('CasperJS frame 1');
casper.then(function() {
// Same frame in next step
test.assertTitle('CasperJS frame 1');
casper.switchToParentFrame();
test.assertTitle("CasperJS test frames");
casper.switchToFrame("frame2");
test.assertTitle('CasperJS frame 2');
casper.switchToMainFrame();
test.assertTitle("CasperJS test frames");
this.removeAllListeners('frame.changed');
});
});
casper.thenOpen("tests/site/frames.html", function(){
var expected = ['frame4','frame5', 'frame5','frame4'];
casper.page.switchToMainFrame();
casper.on('frame.changed', function (name , status) {
test.assertEquals(name, expected.shift());
});
casper.switchToFrame("frame4");
test.assertTitle('CasperJS frame 4');
casper.switchToFrame("frame5");
test.assertTitle('CasperJS frame 1');
casper.clickLabel('_top');
});
casper.then(function() {
casper.switchToParentFrame();
casper.switchToParentFrame();
casper.waitForText("three",function(){
test.assertMatches( this.getHTML(),/three/,'go on top frame');
});
casper.switchToParentFrame();
casper.switchToParentFrame();
casper.switchToParentFrame();
casper.switchToParentFrame();
casper.switchToParentFrame();
this.removeAllListeners('frame.changed');
});
casper.run(function() {
test.assertTitle('CasperJS test index');
test.done();
});
});