forked from NichenFly/slimerjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-webpage-frames.js
172 lines (144 loc) · 6.11 KB
/
test-webpage-frames.js
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
describe("WebPage with frames", function(){
var webpage;
var domain = "http://127.0.0.1:8083/";
var url = domain+"frame_main.html";
beforeEach(function() {
if (webpage) {
return;
}
webpage = require("webpage").create();
});
it("can be loaded",function() {
var loaded = false;
runs(function() {
webpage.open(url, function(success){
loaded = true;
});
});
waitsFor(function(){ return loaded;}, 1000);
runs(function(){
expect(loaded).toBeTruthy();
});
});
it("has the right frames count",function() {
expect(webpage.framesCount).toEqual(3);
expect(webpage.childFramesCount()).toEqual(3);
});
it("has the right frames list",function() {
expect(webpage.framesName).toEqual(["frametop","frameleft","frameright"]);
expect(webpage.childFramesName()).toEqual(["frametop","frameleft","frameright"]);
});
it("has the main window as the current frame",function() {
expect(webpage.frameTitle).toEqual('window frames');
expect(webpage.frameName).toEqual('');
expect(webpage.currentFrameName()).toEqual('');
expect(webpage.frameUrl).toEqual(url);
expect(webpage.frameContent).toNotEqual('');
expect(webpage.focusedFrameName).toEqual('');
});
it("has a frame that can be retrieved by name",function() {
webpage.switchToFrame('frametop')
expect(webpage.frameTitle).toEqual('frame top');
expect(webpage.frameName).toEqual('frametop');
expect(webpage.currentFrameName()).toEqual('frametop');
expect(webpage.frameUrl).toEqual(domain+"frame_top.html");
expect(webpage.frameContent).toNotEqual('');
expect(webpage.framePlainText).toEqual(' top frame ');
expect(webpage.title).toEqual('window frames');
expect(webpage.url).toEqual(url);
expect(webpage.windowName).toEqual('');
});
it("has a frame that can be retrieved by position",function() {
webpage.switchToMainFrame()
webpage.switchToFrame(0)
expect(webpage.frameTitle).toEqual('frame top');
expect(webpage.frameName).toEqual('frametop');
expect(webpage.currentFrameName()).toEqual('frametop');
expect(webpage.frameUrl).toEqual(domain+"frame_top.html");
expect(webpage.frameContent).toNotEqual('');
expect(webpage.framePlainText).toEqual(' top frame ');
});
it("has a sub frame that can be retrieved", function() {
// verify that switchToFrame doesn't work here, so that we are still
// in frametop
expect(webpage.switchToFrame('frameright')).toEqual(false);
expect(webpage.frameName).toEqual('frametop');
// back to main frame
webpage.switchToMainFrame()
// go into a frame then a subframe
webpage.switchToFrame('frameright');
expect(webpage.framesName).toEqual(["subframetop","subframebottom"]);
expect(webpage.framesCount).toEqual(2);
webpage.switchToFrame('subframebottom')
expect(webpage.frameTitle).toEqual('simple hello world');
expect(webpage.frameName).toEqual('subframebottom');
expect(webpage.currentFrameName()).toEqual('subframebottom');
expect(webpage.frameUrl).toEqual(domain+"simplehello.html");
expect(webpage.frameContent).toNotEqual('');
expect(webpage.framePlainText).toEqual(' Hello World! 你好 ! çàéèç ');
// test switchToParentFrame
webpage.switchToParentFrame();
expect(webpage.frameName).toEqual('frameright');
});
it("has a sub frame that can be focused", function() {
webpage.switchToMainFrame()
webpage.switchToFrame('frameleft');
expect(webpage.evaluate(function(){
return setFocusInOtherFrame();
})).toEqual("ok");
expect(webpage.frameName).toEqual('frameleft');
expect(webpage.focusedFrameName).toEqual('frametop');
expect(webpage.switchToFocusedFrame()).toEqual(true);
expect(webpage.frameName).toEqual('frametop');
});
it("has a sub frame that is unloaded", function() {
webpage.switchToMainFrame()
webpage.switchToFrame('frameright');
webpage.switchToFrame('subframebottom')
expect(webpage.frameTitle).toEqual('simple hello world');
var loaded = false;
runs(function() {
expect(webpage.evaluate(function(){
var win = window.parent.parent.frames[1];
var url = win.location.href;
var doc = win.document;
var evt = doc.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, win, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
var lk = doc.getElementById("linktoclick");
if (!lk)
return "no";
lk.dispatchEvent(evt);
return "ok "+url;
})).toEqual("ok "+domain+"frame_left.html");
setTimeout(function(){
loaded = true;
},400);
});
waitsFor(function(){ return loaded;}, 1000);
runs(function(){
expect(webpage.frameTitle).toEqual('');
webpage.switchToMainFrame();
webpage.switchToFrame('frameright');
expect(webpage.frameTitle).toEqual('test consolemessage');
webpage.close();
});
});
// webpage.frameTitle RO
// webpage.frameContent RW
// webpage.frameUrl RO
// webpage.framePlainText RO
// webpage.framesName RO
// webpage.frameName RO
// webpage.currentFrameName() D
// webpage.framesCount RO
// webpage.childFramesCount() D
// webpage.focusedFrameName
// webpage.childFramesName RO D
// webpage.switchToFrame(frameName)
// webpage.switchToChildFrame(frameName) D
// webpage.switchToFrame(position)
// webpage.switchToChildFrame(position) D
// webpage.switchToMainFrame()
// webpage.switchToParentFrame()
// webpage.switchToFocusedFrame()
});