This repository has been archived by the owner on Sep 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqxwebdriver.js
195 lines (177 loc) · 5.45 KB
/
qxwebdriver.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
(function() {
var webdriver;
if (typeof require !== "undefined") {
// running in node.js
webdriver = require('./webdriver.js');
}
else if (window.webdriver) {
// running in a browser
webdriver = window.webdriver;
}
var qxwebdriver = {};
qxwebdriver.util = {
addInterfaceMethods : function(iFaces, element) {
iFaces.forEach(function(iFace, i) {
if (qxwebdriver.interactions[iFace]) {
var interactions = qxwebdriver.interactions[iFace];
for (var method in interactions) {
//console.log("adding method", method, "interface", iFace);
element[method] = interactions[method].bind(element);
}
}
});
},
getInterfacesByElement : function() {
var $qx = qx;
var widget = $qx.ui.core.Widget.getWidgetByElement(arguments[0]);
var clazz = widget.constructor;
var iFaces = [];
qx.Class.getInterfaces(clazz).forEach(function(item, i) {
iFaces.push(/\[Interface (.*?)\]/.exec(item.toString())[1]);
});
return iFaces;
},
getInterfaces : function() {
var $qx = qx;
var clazz = arguments[0].constructor;
var iFaces = [];
$qx.Class.getInterfaces(clazz).forEach(function(item, i) {
iFaces.push(/\[Interface (.*?)\]/.exec(item.toString())[1]);
});
return iFaces;
},
getClassHierarchy : function()
{
var $qx = qx;
var widget = $qx.ui.core.Widget.getWidgetByElement(arguments[0]);
var hierarchy = [];
var clazz = widget.constructor;
while (clazz && clazz.classname) {
hierarchy.push(clazz.classname);
clazz = clazz.superclass;
}
return hierarchy;
}
};
qxwebdriver.interactions = {
"qx.ui.core.ISingleSelection" : {
getSelectables : function()
{
var $qx = qx;
var widget = $qx.core.ObjectRegistry.fromHashCode(this.qxHash);
var selectables = widget.getSelectables();
return selectables;
}
},
"qx.ui.form.SelectBox" : {
selectItem : function(itemLocator)
{
this.click();
var menu = null;
this.driver_.wait(function() {
try {
//TODO: Make sure we've got the right popup
menu = this.findElement(webdriver.By.xpath('//div[@qxclass="qx.ui.popup.Popup"]'));
return menu !== null;
}
catch(ex) {
return false;
}
}.bind(this), 500)
.then(function() {
var item = null;
menu.findElement(itemLocator).then(function(element) {
element.click();
}, function(e) {
e.message = "Couldn't find menu child of SelectBox! " + e.message;
throw e;
});
});
}
}
};
qxwebdriver.WebDriver = {
findWidget : function(locator)
{
var driver = this;
var app = webdriver.promise.Application.getInstance();
return app.schedule("findQxWidget", function() {
var element = driver.findElement(locator);
return driver.addQxBehavior(element);
});
},
addQxBehavior : function(element)
{
var driver = this;
return driver.executeScript(qxwebdriver.util.getInterfacesByElement, element)
.then(function(iFaces) {
driver.executeScript(qxwebdriver.util.getClassHierarchy, element)
.then(function(hierarchy) {
iFaces = hierarchy.concat(iFaces);
qxwebdriver.util.addInterfaceMethods(iFaces, element);
});
// Store the widget's qx object registry id
return driver.executeScript("return qx.ui.core.Widget.getWidgetByElement(arguments[0]).toHashCode()", element)
.then(function(hash) {
element.qxHash = hash;
return element;
});
});
},
waitForQxApplication : function(timeout)
{
var driver = this;
return driver.wait(function() {
var ready = false;
var isQxReady = function() {
try {
var $qx = qx;
return !!$qx.core.Init.getApplication();
} catch(ex) {
return false;
}
};
ready = driver.executeScript(isQxReady);
return ready;
}, timeout || 5000);
}
};
/**
* Creates new WebDriver clients with qooxdoo-specific enhancements.
* See the webdriver.Builder documentation for details.
*/
qxwebdriver.Builder = function() {
this.__builder = new webdriver.Builder();
};
qxwebdriver.Builder.prototype.usingServer = function(url) {
this.__builder.serverUrl_ = url;
return this;
};
qxwebdriver.Builder.prototype.usingSession = function(id) {
this.__builder.sessionId_ = id;
return this;
};
qxwebdriver.Builder.prototype.withCapabilities = function(capabilities) {
this.__builder.capabilities_ = capabilities;
return this;
};
/**
* Builds a new webdriver.WebDriver instance using this builder's
* current configuration and adds qooxdoo-specific methods.
* @return {webdriver.WebDriver} A new WebDriver client.
*/
qxwebdriver.Builder.prototype.build = function() {
var driver = this.__builder.build();
for (var methodName in qxwebdriver.WebDriver) {
driver[methodName] = qxwebdriver.WebDriver[methodName].bind(driver);
}
return driver;
};
// expose global object for in-browser testing
if (typeof require == "undefined") {
window.qxwebdriver = qxwebdriver;
}
else {
exports.Builder = qxwebdriver.Builder;
}
})();