forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectronWebDriver.js
293 lines (255 loc) · 9.4 KB
/
spectronWebDriver.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
const { Builder, By, Key, until, Actions } = require('selenium-webdriver')
require('selenium-webdriver/chrome');
require('chromedriver');
const Utils = require('./spectronUtils');
var assert = require('assert');
const ui = require('./spectronInterfaces.js');
const specconst = require('./spectronConstants.js');
let TIMEOUT_WAIT_ELEMENT = parseInt(specconst.TIMEOUT_WAIT_ELEMENT, 10);
let TIMEOUT_PAGE_LOAD = parseInt(specconst.TIMEOUT_PAGE_LOAD, 10);
class WebDriver {
constructor(options) {
this.options = options;
this.d = new Builder().forBrowser(options.browser).build();
this.initDriver();
}
async waitElelmentIsNotVisible(xpath) {
let result = false;
try {
const el = await this.driver.wait(
until.elementLocated(By.xpath(xpath)),
TIMEOUT_WAIT_ELEMENT
)
await this.driver.wait(until.elementIsNotVisible(el), TIMEOUT_WAIT_ELEMENT);
if (this.driver.findElements(By.xpath(xpath)).length > 0) {
result = true;
}
else {
result = false;
}
return await assert.equal(result, false);
}
catch (err) {
await assert.equal(result, false);
}
}
async waitElelmentIsVisible(xpath, timeout) {
const el = await this.driver.wait(
until.elementLocated(By.xpath(xpath)),
timeout
)
await this.driver.wait(until.elementIsVisible(el), timeout);
}
async waitElementVisibleAndGet(xpath) {
const el = await this.driver.wait(
until.elementLocated(By.xpath(xpath)),
TIMEOUT_WAIT_ELEMENT
)
return await this.driver.wait(until.elementIsVisible(el), TIMEOUT_WAIT_ELEMENT)
}
async getElementById(id) {
const el = await this.driver.wait(until.elementLocated(By.id(id)), TIMEOUT_WAIT_ELEMENT)
return await this.driver.wait(until.elementIsVisible(el), TIMEOUT_WAIT_ELEMENT)
}
async getElementByXPath(xpath) {
const el = await this.driver.wait(
until.elementLocated(By.xpath(xpath)),
TIMEOUT_WAIT_ELEMENT
)
return await this.driver.wait(until.elementIsVisible(el), TIMEOUT_WAIT_ELEMENT)
}
async inputText(el, data) {
var obj = await this.getElementByXPath(el);
await obj.sendKeys(data);
}
async sendEnter(el) {
var obj = await this.getElementByXPath(el);
await obj.sendKeys(Key.ENTER);
}
async sendMessage(message) {
await this.inputText(ui.CHAT_INPUT_TYPING, message);
await this.sendEnter(ui.CHAT_INPUT_TYPING);
}
async sendMessages(messages) {
for (var i = 0; i < messages.length; i++) {
await this.sendMessage(messages[i]);
await this.sleep(1);
}
}
async login(user) {
await this.inputText(ui.SIGN_IN_EMAIL, user.username);
await this.inputText(ui.SIGN_IN_PASSWORD, user.password);
var singin = await this.getElementByXPath(ui.SIGN_IN_BUTTON);
await singin.click();
await this.waitElelmentIsVisible(ui.SETTTING_BUTTON, TIMEOUT_PAGE_LOAD);
}
async mentionUserOnChat(user) {
await this.inputText(ui.CHAT_INPUT_TYPING, "@" + user.name);
var suggestion = ui.MENTION_USER_SUGGESTION.replace("$$", user.name);
var el = await this.getElementByXPath(suggestion);
await el.click();
await this.sendEnter(ui.CHAT_INPUT_TYPING);
}
async waitSuggestionShowOnlyOneItem(xpath) {
if (this.driver.findElements(By.xpath(xpath)).length == 1) {
return result = true;
}
return false;
}
async clickShowConversationCreationModal() {
var plusButton = await this.getElementByXPath(ui.PLUS_BTN);
await plusButton.click();
}
async selectIMTab() {
var imTab = await this.getElementByXPath(ui.IM_TAB);
await imTab.click();
}
async selectRoomTab() {
var roomTab = await this.getElementByXPath(ui.CHATROOM_TAB);
await roomTab.click();
}
async addParticipant(username) {
await this.inputText(ui.ADD_PARTICIPANT_TEXT, username);
await this.sleep(5);
var el = await this.waitElementVisibleAndGet(ui.USERS_SUGGESTION_LIST);
await el.click();
}
async clickDoneButton() {
var el = await this.getElementByXPath(ui.CREATE_IM_DONE_BTN);
await el.click();
await this.waitElelmentIsNotVisible(ui.CREATE_IM_DONE_BTN);
}
async clickConfirmCreateRoom() {
var el = await this.getElementByXPath(ui.CONFIRM_CREATE_ROOM_BUTTON);
await el.click();
await this.waitElelmentIsNotVisible(ui.CONFIRM_CREATE_ROOM_BUTTON);
}
async clickStartChat() {
var el = await this.getElementByXPath(ui.START_CHAT);
await el.click();
}
async createIM(username) {
await this.clickShowConversationCreationModal();
await this.clickStartChat();
await this.selectIMTab();
await this.addParticipant(username);
await this.clickDoneButton();
}
async createMIM(usernames) {
await this.clickShowConversationCreationModal();
await this.clickStartChat();
await this.selectIMTab();
for (var i = 0; i < usernames.length; i++) {
await this.addParticipant(usernames[i]);
}
await this.clickDoneButton();
}
async clickCreateSignal() {
var el = await this.getElementByXPath(ui.SIGNAL_OPTION);
await el.click();
}
async selectPublicRadioButton() {
var el = await this.waitElementVisibleAndGet(ui.PUBLIC_ROOM_RADIO_BTN);
await el.click();
}
async selectPrivateRadioButton() {
var el = await this.waitElementVisibleAndGet(ui.PRIVATE_ROOM_RADIO_BTN);
await el.click();
}
async clickLeftNavItem(name) {
var xpath = await ui.LEFT_NAV_SINGLE_ITEM.replace("$$", name);
var el = await this.getElementByXPath(xpath);
await el.click();
var eheader = await this.getElementByXPath(ui.HEADER_MODULE);
await this.driver.wait(until.elementIsVisible(eheader), TIMEOUT_WAIT_ELEMENT)
}
async createRoom(usernames, name, description, type) {
await this.clickShowConversationCreationModal();
await this.clickStartChat();
await this.selectRoomTab();
await this.inputText(ui.CHATROOM_NAME_TEXT, name);
await this.inputText(ui.CHATROOM_DESCR_TEXT, description);
if (type === specconst.TYPE_ROOM.private) {
await this.selectPrivateRadioButton();
}
if (type === specconst.TYPE_ROOM.public) {
await this.selectPublicRadioButton();
}
for (var i = 0; i < usernames.length; i++) {
await this.addParticipant(usernames[i]);
}
await this.clickDoneButton();
// await this.clickConfirmCreateRoom();
}
async createSignal(signalName, hashTag) {
await this.clickShowConversationCreationModal();
await this.clickCreateSignal();
await this.inputText(ui.SIGNAL_NAME, signalName);
await this.inputText(ui.LAST_RULE_ROW + ui.ENTER_KEYWORD_IN_LAST_INPUT, hashTag);
await this.clickDoneButton();
}
async initDriver() {
return this.d.then(_d => {
this.driver = _d
})
}
async startDriver() {
await this.driver
.manage()
.window()
.setPosition(0, 0);
var size = await await this.driver
.manage()
.window().getSize();
await this.driver.get(specconst.TESTED_HOST);
}
async focusCurrentBrowser() {
this.driver.switchTo().window(this.driver.getAllWindowHandles()[0]);
}
async sleep(secondSleep) {
await this.driver.sleep(secondSleep * 1000);
}
async timeOut(secondSleep) {
return secondSleep * 1000;
}
async quit() {
await this.driver.quit();
}
async close() {
await this.driver.close();
}
async sendMessagesAndVerifyToast(messages) {
for (var i = 0; i < messages.length; i++) {
await this.webActions.clickPlusButton();
await this.windowAction.pressCtrlM();
await this.sendMessage(messages[i]).then(async () => {
await this.windowAction.verifyPersistToastNotification(messages[i]);
});
}
}
async closeAllGridModules() {
let count = await this.getCount(ui.HEADER_MODULE);
for (let i = 1; i <= count; i++) {
let header = ui.HEADER_MODULES.replace("$$", 1);
let closeButton = ui.CLOSE_MODULES.replace("$$", 1);
let pinButton = ui.PIN_CHAT_MODS.replace("$$", 1);
await this.clickIfElementVisible(header);
await this.clickIfElementVisible(pinButton);
await this.clickIfElementVisible(closeButton);
}
}
async clickIfElementVisible(selector) {
let el = await this.getElementByXPath(selector);
await el.click();
}
async getCount(locator) {
let elements = await this.driver.findElements(By.xpath(locator));
return elements.length;
}
async mouseOver(locator) {
let el = await this.getElementByXPath(locator);
let builder = await new Actions(this.driver);
builder.moveToElement(el, 20, 20).click().build().perform();
}
}
module.exports = WebDriver;