|
| 1 | +import path from 'path'; |
| 2 | +import { $ } from '@wdio/globals'; |
| 3 | + |
| 4 | +export class Navbar { |
| 5 | + |
| 6 | + public async takeScreenshot() { |
| 7 | + const timestamp = new Date().toLocaleString('iso', { |
| 8 | + year: 'numeric', |
| 9 | + month: '2-digit', |
| 10 | + day: '2-digit', |
| 11 | + hour: '2-digit', |
| 12 | + minute: '2-digit', |
| 13 | + hour12: false |
| 14 | + }).replace(/[ ]/g, '--').replace(':', '-'); |
| 15 | + |
| 16 | + // get current test title and clean it, to use it as file name |
| 17 | + const filename = encodeURIComponent( |
| 18 | + `chrome-${timestamp}`.replace(/[/]/g, '__') |
| 19 | + ).replace(/%../, '.'); |
| 20 | + |
| 21 | + const filePath = path.resolve('./', `${filename}.png`); |
| 22 | + |
| 23 | + console.log('Saving screenshot to:', filePath); |
| 24 | + await browser.saveScreenshot(filePath); |
| 25 | + console.log('Saved screenshot to:', filePath); |
| 26 | + } |
| 27 | + |
| 28 | + public async header() { |
| 29 | + const ele = await $(`#header`); |
| 30 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 31 | + // ele.waitForClickable({timeout: 40000}); |
| 32 | + return ele; |
| 33 | + } |
| 34 | + |
| 35 | + public async applicationSettingsBtn(): Promise<WebdriverIO.Element> { |
| 36 | + const ele = await $(`#application-settings`); |
| 37 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 38 | + return ele; |
| 39 | + } |
| 40 | + |
| 41 | + public async signOutDropdown(): Promise<WebdriverIO.Element> { |
| 42 | + const ele = await $(`#sign-out-dropdown`); |
| 43 | + // await ele.waitForDisplayed({ timeout: 40000 }); |
| 44 | + // await ele.waitForClickable({ timeout: 40000 }); |
| 45 | + return ele; |
| 46 | + } |
| 47 | + |
| 48 | + public async advancedBtn(): Promise<WebdriverIO.Element> { |
| 49 | + const ele = await $(`#advanced`); |
| 50 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 51 | + await ele.waitForClickable({ timeout: 40000 }); |
| 52 | + return ele; |
| 53 | + } |
| 54 | + |
| 55 | + public async logoutBtn(): Promise<WebdriverIO.Element> { |
| 56 | + const ele = await $(`#sign-out`); |
| 57 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 58 | + await ele.waitForClickable({ timeout: 40000 }); |
| 59 | + return ele; |
| 60 | + } |
| 61 | + |
| 62 | + public async settingsBtn(): Promise<WebdriverIO.Element> { |
| 63 | + const ele = await $(`#settings`); |
| 64 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 65 | + // ele.waitForClickable({timeout: 40000}); |
| 66 | + return ele; |
| 67 | + } |
| 68 | + |
| 69 | + public async changePasswordBtn(): Promise<WebdriverIO.Element> { |
| 70 | + const ele = await $(`#change-password`); |
| 71 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 72 | + // ele.waitForClickable({timeout: 40000}); |
| 73 | + return ele; |
| 74 | + } |
| 75 | + |
| 76 | + public async userAdministrationBtn(): Promise<WebdriverIO.Element> { |
| 77 | + const ele = await $(`#user-management-menu`); |
| 78 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 79 | + await ele.waitForClickable({ timeout: 40000 }); |
| 80 | + return ele; |
| 81 | + } |
| 82 | + |
| 83 | + public async workersBtn(): Promise<WebdriverIO.Element> { |
| 84 | + const ele = await $(`#workers`); |
| 85 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 86 | + // ele.waitForClickable({timeout: 40000}); |
| 87 | + return ele; |
| 88 | + } |
| 89 | + |
| 90 | + public async sitesBtn(): Promise<WebdriverIO.Element> { |
| 91 | + const ele = await $(`#sites`); |
| 92 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 93 | + // ele.waitForClickable({timeout: 40000}); |
| 94 | + return ele; |
| 95 | + } |
| 96 | + |
| 97 | + public async foldersBtn(): Promise<WebdriverIO.Element> { |
| 98 | + const ele = await $(`#folders`); |
| 99 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 100 | + // ele.waitForClickable({timeout: 40000}); |
| 101 | + return ele; |
| 102 | + } |
| 103 | + |
| 104 | + public async pluginsBtn(): Promise<WebdriverIO.Element> { |
| 105 | + const ele = await $(`#plugins-settings`); |
| 106 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 107 | + // ele.waitForClickable({timeout: 40000}); |
| 108 | + return ele; |
| 109 | + } |
| 110 | + |
| 111 | + public async menuEditorBtn(): Promise<WebdriverIO.Element> { |
| 112 | + const ele = await $(`#menu-editor`); |
| 113 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 114 | + // ele.waitForClickable({timeout: 40000}); |
| 115 | + return ele; |
| 116 | + } |
| 117 | + |
| 118 | + public async securityBtn(): Promise<WebdriverIO.Element> { |
| 119 | + const ele = await $(`#security`); |
| 120 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 121 | + // ele.waitForClickable({timeout: 40000}); |
| 122 | + return ele; |
| 123 | + } |
| 124 | + |
| 125 | + public async deviceUsersBtn(): Promise<WebdriverIO.Element> { |
| 126 | + const ele = await $(`#device-users`); |
| 127 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 128 | + return ele; |
| 129 | + } |
| 130 | + |
| 131 | + public async entitySearchBtn(): Promise<WebdriverIO.Element> { |
| 132 | + const ele = await $(`#search`); |
| 133 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 134 | + return ele; |
| 135 | + } |
| 136 | + |
| 137 | + public async entitySelectBtn(): Promise<WebdriverIO.Element> { |
| 138 | + const ele = await $(`#selectable-list`); |
| 139 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 140 | + return ele; |
| 141 | + } |
| 142 | + |
| 143 | + public async myEformsBtn(): Promise<WebdriverIO.Element> { |
| 144 | + const ele = await $(`#my-eforms`); |
| 145 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 146 | + await ele.waitForClickable({ timeout: 40000 }); |
| 147 | + return ele; |
| 148 | + } |
| 149 | + |
| 150 | + public async clickOnSubMenuItem(menuItem) { |
| 151 | + const ele = await $( |
| 152 | + `//*[contains(@class, 'fadeInDropdown')]//*[contains(text(), '${menuItem}')]` |
| 153 | + ); |
| 154 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 155 | + ele.click(); |
| 156 | + } |
| 157 | + |
| 158 | + public async advancedDropdownClick() { |
| 159 | + await (await this.advancedBtn()).waitForDisplayed({ timeout: 60000 }); |
| 160 | + await (await this.advancedBtn()).click(); |
| 161 | + await browser.pause(500); |
| 162 | + } |
| 163 | + |
| 164 | + public async clickOnHeaderMenuItem(headerMenuItem) { |
| 165 | + return $(`//*[@id="header"]//*[text()="${headerMenuItem}"]`) |
| 166 | + .$('..') |
| 167 | + .$('..'); |
| 168 | + } |
| 169 | + |
| 170 | + public async verifyHeaderMenuItem(headerMenuItem) { |
| 171 | + return $( |
| 172 | + `//*[@id="header"]//*[contains(text(), '${headerMenuItem}')]` |
| 173 | + ).getText(); |
| 174 | + } |
| 175 | + |
| 176 | + public async clickOnHeaderMenuItem2(headerMenuItem) { |
| 177 | + const ele = await $( |
| 178 | + `//*[mat-tree-node]//*[contains(text(), '${headerMenuItem}')]` |
| 179 | + //`//*[@id="header"]//*[contains(text(), '${headerMenuItem}')]` |
| 180 | + ); |
| 181 | + await ele.waitForDisplayed({ timeout: 40000 }); |
| 182 | + await ele.waitForClickable({ timeout: 40000 }); |
| 183 | + return ele; |
| 184 | + } |
| 185 | + |
| 186 | + public async logout() { |
| 187 | + await (await this.signOutDropdown()).click(); |
| 188 | + await browser.pause(500); |
| 189 | + await (await this.logoutBtn()).click(); |
| 190 | + await browser.pause(500); |
| 191 | + } |
| 192 | + |
| 193 | + public async goToProfileSettings() { |
| 194 | + await (await this.signOutDropdown()).click(); |
| 195 | + await (await this.settingsBtn()).waitForDisplayed({ timeout: 5000 }); |
| 196 | + await (await this.settingsBtn()).waitForClickable({ timeout: 5000 }); |
| 197 | + await browser.pause(500); |
| 198 | + await (await this.settingsBtn()).click(); |
| 199 | + await browser.pause(500); |
| 200 | + } |
| 201 | + |
| 202 | + public async goToApplicationSettings() { |
| 203 | + if (!await $(`#application-settings`).isDisplayed()) { |
| 204 | + await this.advancedDropdownClick(); |
| 205 | + } |
| 206 | + await (await this.applicationSettingsBtn()).click(); |
| 207 | + await browser.pause(500); |
| 208 | + } |
| 209 | + |
| 210 | + public async goToWorkers() { |
| 211 | + await this.advancedDropdownClick(); |
| 212 | + await (await this.workersBtn()).click(); |
| 213 | + await browser.pause(500); |
| 214 | + } |
| 215 | + |
| 216 | + public async goToSites() { |
| 217 | + await this.advancedDropdownClick(); |
| 218 | + await (await this.sitesBtn()).click(); |
| 219 | + // browser.pause(15000); |
| 220 | + await browser.pause(500); |
| 221 | + } |
| 222 | + |
| 223 | + public async goToUserAdministration() { |
| 224 | + await (await this.signOutDropdown()).click(); |
| 225 | + await (await this.userAdministrationBtn()).waitForDisplayed({ timeout: 5000 }); |
| 226 | + await (await this.userAdministrationBtn()).waitForClickable({ timeout: 5000 }); |
| 227 | + await (await this.userAdministrationBtn()).click(); |
| 228 | + await browser.pause(500); |
| 229 | + } |
| 230 | + |
| 231 | + public async goToPasswordSettings() { |
| 232 | + await (await this.signOutDropdown()).click(); |
| 233 | + await (await this.changePasswordBtn()).click(); |
| 234 | + await browser.pause(500); |
| 235 | + } |
| 236 | + |
| 237 | + public async goToDeviceUsersPage() { |
| 238 | + await (await this.deviceUsersBtn()).click(); |
| 239 | + await browser.pause(500); |
| 240 | + } |
| 241 | + |
| 242 | + public async goToEntitySelect() { |
| 243 | + await this.advancedDropdownClick(); |
| 244 | + await (await this.entitySelectBtn()).click(); |
| 245 | + await this.waitForSpinnerHide(); |
| 246 | + await browser.pause(500); |
| 247 | + } |
| 248 | + |
| 249 | + public async goToEntitySearch() { |
| 250 | + await this.advancedDropdownClick(); |
| 251 | + await (await this.entitySearchBtn()).click(); |
| 252 | + await browser.pause(500); |
| 253 | + } |
| 254 | + |
| 255 | + public async goToFolderPage() { |
| 256 | + if (await (await $(`#folders`)).isDisplayed()) { |
| 257 | + await (await this.foldersBtn()).click(); |
| 258 | + await browser.pause(500); |
| 259 | + } else { |
| 260 | + await this.advancedDropdownClick(); |
| 261 | + await (await this.foldersBtn()).waitForDisplayed({ timeout: 40000 }); |
| 262 | + await (await this.foldersBtn()).waitForClickable({ timeout: 40000 }); |
| 263 | + await (await this.foldersBtn()).click(); |
| 264 | + await browser.pause(500); |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + public async goToPluginsPage() { |
| 269 | + await this.advancedDropdownClick(); |
| 270 | + await (await this.pluginsBtn()).click(); |
| 271 | + // browser.pause(15000); |
| 272 | + } |
| 273 | + |
| 274 | + public async goToMenuEditorPage() { |
| 275 | + await (await this.signOutDropdown()).click(); |
| 276 | + await (await this.menuEditorBtn()).click(); |
| 277 | + } |
| 278 | + |
| 279 | + public async goToMyEForms() { |
| 280 | + await (await this.myEformsBtn()).click(); |
| 281 | + } |
| 282 | + |
| 283 | + public async goToSecurity() { |
| 284 | + await (await this.signOutDropdown()).click(); |
| 285 | + await (await this.securityBtn()).click(); |
| 286 | + } |
| 287 | + |
| 288 | + public async spinnerAnimation() { |
| 289 | + return $('#spinner-animation'); |
| 290 | + } |
| 291 | + |
| 292 | + public async waitForSpinnerHide(timeout: number = 90000) { |
| 293 | + |
| 294 | + // do a while loop to wait for the spinner to hide for the given timeout |
| 295 | + let i = 1000; |
| 296 | + // while (i <= timeout) { |
| 297 | + // if (await (await this.spinnerAnimation()).isDisplayed()) { |
| 298 | + // await browser.pause(1000); |
| 299 | + // i += 1000; |
| 300 | + // } else { |
| 301 | + // break; |
| 302 | + // } |
| 303 | + // } |
| 304 | + |
| 305 | + // TODO: This is not working as expected, probably because of this bug https://github.com/webdriverio/webdriverio/issues/13253 |
| 306 | + //await (await this.spinnerAnimation()).waitForDisplayed({timeout: timeout, reverse: true}); |
| 307 | + } |
| 308 | +} |
0 commit comments