How to use d.findElement method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

dialog-modal_datepicker.js

Source:dialog-modal_datepicker.js Github

copy

Full Screen

1'use strict';2const { ariaTest } = require('..');3const { By, Key } = require('selenium-webdriver');4const assertAttributeValues = require('../util/assertAttributeValues');5const assertAttributeDNE = require('../util/assertAttributeDNE');6const assertAriaLabelledby = require('../util/assertAriaLabelledby');7const assertAriaLabelExists = require('../util/assertAriaLabelExists');8const assertAriaRoles = require('../util/assertAriaRoles');9const exampleFile = 'dialog-modal/datepicker-dialog.html';10let today = new Date();11let todayDataDate = today.toISOString().split('T')[0];12const ex = {13 dialogSelector: '#example [role="dialog"]',14 inputSelector: '#example input',15 buttonSelector: '#example button.icon',16 messageSelector: '#example .dialog-message',17 controlButtons: '#example [role="dialog"] .header button',18 gridSelector: '#example [role="dialog"] table.dates',19 gridcellSelector: '#example [role="dialog"] table.dates td',20 currentMonthDateButtons: '#example table.dates td:not(.disabled)',21 allDates: '#example [role="dialog"] table.dates td',22 jan12019Day: '#example [role="dialog"] table.dates td[data-date="2019-01-01"]',23 jan22019Day: '#example [role="dialog"] table.dates td[data-date="2019-01-02"]',24 todayDay: `#example [role="dialog"] table.dates td[data-date="${todayDataDate}"]`,25 currentlyFocusedDay: '#example [role="dialog"] table.dates td[tabindex="0"]',26 allFocusableElementsInDialog: [27 `#example [role="dialog"] table.dates td[data-date="${todayDataDate}"]`,28 '#example [role="dialog"] button[value="cancel"]',29 '#example [role="dialog"] button[value="ok"]',30 '#example [role="dialog"] button.prev-year',31 '#example [role="dialog"] button.prev-month',32 '#example [role="dialog"] button.next-month',33 '#example [role="dialog"] button.next-year'34 ],35 prevMonthButton: '#example [role="dialog"] button.prev-month',36 prevYearButton: '#example [role="dialog"] button.prev-year',37 nextMonthButton: '#example [role="dialog"] button.next-month',38 nextYearButton: '#example [role="dialog"] button.next-year',39 cancelButton: '#example [role="dialog"] button[value="cancel"]',40 okButton: '#example [role="dialog"] button[value="ok"]'41};42const clickFirstOfMonth = async function (t) {43 let today = new Date();44 today.setUTCHours(0,0,0,0);45 let firstOfMonth = new Date(today);46 firstOfMonth.setDate(1);47 let firstOfMonthString = today.toISOString().split('T')[0];48 return t.context.session.findElement(By.css(`[data-date=${firstOfMonthString}]`)).click();49};50const clickToday = async function (t) {51 let today = new Date();52 today.setUTCHours(0,0,0,0);53 let todayString = today.toISOString().split('T')[0];54 return t.context.session.findElement(By.css(`[data-date=${todayString}]`)).click();55};56const setDateToJanFirst2019 = async function (t) {57 await t.context.session.findElement(By.css(ex.inputSelector)).click();58 return t.context.session.executeScript(function () {59 const inputSelector = arguments[0];60 document.querySelector(inputSelector).value = '1/1/2019';61 }, ex.inputSelector);62};63const focusMatchesElement = async function (t, selector) {64 return t.context.session.wait(async function () {65 return t.context.session.executeScript(function () {66 selector = arguments[0];67 return document.activeElement === document.querySelector(selector);68 }, selector);69 }, t.context.WaitTime);70};71// Button Tests72ariaTest('"aria-label" attribute on button', exampleFile, 'calendar-button-aria-label', async (t) => {73 await assertAriaLabelExists(t, ex.buttonSelector);74});75// Dialog Tests76ariaTest('role="dialog" attribute on div', exampleFile, 'dialog-role', async (t) => {77 await assertAriaRoles(t, 'example', 'dialog', 1, 'div');78});79ariaTest('aria-modal="true" on modal', exampleFile, 'dialog-aria-modal', async (t) => {80 await assertAttributeValues(t, ex.dialogSelector, 'aria-modal', 'true');81});82ariaTest('aria-label exist on dialog', exampleFile, 'dialog-aria-label', async (t) => {83 await assertAriaLabelExists(t, ex.dialogSelector);84});85ariaTest('aria-live="polite" on keyboard support message', exampleFile, 'dialog-aria-live', async (t) => {86 await assertAttributeValues(t, ex.messageSelector, 'aria-live', 'polite');87});88ariaTest('"aria-label" exists on control buttons', exampleFile, 'change-date-button-aria-label', async (t) => {89 await assertAriaLabelExists(t, ex.controlButtons);90});91ariaTest('aria-live="polite" on dialog header', exampleFile, 'change-date-aria-live', async (t) => {92 await assertAttributeValues(t, `${ex.dialogSelector} h2`, 'aria-live', 'polite');93});94ariaTest('grid role on table element', exampleFile, 'grid-role', async (t) => {95 await assertAriaRoles(t, 'example', 'grid', 1, 'table');96});97ariaTest('aria-labelledby on grid element', exampleFile, 'grid-aria-labelledby', async (t) => {98 await assertAriaLabelledby(t, ex.gridSelector);99});100ariaTest('Roving tab index on dates in gridcell', exampleFile, 'gridcell-button-tabindex', async (t) => {101 await setDateToJanFirst2019(t);102 await t.context.session.findElement(By.css(ex.buttonSelector)).click();103 let focusableButtons = await t.context.queryElements(t, ex.currentMonthDateButtons);104 let allButtons = await t.context.queryElements(t, ex.allDates);105 // test only one element has tabindex="0"106 for (let tabbableEl = 0; tabbableEl < 30; tabbableEl++) {107 let dateSelected = await focusableButtons[tabbableEl].getText();108 for (let el = 0; el < allButtons.length; el++) {109 let date = await allButtons[el].getText();110 let disabled = (await allButtons[el].getAttribute('class')).includes('disabled');111 let tabindex = dateSelected === date && !disabled ? '0' : '-1';112 t.is(113 await allButtons[el].getAttribute('tabindex'),114 tabindex,115 'focus is on day ' + (tabbableEl + 1) + ' therefore the button number ' +116 el + ' should have tab index set to: ' + tabindex117 );118 }119 // Send the tabindex="0" element the appropriate key to switch focus to the next element120 await focusableButtons[tabbableEl].sendKeys(Key.ARROW_RIGHT);121 }122});123ariaTest('aria-selected on selected date', exampleFile, 'gridcell-button-aria-selected', async (t) => {124 await t.context.session.findElement(By.css(ex.buttonSelector)).click();125 await assertAttributeDNE(t, ex.allDates, 'aria-selected');126 await setDateToJanFirst2019(t);127 await t.context.session.findElement(By.css(ex.buttonSelector)).click();128 await assertAttributeValues(t, ex.jan12019Day, 'aria-selected', 'true');129 let selectedButtons = await t.context.queryElements(t, `${ex.allDates}[aria-selected="true"]`);130 t.is(131 selectedButtons.length,132 1,133 'after setting date in box, only one button should have aria-selected'134 );135 await t.context.session.findElement(By.css(ex.jan22019Day)).click();136 await t.context.session.findElement(By.css(ex.buttonSelector)).click();137 await assertAttributeValues(t, ex.jan22019Day, 'aria-selected', 'true');138 selectedButtons = await t.context.queryElements(t, `${ex.allDates}[aria-selected="true"]`);139 t.is(140 selectedButtons.length,141 1,142 'after clicking a date and re-opening datepicker, only one button should have aria-selected'143 );144});145// Keyboard146ariaTest('ENTER to open datepicker', exampleFile, 'button-space-return', async (t) => {147 let chooseDateButton = await t.context.session.findElement(By.css(ex.buttonSelector));148 chooseDateButton.sendKeys(Key.ENTER);149 t.not(150 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),151 'none',152 'After sending ENTER to the "choose date" button, the calendar dialog should open'153 );154});155ariaTest('SPACE to open datepicker', exampleFile, 'button-space-return', async (t) => {156 let chooseDateButton = await t.context.session.findElement(By.css(ex.buttonSelector));157 chooseDateButton.sendKeys(' ');158 t.not(159 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),160 'none',161 'After sending SPACE to the "choose date" button, the calendar dialog should open'162 );163});164ariaTest('Sending key ESC when focus is in dialog closes dialog', exampleFile, 'dialog-esc', async (t) => {165 let chooseDateButton = await t.context.session.findElement(By.css(ex.buttonSelector));166 for (let i = 0; i < ex.allFocusableElementsInDialog.length; i++) {167 await chooseDateButton.sendKeys(Key.ENTER);168 let el = t.context.session.findElement(By.css(ex.allFocusableElementsInDialog[i]));169 await el.sendKeys(Key.ESCAPE);170 t.is(171 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),172 'none',173 'After sending ESC to element "' + ex.allFocusableElementsInDialog[i] + '" in the dialog, the calendar dialog should close'174 );175 t.is(176 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),177 '',178 'After sending ESC to element "' + ex.allFocusableElementsInDialog[i] + '" in the dialog, no date should be selected'179 );180 }181});182ariaTest('Tab should go through all tabbable items, then loop', exampleFile, 'dialog-tab', async (t) => {183 await t.context.session.findElement(By.css(ex.buttonSelector)).click();184 for (let itemSelector of ex.allFocusableElementsInDialog) {185 t.true(186 await focusMatchesElement(t, itemSelector),187 'Focus should be on: ' + itemSelector188 );189 await t.context.session.findElement(By.css(itemSelector)).sendKeys(Key.TAB);190 }191 t.true(192 await focusMatchesElement(t, ex.allFocusableElementsInDialog[0]),193 'After tabbing through all items, focus should return to: ' + ex.allFocusableElementsInDialog[0]194 );195});196ariaTest('Shift+tab should send focus backwards through dialog, then loop', exampleFile, 'dialog-shift-tab', async (t) => {197 await t.context.session.findElement(By.css(ex.buttonSelector)).click();198 await t.context.session.findElement(By.css(ex.allFocusableElementsInDialog[0]))199 .sendKeys(Key.chord(Key.SHIFT, Key.TAB));200 let lastIndex = ex.allFocusableElementsInDialog.length - 1;201 for (let i = lastIndex; i >= 0; i--) {202 t.true(203 await focusMatchesElement(t, ex.allFocusableElementsInDialog[i]),204 'Focus should be on: ' + ex.allFocusableElementsInDialog[i]205 );206 await t.context.session.findElement(By.css(ex.allFocusableElementsInDialog[i]))207 .sendKeys(Key.chord(Key.SHIFT, Key.TAB));208 }209});210ariaTest('ENTER to buttons change calendar and date in focus', exampleFile, 'month-year-button-space-return', async (t) => {211 await t.context.session.findElement(By.css(ex.buttonSelector)).click();212 // By default, focus will be on todays date.213 let day = new Date();214 // send enter to next month button215 await t.context.session.findElement(By.css(ex.nextMonthButton)).sendKeys(Key.ENTER);216 day.setMonth(day.getMonth() + 1);217 let dayInFocus = await t.context.session218 .findElement(By.css(ex.currentlyFocusedDay))219 .getAttribute('data-date');220 t.is(221 dayInFocus,222 day.toISOString().split('T')[0],223 'After selected next month button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus224 );225 // send enter to next year button226 await t.context.session.findElement(By.css(ex.nextYearButton)).sendKeys(Key.ENTER);227 day.setFullYear(day.getFullYear() + 1);228 dayInFocus = await t.context.session229 .findElement(By.css(ex.currentlyFocusedDay))230 .getAttribute('data-date');231 t.is(232 dayInFocus,233 day.toISOString().split('T')[0],234 'After selected next month button, then next year button date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus235 );236 // Send enter to previous month button237 await t.context.session.findElement(By.css(ex.prevMonthButton)).sendKeys(Key.ENTER);238 day.setMonth(day.getMonth() - 1);239 dayInFocus = await t.context.session240 .findElement(By.css(ex.currentlyFocusedDay))241 .getAttribute('data-date');242 t.is(243 dayInFocus,244 day.toISOString().split('T')[0],245 'After selected next month button, then next year button date, then previous month button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus246 );247 // Send enter to previous year button248 await t.context.session.findElement(By.css(ex.prevYearButton)).sendKeys(Key.ENTER);249 day.setFullYear(day.getFullYear() - 1);250 dayInFocus = await t.context.session251 .findElement(By.css(ex.currentlyFocusedDay))252 .getAttribute('data-date');253 t.is(254 dayInFocus,255 day.toISOString().split('T')[0],256 'After selected next month button, then next year button date, then previous month button, then previous year button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus257 );258});259ariaTest('SPACE to buttons change calendar and date in focus', exampleFile, 'month-year-button-space-return', async (t) => {260 await t.context.session.findElement(By.css(ex.buttonSelector)).click();261 // By default, focus will be on todays date.262 let day = new Date();263 // send space to next month button264 await t.context.session.findElement(By.css(ex.nextMonthButton)).sendKeys(Key.SPACE);265 day.setMonth(day.getMonth() + 1);266 let dayInFocus = await t.context.session267 .findElement(By.css(ex.currentlyFocusedDay))268 .getAttribute('data-date');269 t.is(270 dayInFocus,271 day.toISOString().split('T')[0],272 'After selected next month button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus273 );274 // send space to next year button275 await t.context.session.findElement(By.css(ex.nextYearButton)).sendKeys(Key.SPACE);276 day.setFullYear(day.getFullYear() + 1);277 dayInFocus = await t.context.session278 .findElement(By.css(ex.currentlyFocusedDay))279 .getAttribute('data-date');280 t.is(281 dayInFocus,282 day.toISOString().split('T')[0],283 'After selected next month button, then next year button date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus284 );285 // Send space to previous month button286 await t.context.session.findElement(By.css(ex.prevMonthButton)).sendKeys(Key.SPACE);287 day.setMonth(day.getMonth() - 1);288 dayInFocus = await t.context.session289 .findElement(By.css(ex.currentlyFocusedDay))290 .getAttribute('data-date');291 t.is(292 dayInFocus,293 day.toISOString().split('T')[0],294 'After selected next month button, then next year button date, then previous month button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus295 );296 // Send space to previous year button297 await t.context.session.findElement(By.css(ex.prevYearButton)).sendKeys(Key.SPACE);298 day.setFullYear(day.getFullYear() - 1);299 dayInFocus = await t.context.session300 .findElement(By.css(ex.currentlyFocusedDay))301 .getAttribute('data-date');302 t.is(303 dayInFocus,304 day.toISOString().split('T')[0],305 'After selected next month button, then next year button date, then previous month button, then previous year button, date should be ' + day.toISOString().split('T')[0] + ' but found: ' + dayInFocus306 );307});308ariaTest('SPACE or RETURN selects date in focus', exampleFile, 'grid-space-return', async (t) => {309 // By default, focus will be on todays date.310 let day = new Date();311 await t.context.session.findElement(By.css(ex.buttonSelector)).sendKeys(Key.ENTER);312 await t.context.session.findElement(By.css(ex.todayDay)).sendKeys(Key.ENTER);313 t.is(314 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),315 `${day.getMonth() + 1}/${day.getDate()}/${day.getFullYear()}`,316 'ENTER sent to today\'s date button should select date'317 );318 await t.context.session.findElement(By.css(ex.buttonSelector)).click();319 await t.context.session.findElement(By.css(ex.todayDay)).sendKeys(Key.ARROW_RIGHT);320 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(' ');321 day.setDate(day.getDate() + 1);322 t.is(323 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),324 `${day.getMonth() + 1}/${day.getDate()}/${day.getFullYear()}`,325 'SPACE sent to tomorrow\'s date button should select tomorrow'326 );327});328ariaTest('UP ARROW moves date up by week', exampleFile, 'grid-up-arrow', async (t) => {329 await t.context.session.findElement(By.css(ex.buttonSelector)).click();330 let day = new Date();331 for (let i = 1; i <= 5; i++) {332 // Send up arrow to key333 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_UP);334 day.setDate(day.getDate() - 7);335 t.is(336 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),337 day.toISOString().split('T')[0],338 'After sending ' + i + ' UP ARROWS to focused date, the focused date should be: ' + day.toISOString().split('T')[0]339 );340 }341});342ariaTest('DOWN ARROW moves date down by week', exampleFile, 'grid-down-arrow', async (t) => {343 await t.context.session.findElement(By.css(ex.buttonSelector)).click();344 let day = new Date();345 for (let i = 1; i <= 5; i++) {346 // Send up arrow to key347 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_DOWN);348 day.setDate(day.getDate() + 7);349 t.is(350 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),351 day.toISOString().split('T')[0],352 'After sending ' + i + ' DOWN ARROWS to focused date, the focused date should be: ' + day.toISOString().split('T')[0]353 );354 }355});356ariaTest('RIGHT ARROW moves date greater by one', exampleFile, 'grid-right-arrow', async (t) => {357 await t.context.session.findElement(By.css(ex.buttonSelector)).click();358 let day = new Date();359 for (let i = 1; i <= 31; i++) {360 // Send up arrow to key361 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_RIGHT);362 day.setDate(day.getDate() + 1);363 t.is(364 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),365 day.toISOString().split('T')[0],366 'After sending ' + i + ' RIGHT ARROWS to focused date, the focused date should be: ' + day.toISOString().split('T')[0]367 );368 }369});370ariaTest('LEFT ARROW moves date previous one', exampleFile, 'grid-left-arrow', async (t) => {371 await t.context.session.findElement(By.css(ex.buttonSelector)).click();372 let day = new Date();373 for (let i = 1; i <= 31; i++) {374 // Send up arrow to key375 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_LEFT);376 day.setDate(day.getDate() - 1);377 t.is(378 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),379 day.toISOString().split('T')[0],380 'After sending ' + i + ' LEFT ARROWS to focused date, the focused date should be: ' + day.toISOString().split('T')[0]381 );382 }383});384ariaTest('Key HOME sends focus to beginning of row', exampleFile, 'grid-home', async (t) => {385 await t.context.session.findElement(By.css(ex.buttonSelector)).click();386 let day = new Date();387 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.HOME);388 day.setDate(day.getDate() - day.getDay()); // getDay returns day of week389 t.is(390 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),391 day.toISOString().split('T')[0],392 'Sending HOME should move focus to Sunday: ' + day.toISOString().split('T')[0]393 );394 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.HOME);395 t.is(396 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),397 day.toISOString().split('T')[0],398 'Sending HOME to Sunday should not move focus from:' + day.toISOString().split('T')[0]399 );400});401ariaTest('Key END sends focus to end of row', exampleFile, 'grid-end', async (t) => {402 await t.context.session.findElement(By.css(ex.buttonSelector)).click();403 let day = new Date();404 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.END);405 day.setDate(day.getDate() + (6 - day.getDay())); // getDay returns day of week406 t.is(407 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),408 day.toISOString().split('T')[0],409 'Sending END should move focus to Saturday: ' + day.toISOString().split('T')[0]410 );411 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.END);412 t.is(413 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),414 day.toISOString().split('T')[0],415 'Sending END to Saturday should not move focus from:' + day.toISOString().split('T')[0]416 );417});418ariaTest('Sending PAGE UP moves focus by back month', exampleFile, 'grid-pageup', async (t) => {419 await t.context.session.findElement(By.css(ex.buttonSelector)).click();420 let day = new Date();421 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.PAGE_UP);422 day.setMonth(day.getMonth() - 1);423 t.is(424 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),425 day.toISOString().split('T')[0],426 'Sending PAGE UP should move focus back by month: ' + day.toISOString().split('T')[0]427 );428 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.PAGE_UP);429 day.setMonth(day.getMonth() - 1);430 t.is(431 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),432 day.toISOString().split('T')[0],433 'Sending PAGE UP should move focus back by month, again:' + day.toISOString().split('T')[0]434 );435});436ariaTest('Sending SHIFT+PAGE UP moves focus back by year', exampleFile, 'grid-shift-pageup', async (t) => {437 await t.context.session.findElement(By.css(ex.buttonSelector)).click();438 let day = new Date();439 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.chord(Key.SHIFT, Key.PAGE_UP));440 day.setFullYear(day.getFullYear() - 1);441 t.is(442 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),443 day.toISOString().split('T')[0],444 'Sending SHIFT+PAGE UP should move focus back by year: ' + day.toISOString().split('T')[0]445 );446 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.chord(Key.SHIFT, Key.PAGE_UP));447 day.setFullYear(day.getFullYear() - 1);448 t.is(449 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),450 day.toISOString().split('T')[0],451 'Sending SHIFT+PAGE UP should move focus back by year, again:' + day.toISOString().split('T')[0]452 );453});454ariaTest('Sending PAGE DOWN moves focus back by month', exampleFile, 'grid-pagedown', async (t) => {455 await t.context.session.findElement(By.css(ex.buttonSelector)).click();456 let day = new Date();457 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.PAGE_DOWN);458 day.setMonth(day.getMonth() + 1);459 t.is(460 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),461 day.toISOString().split('T')[0],462 'Sending PAGE UP should move focus forward by month: ' + day.toISOString().split('T')[0]463 );464 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.PAGE_DOWN);465 day.setMonth(day.getMonth() + 1);466 t.is(467 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),468 day.toISOString().split('T')[0],469 'Sending PAGE UP should move focus forward by month, again:' + day.toISOString().split('T')[0]470 );471});472ariaTest('Sending SHIFT+PAGE DOWN moves focus back by year', exampleFile, 'grid-shift-pagedown', async (t) => {473 await t.context.session.findElement(By.css(ex.buttonSelector)).click();474 let day = new Date();475 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.chord(Key.SHIFT, Key.PAGE_DOWN));476 day.setFullYear(day.getFullYear() + 1);477 t.is(478 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),479 day.toISOString().split('T')[0],480 'Sending SHIFT+PAGE UP should move focus forward by year: ' + day.toISOString().split('T')[0]481 );482 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.chord(Key.SHIFT, Key.PAGE_DOWN));483 day.setFullYear(day.getFullYear() + 1);484 t.is(485 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).getAttribute('data-date'),486 day.toISOString().split('T')[0],487 'Sending SHIFT+PAGE UP should move focus forward by year, again:' + day.toISOString().split('T')[0]488 );489});490ariaTest('ENTER on cancel button does not select date', exampleFile, 'okay-cancel-button-space-return', async (t) => {491 await t.context.session.findElement(By.css(ex.buttonSelector)).click();492 await t.context.session.findElement(By.css(ex.cancelButton)).sendKeys(Key.ENTER);493 t.is(494 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),495 '',496 'ENTER sent to cancel should not set a date'497 );498 t.is(499 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),500 'none',501 'After sending ENDER to the "cancel" button, the calendar dialog should close'502 );503 await setDateToJanFirst2019(t);504 await t.context.session.findElement(By.css(ex.buttonSelector)).click();505 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_RIGHT);506 await t.context.session.findElement(By.css(ex.cancelButton)).sendKeys(Key.ENTER);507 t.is(508 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),509 '1/1/2019',510 'ENTER send to cancel should not change date'511 );512 t.is(513 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),514 'none',515 'After sending ENTER to the "cancel" button, the calendar dialog should close'516 );517});518ariaTest('SPACE on cancel button does not select date', exampleFile, 'okay-cancel-button-space-return', async (t) => {519 await t.context.session.findElement(By.css(ex.buttonSelector)).click();520 await t.context.session.findElement(By.css(ex.cancelButton)).sendKeys(Key.SPACE);521 t.is(522 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),523 '',524 'SPACE sent to cancel should not set a date'525 );526 t.is(527 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),528 'none',529 'After sending SPACE to the "cancel" button, the calendar dialog should close'530 );531 await setDateToJanFirst2019(t);532 await t.context.session.findElement(By.css(ex.buttonSelector)).click();533 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_RIGHT);534 await t.context.session.findElement(By.css(ex.cancelButton)).sendKeys(Key.SPACE);535 t.is(536 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),537 '1/1/2019',538 'SPACE send to cancel should not change date'539 );540 t.is(541 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),542 'none',543 'After sending SPACE to the "cancel" button, the calendar dialog should close'544 );545});546ariaTest('ENTER on ok button does selects date', exampleFile, 'okay-cancel-button-space-return', async (t) => {547 let day = new Date();548 await t.context.session.findElement(By.css(ex.buttonSelector)).click();549 await t.context.session.findElement(By.css(ex.okButton)).sendKeys(Key.ENTER);550 t.is(551 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),552 `${day.getMonth() + 1}/${day.getDate()}/${day.getFullYear()}`,553 'ENTER sent to ok button should set a date'554 );555 t.is(556 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),557 'none',558 'After sending ENTER to the "ok" button, the calendar dialog should close'559 );560 await setDateToJanFirst2019(t);561 await t.context.session.findElement(By.css(ex.buttonSelector)).click();562 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_RIGHT);563 await t.context.session.findElement(By.css(ex.okButton)).sendKeys(Key.ENTER);564 t.is(565 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),566 '1/2/2019',567 'ENTER send to ok should not change date to Jan 2nd'568 );569 t.is(570 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),571 'none',572 'After sending ENTER to the "cancel" button, the calendar dialog should close'573 );574});575ariaTest('SPACE on ok button does selects date', exampleFile, 'okay-cancel-button-space-return', async (t) => {576 let day = new Date();577 await t.context.session.findElement(By.css(ex.buttonSelector)).click();578 await t.context.session.findElement(By.css(ex.okButton)).sendKeys(Key.SPACE);579 t.is(580 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),581 `${day.getMonth() + 1}/${day.getDate()}/${day.getFullYear()}`,582 'SPACE sent to ok button should set a date'583 );584 t.is(585 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),586 'none',587 'After sending SPACE to the "ok" button, the calendar dialog should close'588 );589 await setDateToJanFirst2019(t);590 await t.context.session.findElement(By.css(ex.buttonSelector)).click();591 await t.context.session.findElement(By.css(ex.currentlyFocusedDay)).sendKeys(Key.ARROW_RIGHT);592 await t.context.session.findElement(By.css(ex.okButton)).sendKeys(Key.SPACE);593 t.is(594 await t.context.session.findElement(By.css(ex.inputSelector)).getAttribute('value'),595 '1/2/2019',596 'SPACE send to ok should not change date to Jan 2nd'597 );598 t.is(599 await t.context.session.findElement(By.css(ex.dialogSelector)).getCssValue('display'),600 'none',601 'After sending SPACE to the "cancel" button, the calendar dialog should close'602 );...

Full Screen

Full Screen

e2e.test.js

Source:e2e.test.js Github

copy

Full Screen

1const CryptoJS = require('crypto-js');2const { By, logging } = require('selenium-webdriver');3const { setupBrowser } = require('./setup');4const {5 STORE_KEY_VAULT,6} = require('../../src/scripts/enums');7/**8 * Plugin account password9 * @type {string}10 */11const password = 'asdf';12/**13 * Secret key14 * @type {string}15 */16const secretKey = 'FF767FC8FAF9CFA8D2C3BD193663E8B8CAC85005AD56E085FAB179B52BD88DD6';17/**18 * Public key19 * @type {string}20 */21const publicKey = 'D69BCCF69C2D0F6CED025A05FA7F3BA687D1603AC1C8D9752209AC2BBF2C4D17';22/**23 * Signature of empty string created with secret key24 * @type {string}25 */26const signature = '7A1CA8AF3246222C2E06D2ADE525A693FD81A2683B8A8788C32B7763DF6037A5'27 + 'DF3105B92FEF398AF1CDE0B92F18FE68DEF301E4BF7DB0ABC0AEA6BE24969006';28/**29 * Selenium WebDriver30 */31let driver;32/**33 * Popup page URI34 */35let popupUri;36/**37 * Returns data from store.38 *39 * @param key40 * @returns {Promise<void>}41 */42async function getStoreDataByKey(key) {43 return (await driver.executeAsyncScript(`chrome.storage.local.get('${key}', arguments[arguments.length - 1]);`))[key];44}45/**46 * Returns data from store.47 *48 * @param key49 * @param pass50 * @returns {Promise<void>}51 */52async function getEncryptedStoreDataByKey(key, pass) {53 const encrypted = (await driver.executeAsyncScript(`chrome.storage.local.get('${key}', arguments[arguments.length - 1]);`))[key];54 let decrypted;55 if (encrypted) {56 decrypted = CryptoJS.AES.decrypt(encrypted, pass)57 .toString(CryptoJS.enc.Utf8);58 } else {59 decrypted = encrypted;60 }61 return decrypted;62}63/**64 * Saves data to store.65 *66 * @param key67 * @param data68 * @param pass69 * @returns {Promise<void>}70 */71async function setEncryptedStoreDataByKey(key, data, pass) {72 const encrypted = CryptoJS.AES.encrypt(JSON.stringify(data), pass)73 .toString();74 const dataObject = {};75 dataObject[key] = encrypted;76 const dataString = JSON.stringify(dataObject);77 const script = `chrome.storage.local.set(${dataString}, arguments[arguments.length - 1]);`;78 return driver.executeAsyncScript(script);79}80/**81 * Clears store.82 *83 * @returns {Promise}84 */85async function clearStore() {86 return driver.executeAsyncScript('chrome.storage.local.clear( arguments[arguments.length - 1]);');87}88async function getPendingTxCount() {89 const txElementArray = await driver.findElements(By.css('#tx-pending > div'));90 return txElementArray.length;91}92async function isElementDisplayed(pageId) {93 return driver.findElement(By.id(pageId))94 .isDisplayed();95}96async function isPageCreateAccount() {97 return isElementDisplayed('create-acc-page');98}99async function isPageLogin() {100 return isElementDisplayed('login-page');101}102async function isPageUser() {103 return isElementDisplayed('user-page');104}105async function isTabTransactions() {106 return isElementDisplayed('tab-tx');107}108async function isTabSettings() {109 return isElementDisplayed('tab-settings');110}111describe('create account', () => {112 beforeAll(async () => {113 ({114 driver,115 popupUri,116 } = await setupBrowser());117 });118 beforeEach(async () => {119 // open popup120 await driver.get(popupUri);121 expect(await isPageCreateAccount())122 .toBeTruthy();123 });124 afterEach(async () => {125 await clearStore();126 });127 afterAll(async () => {128 await driver.quit();129 });130 test('create account and login', async () => {131 expect.assertions(4);132 // input password for new account133 await driver.findElement(By.id('password-new'))134 .sendKeys(password);135 await driver.findElement(By.id('password-new-confirm'))136 .sendKeys(password);137 // create account button138 await driver.findElement(By.id('btn-create-acc'))139 .click();140 // check if account was created141 const decrypted = await getEncryptedStoreDataByKey(STORE_KEY_VAULT, password);142 expect(decrypted)143 .toBe('{}');144 expect(await isPageUser())145 .toBeTruthy();146 // default tab is tx tab147 expect(await isTabTransactions())148 .toBeTruthy();149 });150 test('create account with invalid password', async () => {151 expect.assertions(4);152 const invalidPassword = '';153 // input password for new account154 await driver.findElement(By.id('password-new'))155 .sendKeys(invalidPassword);156 await driver.findElement(By.id('password-new-confirm'))157 .sendKeys(invalidPassword);158 // create account button159 await driver.findElement(By.id('btn-create-acc'))160 .click();161 // check if account was created162 expect(await getStoreDataByKey(STORE_KEY_VAULT))163 .toBeUndefined();164 expect(await isPageUser())165 .toBeFalsy();166 // default tab is tx tab167 expect(await isTabTransactions())168 .toBeFalsy();169 });170 test('create account with not matching passwords', async () => {171 expect.assertions(4);172 // input password for new account173 await driver.findElement(By.id('password-new'))174 .sendKeys('asdfasdfasdf1');175 await driver.findElement(By.id('password-new-confirm'))176 .sendKeys('asdfasdfasdf2');177 // create account button178 await driver.findElement(By.id('btn-create-acc'))179 .click();180 // check if account was created181 expect(await getStoreDataByKey(STORE_KEY_VAULT))182 .toBeUndefined();183 expect(await isPageUser())184 .toBeFalsy();185 // default tab is tx tab186 expect(await isTabTransactions())187 .toBeFalsy();188 });189});190describe('log in', () => {191 beforeAll(async () => {192 ({193 driver,194 popupUri,195 } = await setupBrowser());196 // create account197 await driver.get(popupUri);198 const data = {};199 await setEncryptedStoreDataByKey(STORE_KEY_VAULT, data, password);200 });201 beforeEach(async () => {202 // open popup203 await driver.get(popupUri);204 expect(await isPageLogin())205 .toBeTruthy();206 });207 afterAll(async () => {208 await driver.quit();209 });210 test('log in with valid credentials, then logout', async () => {211 expect.assertions(5);212 /**213 * Login214 */215 // input password216 await driver.findElement(By.id('password'))217 .sendKeys(password);218 // log in button219 await driver.findElement(By.id('btn-login'))220 .click();221 expect(await isPageUser())222 .toBeTruthy();223 /**224 * Logout225 */226 // switch to settings tab227 await driver.findElement(By.xpath('//button[@value="tab-settings"]'))228 .click();229 expect(await isPageUser())230 .toBeTruthy();231 expect(await isTabSettings())232 .toBeTruthy();233 // log out button234 await driver.findElement(By.id('btn-logout'))235 .click();236 expect(await isPageLogin())237 .toBeTruthy();238 });239 test('log in with invalid credentials', async () => {240 expect.assertions(2);241 const invalidPassword = 'sdfgsdfgsdfgsdfg';242 // input password243 await driver.findElement(By.id('password'))244 .sendKeys(invalidPassword);245 // log in button246 await driver.findElement(By.id('btn-login'))247 .click();248 expect(await isPageUser())249 .not250 .toBeTruthy();251 });252});253describe('import key', () => {254 beforeAll(async () => {255 ({256 driver,257 popupUri,258 } = await setupBrowser());259 // create account260 await driver.get(popupUri);261 const data = {};262 await setEncryptedStoreDataByKey(STORE_KEY_VAULT, data, password);263 await driver.get(popupUri);264 // log in265 await driver.findElement(By.id('password'))266 .sendKeys(password);267 await driver.findElement(By.id('btn-login'))268 .click();269 await driver.findElement(By.xpath('//button[@value="tab-settings"]'))270 .click();271 });272 beforeEach(async () => {273 expect(await isPageUser())274 .toBeTruthy();275 expect(await isTabSettings())276 .toBeTruthy();277 });278 afterEach(async () => {279 await driver.findElement(By.id('imp-key-sk'))280 .clear();281 await driver.findElement(By.id('imp-key-pk'))282 .clear();283 await driver.findElement(By.id('imp-key-sg'))284 .clear();285 await driver.findElement(By.id('imp-key-password'))286 .clear();287 });288 afterAll(async () => {289 await driver.quit();290 });291 test('import valid key', async () => {292 expect.assertions(6);293 // input secret key294 await driver.findElement(By.id('imp-key-sk'))295 .sendKeys(secretKey);296 // input public key297 await driver.findElement(By.id('imp-key-pk'))298 .sendKeys(publicKey);299 // input signature300 await driver.findElement(By.id('imp-key-sg'))301 .sendKeys(signature);302 // input password303 await driver.findElement(By.id('imp-key-password'))304 .sendKeys(password);305 // import key button306 await driver.findElement(By.id('btn-imp-key'))307 .click();308 // check if form.js fields are empty - key was imported309 expect(await driver.findElement(By.id('imp-key-sk'))310 .getAttribute('value'))311 .toBe('');312 expect(await driver.findElement(By.id('imp-key-pk'))313 .getAttribute('value'))314 .toBe('');315 expect(await driver.findElement(By.id('imp-key-sg'))316 .getAttribute('value'))317 .toBe('');318 expect(await driver.findElement(By.id('imp-key-password'))319 .getAttribute('value'))320 .toBe('');321 });322 test('import key with invalid signature', async () => {323 expect.assertions(6);324 const invalidSignature = '3523C65D4296455FCD3E07055F43C71872699558DD73A94BBD16C77852155FAE'325 + '0EF46E87AB3D8F86EDAC26A65BEE7B90AFFE7E0F8C592927475A66805F128509';326 // input secret key327 await driver.findElement(By.id('imp-key-sk'))328 .sendKeys(secretKey);329 // input public key330 await driver.findElement(By.id('imp-key-pk'))331 .sendKeys(publicKey);332 // input signature333 await driver.findElement(By.id('imp-key-sg'))334 .sendKeys(invalidSignature);335 // input password336 await driver.findElement(By.id('imp-key-password'))337 .sendKeys(password);338 // import key button339 await driver.findElement(By.id('btn-imp-key'))340 .click();341 // check if form.js fields are empty - key was imported342 expect(await driver.findElement(By.id('imp-key-sk'))343 .getAttribute('value'))344 .not345 .toBe('');346 expect(await driver.findElement(By.id('imp-key-pk'))347 .getAttribute('value'))348 .not349 .toBe('');350 expect(await driver.findElement(By.id('imp-key-sg'))351 .getAttribute('value'))352 .not353 .toBe('');354 expect(await driver.findElement(By.id('imp-key-password'))355 .getAttribute('value'))356 .not357 .toBe('');358 });359});360describe('positive path test', () => {361 beforeAll(async () => {362 ({363 driver,364 popupUri,365 } = await setupBrowser());366 });367 afterAll(async () => {368 await driver.quit();369 });370 test('create account and login', async () => {371 expect.assertions(4);372 // open popup373 await driver.get(popupUri);374 expect(await isPageCreateAccount())375 .toBeTruthy();376 // input password for new account377 await driver.findElement(By.id('password-new'))378 .sendKeys(password);379 await driver.findElement(By.id('password-new-confirm'))380 .sendKeys(password);381 // create account button382 await driver.findElement(By.id('btn-create-acc'))383 .click();384 // check if account was created385 const encrypted = await getStoreDataByKey(STORE_KEY_VAULT);386 const decrypted = CryptoJS.AES.decrypt(encrypted, password)387 .toString(CryptoJS.enc.Utf8);388 expect(decrypted)389 .toBe('{}');390 expect(await isPageUser())391 .toBeTruthy();392 // default tab is tx tab393 expect(await isTabTransactions())394 .toBeTruthy();395 });396 test('import key', async () => {397 expect.assertions(6);398 // switch to settings tab399 await driver.findElement(By.xpath('//button[@value="tab-settings"]'))400 .click();401 expect(await isPageUser())402 .toBeTruthy();403 expect(await isTabSettings())404 .toBeTruthy();405 // input secret key406 await driver.findElement(By.id('imp-key-sk'))407 .sendKeys(secretKey);408 // input public key409 await driver.findElement(By.id('imp-key-pk'))410 .sendKeys(publicKey);411 // input signature412 await driver.findElement(By.id('imp-key-sg'))413 .sendKeys(signature);414 // input password415 await driver.findElement(By.id('imp-key-password'))416 .sendKeys(password);417 // import key button418 await driver.findElement(By.id('btn-imp-key'))419 .click();420 // check if form.js fields are empty - key was imported421 expect(await driver.findElement(By.id('imp-key-sk'))422 .getAttribute('value'))423 .toBe('');424 expect(await driver.findElement(By.id('imp-key-pk'))425 .getAttribute('value'))426 .toBe('');427 expect(await driver.findElement(By.id('imp-key-sg'))428 .getAttribute('value'))429 .toBe('');430 expect(await driver.findElement(By.id('imp-key-password'))431 .getAttribute('value'))432 .toBe('');433 });434 test('log out', async () => {435 expect.assertions(3);436 // switch to settings tab437 await driver.findElement(By.xpath('//button[@value="tab-settings"]'))438 .click();439 expect(await isPageUser())440 .toBeTruthy();441 expect(await isTabSettings())442 .toBeTruthy();443 // log out button444 await driver.findElement(By.id('btn-logout'))445 .click();446 expect(await isPageLogin())447 .toBeTruthy();448 });449 test('add transaction', async () => {450 expect.assertions(1);451 // open test page452 await driver.get(`file:///${__dirname}/../index.html`);453 // add transaction454 await driver.findElement(By.id('btn-add-tx'))455 .click();456 // check if there are console errors457 const consoleErrorArray = await driver.manage()458 .logs()459 .get(logging.Type.BROWSER);460 console.log(consoleErrorArray);461 const errorCount = consoleErrorArray.length;462 expect(errorCount)463 .toBe(0);464 });465 test('log in', async () => {466 expect.assertions(2);467 // open popup468 await driver.get(popupUri);469 expect(await isPageLogin())470 .toBeTruthy();471 // input password472 await driver.findElement(By.id('password'))473 .sendKeys(password);474 // log in button475 await driver.findElement(By.id('btn-login'))476 .click();477 expect(await isPageUser())478 .toBeTruthy();479 });480 test('sign transaction', async () => {481 expect.assertions(3);482 // switch to transaction tab483 await driver.findElement(By.xpath('//button[@value="tab-tx"]'))484 .click();485 expect(await isTabTransactions())486 .toBeTruthy();487 expect(await getPendingTxCount())488 .toBe(1);489 // sign button490 await driver.findElement(By.className('btn-accept'))491 .click();492 expect(await getPendingTxCount())493 .toBe(0);494 });...

Full Screen

Full Screen

jest.tests.js

Source:jest.tests.js Github

copy

Full Screen

1const {Builder, By, Key, Util, until} = require('selenium-webdriver');2const script = require('jest');3const {beforeAll} = require('@jest/globals');4const { underscore } = require('consolidate');5require('chromedriver');6var userID;7var passwordID = 'testPassword';8var songsUrl = 'https://www.youtube.com/watch?v=WqRYBWyvbRo&ab_channel=EpitaphRecords, https://www.youtube.com/watch?v=MIajmLP46b4&ab_channel=UNFD, https://www.youtube.com/watch?v=SQNtGoM3FVU&ab_channel=NapalmRecords, https://www.youtube.com/watch?v=eH6tqXQNWUA&ab_channel=WhileSheSleepsVEVO'9const url = 'http://localhost:8080/';10jest.setTimeout(10000);11describe('EarStorm Tests', function(){12 let driver;13 14 beforeAll(async function(){15 driver = new Builder().forBrowser('chrome').build();16 } ,10000);17 afterAll(async function(){18 await driver.quit();19 }, 20000);20 test('Check title of the page', async function(){21 await driver.get(url);22 let title = await driver.getTitle();23 expect(title).toBe('EarStorm');24 });25 test('Go on playlists page', async function(){26 await driver.get(url);27 let button = await driver.findElement(By.id('discover'));28 await button.click();29 await driver.wait(until.urlContains("homepage"));30 let currentUrl = await driver.getCurrentUrl();31 expect(currentUrl).toBe(url+'homepage');32 });33 test('Create an account', async function(){34 await driver.get(url+'homepage');35 let loginButton = await driver.findElement(By.id('login'));36 await loginButton.click();37 await driver.wait(until.urlContains("login"));38 let currentUrl = await driver.getCurrentUrl();39 expect(currentUrl).toBe(url+'login');40 let usernameField = await driver.findElement(By.name('signUpUsername'));41 await usernameField.click();42 await driver.sleep(1000);43 let user = 'TestUsername'+(Math.floor(Math.random()*Math.floor(10000))).toString();44 userID = user;45 await usernameField.sendKeys(user);46 await driver.sleep(1000);47 let passwordField = await driver.findElement(By.name('signUpPassword'));48 await passwordField.clear();49 await passwordField.click();50 await passwordField.sendKeys('testPassword');51 let emailField = await driver.findElement(By.name('emailAddress'));52 await emailField.click();53 await emailField.clear();54 await emailField.sendKeys('testEmail@test.com');55 await driver.findElement(By.id('signUp')).click();56 await driver.wait(until.urlContains("signup"));57 await driver.sleep(1000);58 await driver.get(url+'homepage');59 let username = await driver.findElement(By.id('username')).getText();60 expect(username).toBe(user);61 });62 test('Test de logout', async function(){63 let accountBtn = await driver.findElement(By.id('username'));64 await accountBtn.click();65 await driver.wait(until.urlContains("account"));66 let logoutBtn = await driver.findElement(By.id('logout'));67 await logoutBtn.click();68 await driver.get(url+'homepage');69 let username = await driver.findElement(By.id('username')).getText();70 expect(username.get).toBe(undefined);71 });72 test('Test login', async function(){73 let loginButton = await driver.findElement(By.id('login'));74 await loginButton.click();75 await driver.wait(until.urlContains("login"));76 let loginUsername = await driver.findElement(By.id('loginUsername'));77 let loginPassword = await driver.findElement(By.id('loginPassword'));78 let loginBtn = await driver.findElement(By.id('login'));79 await loginUsername.clear();80 await loginUsername.click();81 await driver.sleep(1000);82 await loginUsername.sendKeys(userID);83 await driver.sleep(1000);84 await loginPassword.clear();85 await loginPassword.click();86 await loginPassword.sendKeys(passwordID);87 await loginBtn.click();88 await driver.wait(until.urlContains("account"));89 expect(await driver.getCurrentUrl()).toBe(url+'account');90 await driver.get(url+'homepage');91 await driver.wait(until.urlContains("homepage"));92 let username = await driver.findElement(By.id('username')).getText();93 expect(username).toBe(userID);94 });95 test('Test create new Playlist', async function(){96 let accountBtn = await driver.findElement(By.id('username'));97 await accountBtn.click();98 await driver.wait(until.urlContains("account"));99 let createPlaylistBtn = await driver.findElement(By.id('btnCreatePl'));100 await driver.executeScript("arguments[0].click();", createPlaylistBtn);101 await driver.wait(until.urlContains("add_playlist"));102 let playlistNameField = await driver.findElement(By.name("playlist_name"));103 let songsUrlField = await driver.findElement(By.name("playlist_songs"));104 let metalCheckBox = await driver.findElement(By.id("metal"));105 let countryCheckBox = await driver.findElement(By.id("country"));106 let additionalGenresField = await driver.findElement(By.name("playlist_add_genre"));107 let descriptionField = await driver.findElement(By.name("playlist_descr"));108 let savePlaylistBtn = await driver.findElement(By.name('saveplaylist'));109 await playlistNameField.clear();110 await playlistNameField.click();111 await driver.sleep(1000);112 await playlistNameField.sendKeys('Playlist For JTest');113 await driver.sleep(1000);114 await songsUrlField.clear();115 await songsUrlField.click();116 await songsUrlField.sendKeys(songsUrl);117 await metalCheckBox.click();118 await countryCheckBox.click();119 await additionalGenresField.clear();120 await additionalGenresField.click();121 await additionalGenresField.sendKeys('AnotherGenre, OtherGenre');122 await descriptionField.clear();123 await descriptionField.click();124 await descriptionField.sendKeys('This is the description of the playlist');125 await savePlaylistBtn.click();126 await driver.wait(until.urlContains("account"));127 await expect(await driver.getCurrentUrl()).toBe(url+'account');128 });129 test('Playlist well added', async function(){130 await driver.get(url+'account');131 var tbody = await driver.findElement(By.id('tbody'));132 var addedPlaylist = await tbody.getText();133 addedPlaylist = await addedPlaylist.split(" ");134 let playlistName = addedPlaylist.slice(0,3).toString();135 let playlistDesciption = addedPlaylist.slice(3,10).toString();136 let creationDate = addedPlaylist.slice(10,13).toString();137 let modificationDate = addedPlaylist.slice(13,16).toString();138 expect(playlistName.replace(/,/g, " ")).toBe("Playlist For JTest");139 expect(playlistDesciption.replace(/,/g, " ")).toBe("This is the description of the playlist");140 expect(creationDate.replace(',', " ")).toBe(getFullDate(new Date()));141 expect(modificationDate.replace(',', " ")).toBe(getFullDate(new Date()));142 });143 test('Search Function', async function(){144 await driver.get(url+"homepage");145 await driver.wait(until.urlContains("homepage"));146 var searchField = await driver.findElement(By.name("search_words"));147 var input = ['description'];148 await searchField.clear();149 await searchField.click();150 await searchField.sendKeys(input[0]);151 var searchBtn = await driver.findElement(By.id('searchBtn'));152 await searchBtn.click();153 var tbody = await driver.findElement(By.id('tbody'));154 var playlists = await tbody.getText();155 expect(playlists).toContain(input[0]);156 input = "ugszidjzidgugfzzdhfzfz";157 var searchField = await driver.findElement(By.name("search_words"));158 await searchField.clear();159 await searchField.click();160 await searchField.sendKeys(input);161 var searchBtn = await driver.findElement(By.id('searchBtn'));162 await driver.sleep(1000);163 await searchBtn.click();164 var tbody = await driver.findElement(By.id('tbody'));165 playlists = await tbody.getText();166 expect(playlists).toBe("");167 });168});169function getFullDate(d) {170 let date = new Date(d);171 let months = ["January", "February", "March", "April", "May", "June", "July", "Augustus", "September", "October", "November", "December"]172 let fullDate = months[date.getMonth()] + " " + date.getDate() + ",,"+ date.getFullYear();173 return fullDate;...

Full Screen

Full Screen

run.js

Source:run.js Github

copy

Full Screen

1/*2const {Builder, By, Key, util} = require('selenium-webdriver');3const firefox = require("selenium-webdriver/firefox");4const options = new firefox.Options();5//const driver2 = new Builder().forBrowser("firefox").build();6async function example(){7 let driver = await new Builder().forBrowser("firefox").build();8 await driver.get("http://google.com");9 await driver.findElement(By.name("q")).sendKeys("Selenium", Key.RETURN);10 //driver.quit();11}12example();13 */14const {Builder, By, Key, util} = require('selenium-webdriver');15const firefox = require("selenium-webdriver/firefox");16const chrome = require("selenium-webdriver/chrome");17const options = new firefox.Options();18const { describe, it, after, before } = require('mocha');19const chai = require('chai');20const expect = chai.expect;21const chaiAsPromised = require('chai-as-promised');22chai.use(chaiAsPromised);23const should = chai.should();24let chaiHttp = require("chai-http");25chai.should();26chai.use(chaiHttp);27process.on('unhandledRejection', () => {});28async function example(browser) {29 try {30 describe ('Pruebas funcionales con Selenium Webdriver', async function () {31 this.timeout(50000);32 let driver;33 beforeEach (async () => {34 driver = await new Builder().forBrowser(browser)35 //.usingServer("http://localhost:4444/wd/hub")36 .build();37 });38 afterEach (async () => {39 //await driver.close();40 });41/*42 it ('Prueba funcional Selenium: encontrar componente crear carpeta', async () => {43 await driver.get("https://www.google.com");44 await driver.findElement(By.name("q"));45 });46 */47 it ('Prueba funcional Selenium: crear archivo', async () => {48 await driver.get("http://localhost:8080/");49 await driver.findElement(By.id("nickname")).sendKeys("uno");50 await driver.findElement(By.id("contrasena")).sendKeys("123");51 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);52 await driver.sleep(5000);53 await driver.findElement(By.id("gestor_carpetas")).sendKeys(Key.RETURN);54 await driver.findElement(By.id("input_crearcarpeta")).sendKeys("SOG2_2");55 await driver.findElement(By.id("btn_creararchvio")).sendKeys(Key.RETURN);56 //await driver.close();57 });58 it ('Prueba funcional Selenium: crear eliminar archivo', async () => {59 await driver.get("http://localhost:8080/");60 await driver.findElement(By.id("nickname")).sendKeys("uno");61 await driver.findElement(By.id("contrasena")).sendKeys("123");62 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);63 await driver.sleep(5000);64 await driver.findElement(By.id("gestor_carpetas")).sendKeys(Key.RETURN);65 await driver.findElement(By.id("input_crearcarpeta")).sendKeys("SOG2_2");66 await driver.findElement(By.id("btn_eliminararchivo")).sendKeys(Key.RETURN);67 //await driver.close();68 });69 it ('Prueba funcional Selenium: registro de usuario', async () => {70 await driver.get("http://localhost:8080/");71 await driver.findElement(By.id("btn_redreg")).sendKeys(Key.RETURN);72 await driver.sleep(5000);73 await driver.findElement(By.id("inp_nick")).sendKeys("PruebaUser001");74 await driver.findElement(By.id("inp_correo")).sendKeys("PruebaUser001@gmail.com");75 await driver.findElement(By.id("inp_fnace")).sendKeys("01-01-2001");76 await driver.findElement(By.id("inp_pass")).sendKeys("PruebaUser001");77 await driver.findElement(By.id("inp_confpass")).sendKeys("PruebaUser001");78 await driver.findElement(By.id("btn_registro")).sendKeys(Key.RETURN);79 //await driver.close();80 });81 it ('Prueba funcional Selenium: login correcto', async () => {82 await driver.get("http://localhost:8080/");83 await driver.findElement(By.id("nickname")).sendKeys("uno");84 await driver.findElement(By.id("contrasena")).sendKeys("123");85 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);86 //await driver.close();87 });88 it ('Prueba funcional Selenium: login incorrecto', async () => {89 await driver.get("http://localhost:8080/");90 await driver.findElement(By.id("nickname")).sendKeys("uno");91 await driver.findElement(By.id("contrasena")).sendKeys("fdasfa");92 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);93 //await driver.close();94 });95 it ('Prueba funcional Selenium: crear carpeta', async () => {96 await driver.get("http://localhost:8080/");97 await driver.findElement(By.id("nickname")).sendKeys("uno");98 await driver.findElement(By.id("contrasena")).sendKeys("123");99 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);100 await driver.sleep(5000);101 await driver.findElement(By.id("gestor_carpetas")).sendKeys(Key.RETURN);102 await driver.findElement(By.id("input_crearcarpeta")).sendKeys("cnx");103 await driver.findElement(By.id("btn_crearcarpeta")).sendKeys(Key.RETURN);104 //await driver.close();105 });106 it ('Prueba funcional Selenium: eliminar carpeta', async () => {107 await driver.get("http://localhost:8080/");108 await driver.findElement(By.id("nickname")).sendKeys("uno");109 await driver.findElement(By.id("contrasena")).sendKeys("123");110 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);111 await driver.sleep(5000);112 await driver.findElement(By.id("gestor_carpetas")).sendKeys(Key.RETURN);113 await driver.findElement(By.id("input_crearcarpeta")).sendKeys("cnx");114 await driver.findElement(By.id("btn_eliminarcarpeta")).sendKeys(Key.RETURN);115 });116 it ('Prueba funcional Selenium: eliminar carpeta, buscar componente', async () => {117 await driver.get("http://localhost:8080/");118 await driver.findElement(By.id("nickname")).sendKeys("uno");119 await driver.findElement(By.id("contrasena")).sendKeys("123");120 await driver.findElement(By.id("btn_inicio_sesion")).sendKeys(Key.RETURN);121 await driver.sleep(5000);122 await driver.findElement(By.id("gestor_carpetas")).sendKeys(Key.RETURN);123 await driver.findElement(By.id("input_crearcarpeta"));124 });125 /*126 it ('find the input box and google search button', async () => {127 const result = await page.findInputAndButton();128 expect(result.inputEnabled).to.equal(true);129 expect(result.buttonText).to.include('Google');130 });131 it ('put keyword in search box and click search button', async () => {132 const result = await page.submitKeywordAndGetResult();133 expect(result.length).to.be.above(10);134 });135 */136 });137 } catch (ex) {138 console.log (new Error(ex.message));139 } finally {140 //driver.quit();141 }142}143example("firefox");...

Full Screen

Full Screen

redirect_authorize.test.js

Source:redirect_authorize.test.js Github

copy

Full Screen

1var expect = require('expect.js');2var webdriver = require('selenium-webdriver');3var selenium = require('./selenium');4var By = webdriver.By;5var until = webdriver.until;6describe('redirect authorize', function() {7 this.timeout(9999999);8 selenium.runTests((newSession, browser) => {9 context(browser, function() {10 it('[token] should result in a successful transaction', function() {11 var session = newSession(this.test.title);12 var driver = session.start();13 driver.findElement(By.id('login-response-type')).sendKeys('token');14 driver.findElement(By.className('login-redirect-authorize')).click();15 driver.wait(until.elementLocated(By.id('hlploaded')), 30000);16 driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');17 driver.findElement(By.id('password')).sendKeys('1234');18 driver.findElement(By.id('upLogin')).click();19 driver.wait(until.elementLocated(By.id('parsed')), 10000);20 driver.findElement(By.id('err')).getText().then(function(value) {21 console.log('ERR:', value ? value : '-empty-');22 expect(value).to.equal('');23 });24 driver.findElement(By.id('result')).getText().then(function(value) {25 console.log('RESULT:', value);26 expect(value).to.not.equal('');27 var response = JSON.parse(value);28 expect(response.accessToken).to.be.ok();29 expect(response.idToken).to.not.be.ok();30 expect(response.tokenType).to.be.ok();31 expect(response.expiresIn).to.be.ok();32 });33 return session.finish();34 });35 it('[code] should result in a successful transaction', function() {36 var session = newSession(this.test.title);37 var driver = session.start();38 driver.findElement(By.id('login-response-type')).sendKeys('code');39 driver.findElement(By.className('login-redirect-authorize')).click();40 driver.wait(until.elementLocated(By.id('hlploaded')), 30000);41 driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');42 driver.findElement(By.id('password')).sendKeys('1234');43 driver.findElement(By.id('upLogin')).click();44 driver.wait(until.elementLocated(By.id('loaded')), 10000);45 driver.getCurrentUrl().then(function(url) {46 console.log('RESULT URL:', url);47 expect(url).to.contain('code=');48 });49 return session.finish();50 });51 it('[token openid] should result in a successful transaction', function() {52 var session = newSession(this.test.title);53 var driver = session.start();54 driver.findElement(By.id('login-scope')).sendKeys('openid');55 driver.findElement(By.id('login-response-type')).sendKeys('token');56 driver.findElement(By.className('login-redirect-authorize')).click();57 driver.wait(until.elementLocated(By.id('hlploaded')), 30000);58 driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');59 driver.findElement(By.id('password')).sendKeys('1234');60 driver.findElement(By.id('upLogin')).click();61 driver.wait(until.elementLocated(By.id('parsed')), 10000);62 driver.findElement(By.id('err')).getText().then(function(value) {63 console.log('ERR:', value ? value : '-empty-');64 expect(value).to.equal('');65 });66 driver.findElement(By.id('result')).getText().then(function(value) {67 console.log('RESULT:', value);68 expect(value).to.not.equal('');69 var response = JSON.parse(value);70 expect(response.accessToken).to.be.ok();71 expect(response.idToken).to.not.be.ok();72 expect(response.tokenType).to.be.ok();73 expect(response.expiresIn).to.be.ok();74 });75 return session.finish();76 });77 it('[id_token] should result in a successful transaction', function() {78 var session = newSession(this.test.title);79 var driver = session.start();80 driver.findElement(By.id('login-response-type')).sendKeys('id_token');81 driver.findElement(By.className('login-redirect-authorize')).click();82 driver.wait(until.elementLocated(By.id('hlploaded')), 30000);83 driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');84 driver.findElement(By.id('password')).sendKeys('1234');85 driver.findElement(By.id('upLogin')).click();86 driver.wait(until.elementLocated(By.id('parsed')), 10000);87 driver.findElement(By.id('err')).getText().then(function(value) {88 console.log('ERR:', value ? value : '-empty-');89 expect(value).to.equal('');90 });91 driver.findElement(By.id('result')).getText().then(function(value) {92 console.log('RESULT:', value);93 expect(value).to.not.equal('');94 var response = JSON.parse(value);95 expect(response.accessToken).to.not.be.ok();96 expect(response.idToken).to.be.ok();97 expect(response.tokenType).to.not.be.ok();98 expect(response.expiresIn).to.not.be.ok();99 });100 return session.finish();101 });102 it('[token id_token] should result in a successful transaction', function() {103 var session = newSession(this.test.title);104 var driver = session.start();105 driver.findElement(By.id('login-response-type')).sendKeys('token id_token');106 driver.findElement(By.className('login-redirect-authorize')).click();107 driver.wait(until.elementLocated(By.id('hlploaded')), 30000);108 driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');109 driver.findElement(By.id('password')).sendKeys('1234');110 driver.findElement(By.id('upLogin')).click();111 driver.wait(until.elementLocated(By.id('parsed')), 10000);112 driver.findElement(By.id('err')).getText().then(function(value) {113 console.log('ERR:', value ? value : '-empty-');114 expect(value).to.equal('');115 });116 driver.findElement(By.id('result')).getText().then(function(value) {117 console.log('RESULT:', value);118 expect(value).to.not.equal('');119 var response = JSON.parse(value);120 expect(response.accessToken).to.be.ok();121 expect(response.idToken).to.be.ok();122 expect(response.tokenType).to.be.ok();123 expect(response.expiresIn).to.be.ok();124 });125 return session.finish();126 });127 });128 });...

Full Screen

Full Screen

ng.directive_ngController_test.js

Source:ng.directive_ngController_test.js Github

copy

Full Screen

1describe("api/ng.directive:ngController", function() {2 describe("angular+jqLite", function() {3 beforeEach(function() {4 browser.get("index-nocache.html#!/api/ng.directive:ngController");5 });6 it('should check controller as', function() {7 var container = element(by.id('ctrl-as-exmpl'));8 9 expect(container.findElement(by.model('settings.name'))10 .getAttribute('value')).toBe('John Smith');11 12 var firstRepeat =13 container.findElement(by.repeater('contact in settings.contacts').row(0));14 var secondRepeat =15 container.findElement(by.repeater('contact in settings.contacts').row(1));16 17 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))18 .toBe('408 555 1212');19 expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))20 .toBe('john.smith@example.org');21 22 firstRepeat.findElement(by.linkText('clear')).click()23 24 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))25 .toBe('');26 27 container.findElement(by.linkText('add')).click();28 29 expect(container.findElement(by.repeater('contact in settings.contacts').row(2))30 .findElement(by.model('contact.value'))31 .getAttribute('value'))32 .toBe('yourname@example.org');33 });34 it('should check controller', function() {35 var container = element(by.id('ctrl-exmpl'));36 37 expect(container.findElement(by.model('name'))38 .getAttribute('value')).toBe('John Smith');39 40 var firstRepeat =41 container.findElement(by.repeater('contact in contacts').row(0));42 var secondRepeat =43 container.findElement(by.repeater('contact in contacts').row(1));44 45 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))46 .toBe('408 555 1212');47 expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))48 .toBe('john.smith@example.org');49 50 firstRepeat.findElement(by.linkText('clear')).click()51 52 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))53 .toBe('');54 55 container.findElement(by.linkText('add')).click();56 57 expect(container.findElement(by.repeater('contact in contacts').row(2))58 .findElement(by.model('contact.value'))59 .getAttribute('value'))60 .toBe('yourname@example.org');61 });62 });63 describe("angular+jQuery", function() {64 beforeEach(function() {65 browser.get("index-jq-nocache.html#!/api/ng.directive:ngController");66 });67 it('should check controller as', function() {68 var container = element(by.id('ctrl-as-exmpl'));69 70 expect(container.findElement(by.model('settings.name'))71 .getAttribute('value')).toBe('John Smith');72 73 var firstRepeat =74 container.findElement(by.repeater('contact in settings.contacts').row(0));75 var secondRepeat =76 container.findElement(by.repeater('contact in settings.contacts').row(1));77 78 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))79 .toBe('408 555 1212');80 expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))81 .toBe('john.smith@example.org');82 83 firstRepeat.findElement(by.linkText('clear')).click()84 85 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))86 .toBe('');87 88 container.findElement(by.linkText('add')).click();89 90 expect(container.findElement(by.repeater('contact in settings.contacts').row(2))91 .findElement(by.model('contact.value'))92 .getAttribute('value'))93 .toBe('yourname@example.org');94 });95 it('should check controller', function() {96 var container = element(by.id('ctrl-exmpl'));97 98 expect(container.findElement(by.model('name'))99 .getAttribute('value')).toBe('John Smith');100 101 var firstRepeat =102 container.findElement(by.repeater('contact in contacts').row(0));103 var secondRepeat =104 container.findElement(by.repeater('contact in contacts').row(1));105 106 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))107 .toBe('408 555 1212');108 expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value'))109 .toBe('john.smith@example.org');110 111 firstRepeat.findElement(by.linkText('clear')).click()112 113 expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value'))114 .toBe('');115 116 container.findElement(by.linkText('add')).click();117 118 expect(container.findElement(by.repeater('contact in contacts').row(2))119 .findElement(by.model('contact.value'))120 .getAttribute('value'))121 .toBe('yourname@example.org');122 });123 });...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1var assert = require("assert").strict;2var webdriver = require("selenium-webdriver");3const { Builder, By, Key, until } = require('selenium-webdriver');4const { expect } = require('chai');5const driver = new Builder().forBrowser('chrome').build();6driver.get("http://localhost:3000/#");7describe("Home Page", () => {8 it("Should load the home page and get title", async () => {9 const title = await driver.getTitle();10 expect(title).to.equal('Hagai Protfolio');11 });12 it("Should check whether the given element is loaded", async () => {13 await driver.sleep(100);14 await driver.findElement({ id: "welcome-modal" }).click();15 await driver.sleep(150);16 });17 it("Should navigate to sign in and send form", async () => {18 await driver.findElement({id: "toggle"}).click();19 await driver.sleep(100);20 await driver.findElement({ id: "signinlink" }).click();21 await driver.findElement({id: "email_address"}).sendKeys('test@selenium.com');22 await driver.sleep(100)23 await driver.findElement({id: "password"}).sendKeys('test');24 await driver.sleep(100);25 await driver.findElement({id: "sign_in"}).click();26 await driver.sleep(2000);27 });28 it("Should register in case that user not have profile", async () => {29 await driver.findElement({id: "toggle"}).click();30 let isUserAllow;31 try {32 isUserAllow = await driver.findElement(By.id("profile")).isDisplayed();33 } catch {34 isUserAllow = false;35 }36 if(!isUserAllow ) {37 console.log('not registerd')38 await driver.findElement({id: "registerlink"}).click();39 await driver.sleep(100);40 await driver.findElement({id: "name"}).sendKeys('test');41 await driver.sleep(100)42 await driver.findElement({id: "email_address"}).sendKeys('test@selenium.com');43 await driver.sleep(100)44 await driver.findElement({id: "password"}).sendKeys('test');45 await driver.sleep(100);46 await driver.findElement({id: "register"}).click();47 await driver.sleep(2000);48 await driver.findElement({id: "toggle"}).click();49 await driver.sleep(100);50 } else { console.log('user registered') }51 await driver.findElement({id: "profile"}).click();52 await driver.sleep(1000);53 })54})55describe("App usage", () => {56 it("Should check if user can change his name", async () => {57 await driver.findElement({id: "changename"}).sendKeys('selenium');58 await driver.sleep(1000);59 await driver.findElement({id: "entername"}).click();60 await driver.sleep(100);61 let checker = await driver.findElement({id: "namecheck"}).getText();62 expect(checker).to.equal("Welcome selenium!");63 await driver.findElement({id: "toggle"}).click();64 await driver.sleep(100);65 await driver.findElement({id: "profile"}).click();66 await driver.sleep(1000)67 await driver.findElement({id: "changename"}).sendKeys('test');68 await driver.sleep(100);69 await driver.findElement({id: "entername"}).click();70 await driver.sleep(200);71 })72 it("Should check if user can check the weather in Be'er Sheva", async () => {73 await driver.findElement({id: "WethWhat"}).click();74 await driver.sleep(200);75 await driver.findElement({id: "wethInput"}).sendKeys("Beer Sheva");76 await driver.sleep(100);77 await driver.findElement({id: "wethEnter"}).click();78 await driver.sleep(1500);79 let temp = await driver.findElement({id: "temp"}).getText();80 console.log(`Beer Sheva ${temp}`);81 })82 it("Should check if user can check faces in pics", async () => {83 await driver.findElement({id: "SmartBrain"}).click();84 await driver.sleep(100);85 await driver.findElement({id: "smartBrainInput"}).sendKeys('https://img.wcdn.co.il/f_auto,w_700/2/6/4/1/2641451-46.jpg');86 await driver.sleep(100);87 await driver.findElement({id: "smartBrainSubmit"}).click();88 await driver.sleep(2500);89 await driver.findElement({id: "faceBox"});90 await driver.sleep(300);91 })92 it("Should check that user nave token by refresh, and card has changed according to submit requests", async () => {93 driver.navigate().refresh();94 await driver.sleep(3500);95 await driver.findElement({id: "toggle"}).click();96 await driver.sleep(100);97 await driver.findElement({id: "profile"})98 })99}) 100describe("About Page", () => {101 it("Should navigate to the About page and afterwards to github", async () => {102 await driver.findElement({id: "aboutLInk"}).click();103 await driver.sleep(800);104 await driver.findElement({id: "gitHubLink"}).click();105 await driver.sleep(2000);106 after(async () => driver.quit());107 })108 ...

Full Screen

Full Screen

seleniumtest.js

Source:seleniumtest.js Github

copy

Full Screen

1const { Builder, By, Key, until } = require('selenium-webdriver');2junit = require("junit")3var it = junit({4 filter: (msg) => msg.indexOf("test")5});6let driver = new Builder().forBrowser('firefox').build();7driver.get('http://167.99.237.199/');8async function mongoQ1() {9 try {10 await driver.findElement(By.id('mongo')).click()11 await driver.findElement(By.id("1")).findElement(By.tagName("input")).click()12 await driver.findElement(By.id("city")).sendKeys("Copenhagen");13 await driver.findElement(By.id("run")).click()14 let table = await driver.findElement(By.tagName("tbody"));15 let res = await driver.wait(function () {16 return driver.findElement(By.tagName("tbody")).getText().then(function (title) {17 if (title != '') {18 it("mongoQ1", () => it.eq(title.split("\n").length, 528));19 return title.split("\n").length20 } else {21 return title != '';22 }23 });24 }, 10000)25 } catch (e) {26 console.log(e)27 } finally {28 //await driver.quit();29 }30};31async function psqlQ4() {32 try {33 await driver.findElement(By.id('psql')).click()34 await driver.findElement(By.id("4")).findElement(By.tagName("input")).click()35 await driver.findElement(By.id("lat")).sendKeys("53.3439");36 await driver.findElement(By.id("lng")).sendKeys("23.0622");37 await driver.findElement(By.id("run")).click()38 let table = await driver.findElement(By.tagName("tbody"));39 let res = await driver.wait(function () {40 return driver.findElement(By.tagName("tbody")).getText().then(function (title) {41 if (title != '') {42 it("psqlQ4", () => it.eq(title.split("\n").length, 56));43 return title.split("\n").length44 } else {45 return title != '';46 }47 });48 }, 10000)49 } catch (e) {50 console.log(e)51 } finally {52 //await driver.quit();53 }54};55async function Neo4jQ4() {56 try {57 let psql = await driver.findElement(By.id('neo4j'))58 psql.click()59 await driver.findElement(By.id("4")).findElement(By.tagName("input")).click()60 await driver.findElement(By.id("lat")).sendKeys("53.3439");61 await driver.findElement(By.id("lng")).sendKeys("23.0622");62 await driver.findElement(By.id("run")).click()63 let table = await driver.findElement(By.tagName("tbody"));64 let res = await driver.wait(function () {65 return driver.findElement(By.tagName("tbody")).getText().then(function (title) {66 if (title != '') {67 it("psqlQ4", () => it.eq(title.split("\n").length, 56));68 return title.split("\n").length69 } else {70 return title != '';71 }72 });73 }, 10000)74 } catch (e) {75 console.log(e)76 } finally {77 //await driver.quit();78 }79};80async function Neo4jQ2() {81 try {82 let psql = await driver.findElement(By.id('neo4j'))83 psql.click()84 await driver.findElement(By.id("2")).findElement(By.tagName("input")).click()85 await driver.findElement(By.id("book")).sendKeys("Byron");86 await driver.findElement(By.id("run")).click()87 setTimeout(function () {88 //do what you need here89 driver.wait(function () {90 return driver.findElement(By.id("map")).findElements(By.tagName("div")).then(function (title) {91 if (title != '') {92 it("Neo4jQ2", () => it.eq(title.length, 428));93 return title94 } else {95 return title != '';96 }97 });98 }, 10000)99 },5000);100 } catch (e) {101 //console.log(e)102 } finally {103 //await driver.quit();104 }105};106async function PsqlQ3() {107 try {108 let psql = await driver.findElement(By.id('neo4j'))109 psql.click()110 await driver.findElement(By.id("3")).findElement(By.tagName("input")).click()111 await driver.findElement(By.id("author")).sendKeys("Poe, Edgar Allan");112 await driver.findElement(By.id("run")).click()113 setTimeout(function () {114 driver.wait(function () {115 return driver.findElement(By.id("map")).findElements(By.tagName("div")).then(function (title) {116 if (title != '') {117 it("psqlQ3", () => it.eq(title.length, 428));118 return title119 } else {120 return title != '';121 }122 });123 }, 10000)124 },5000);125 } catch (e) {126 //console.log(e)127 } finally {128 //await driver.quit();129 }130};131psqlQ4().then(() => {132 mongoQ1().then(() => {133 Neo4jQ4().then(() => {134 Neo4jQ2().then(() => {135 PsqlQ3().then(() => {136 //driver.close();137 });138 });139 });140 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1d.findElement(By.id("com.android.calculator2:id/digit_1")).click();2d.findElement(By.id("com.android.calculator2:id/digit_2")).click();3d.findElement(By.id("com.android.calculator2:id/digit_3")).click();4d.findElement(By.id("com.android.calculator2:id/digit_4")).click();5d.findElement(By.id("com.android.calculator2:id/digit_5")).click();6d.findElement(By.id("com.android.calculator2:id/digit_6")).click();7d.findElement(By.id("com.android.calculator2:id/digit_7")).click();8d.findElement(By.id("com.android.calculator2:id/digit_8")).click();9d.findElement(By.id("com.android.calculator2:id/digit_9")).click();10d.findElement(By.id("com.android.calculator2:id/digit_0")).click();11d.findElement(By.id("com.android.calculator2:id/eq")).click();12d.findElement(By.id("com.android.calculator2:id/clr")).click();13d.findElement(By.id("com.android.calculator2:id/digit_1")).click();14d.findElement(By.id("com.android.calculator2:id/digit_2")).click();15d.findElement(By.id("com.android.calculator2:id/digit_3")).click();16d.findElement(By.id("com.android.calculator2:id/digit_4")).click();17d.findElement(By.id("com.android.calculator2:id/digit_5")).click();18d.findElement(By.id("com.android.calculator2:id/digit_6")).click();19d.findElement(By.id("com.android.calculator2:id/digit_7")).click();20d.findElement(By.id("com.android.calculator2:id/digit_8")).click();21d.findElement(By.id("com.android.calculator2:id/digit_9")).click();22d.findElement(By.id("com.android.calculator2:id/digit_0")).click();23d.findElement(By.id("com.android.calculator2:id/eq")).click();24d.findElement(By.id("com.android.calculator2:id/clr")).click();25d.findElement(By.id("com.android.calculator2:id/digit_1")).click();26d.findElement(By.id("com.android.calculator2:id/digit_2")).click();27d.findElement(By.id("com.android.calculator2:id/digit_3")).click();28d.findElement(By.id("com.android.calculator2:id/digit_4")).click();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2d.findElement(webdriver.By.name('q')).sendKeys('webdriver');3d.findElement(webdriver.By.name('btnG')).click();4driver.quit();5var webdriver = require('selenium-webdriver');6d.element(webdriver.By.name('q')).sendKeys('webdriver');7d.element(webdriver.By.name('btnG')).click();8driver.quit();9var webdriver = require('selenium-webdriver');10d.elements(webdriver.By.name('q')).sendKeys('webdriver');11d.elements(webdriver.By.name('btnG')).click();12driver.quit();13var webdriver = require('selenium-webdriver');14d.elementBy(webdriver.By.name('q')).sendKeys('webdriver');15d.elementBy(webdriver.By.name('btnG')).click();16driver.quit();17var webdriver = require('selenium-webdriver');18d.elementsBy(webdriver.By.name('q')).sendKeys('webdriver');19d.elementsBy(webdriver.By.name('btnG')).click();20driver.quit();21var webdriver = require('selenium-webdriver');22var driver = new webdriver.Builder().usingServer('http

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities(webdriver.Capabilities.android())4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful