How to use findElement method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

selenium-test.js

Source:selenium-test.js Github

copy

Full Screen

...18 const driver = new Builder().forBrowser('chrome').build();19 it('/login should return an empty email (username) field', async function() {20 await driver.get(loginURL);21 await driver.sleep(2000);22 const loginField = await driver.findElement(By.name('uname')).getAttribute('value');23 expect(loginField).to.equal('');24 });25 it('/login should return an empty password field', async function() {26 await driver.get(loginURL);27 await driver.sleep(2000);28 const passwordField = await driver.findElement(By.name('pwd')).getAttribute('value');29 expect(passwordField).to.equal('');30 })31 it('should return the authentication error page with an empty password and empty email field', async function() {32 await driver.get(loginURL);33 await driver.sleep(2000);34 await driver.findElement(By.id('loginSubmit')).click();35 const failEmailField = await driver.findElement(By.name('uname')).getAttribute('value');36 const failPassField = await driver.findElement(By.name('pwd')).getAttribute('value');37 const errorMessage = await driver.findElement(By.css("p")).getText();38 const curURL = await driver.getCurrentUrl();39 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/loginfail');40 expect(failEmailField).to.equal('');41 expect(failPassField).to.equal('');42 expect(errorMessage).to.equal('Authentication error (incorrect email or password).');43 });44 it('should return the authentication error page with valid-formatted but not-in-database email and empty password', async function() {45 await driver.get(loginURL);46 await driver.sleep(2000);47 await driver.findElement(By.name('uname')).sendKeys('notAValid@Email');48 await driver.findElement(By.id('loginSubmit')).click();49 const failEmailField = await driver.findElement(By.name('uname')).getAttribute('value');50 const failPassField = await driver.findElement(By.name('pwd')).getAttribute('value');51 const errorMessage = await driver.findElement(By.css("p")).getText();52 const curURL = await driver.getCurrentUrl();53 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/loginfail');54 expect(failEmailField).to.equal('');55 expect(failPassField).to.equal('');56 expect(errorMessage).to.equal('Authentication error (incorrect email or password).');57 });58 it('should return the authentication error page with empty email and something in password field', async function() {59 await driver.get(loginURL);60 await driver.sleep(2000);61 await driver.findElement(By.name('pwd')).sendKeys('v3ryStr0ngPa55');62 await driver.findElement(By.id('loginSubmit')).click();63 const failEmailField = await driver.findElement(By.name('uname')).getAttribute('value');64 const failPassField = await driver.findElement(By.name('pwd')).getAttribute('value');65 const errorMessage = await driver.findElement(By.css("p")).getText();66 const curURL = await driver.getCurrentUrl();67 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/loginfail');68 expect(failEmailField).to.equal('');69 expect(failPassField).to.equal('');70 expect(errorMessage).to.equal('Authentication error (incorrect email or password).');71 });72 it('should return the authentication error page with incorrect email and incorrect password', async function() {73 await driver.get(loginURL);74 await driver.sleep(2000);75 await driver.findElement(By.name('uname')).sendKeys('invalidEmail@bgcengineering.ca');76 await driver.findElement(By.name('pwd')).sendKeys('v3ryStr0ngPa55');77 await driver.findElement(By.id('loginSubmit')).click();78 const failEmailField = await driver.findElement(By.name('uname')).getAttribute('value');79 const failPassField = await driver.findElement(By.name('pwd')).getAttribute('value');80 const errorMessage = await driver.findElement(By.css("p")).getText();81 const curURL = await driver.getCurrentUrl();82 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/loginfail');83 expect(failEmailField).to.equal('');84 expect(failPassField).to.equal('');85 expect(errorMessage).to.equal('Authentication error (incorrect email or password).');86 });87 it('should return the landing page (/main) for a correctly authenticated organizer user', async function() {88 await driver.get(loginURL);89 await driver.sleep(2000);90 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');91 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');92 await driver.findElement(By.id('loginSubmit')).click();93 const curURL = await driver.getCurrentUrl();94 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/main');95 await driver.get(logoutURL);96 });97 it('should return the landing page (/main) for a correctly authenticated attendee user', async function() {98 await driver.get(loginURL);99 await driver.sleep(2000);100 await driver.findElement(By.name('uname')).sendKeys('test-attendee@bgcengineering.ca');101 await driver.findElement(By.name('pwd')).sendKeys('11111111aA');102 await driver.findElement(By.id('loginSubmit')).click();103 const curURL = await driver.getCurrentUrl();104 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/main');105 await driver.get(logoutURL);106 });107 it('should return the login page after logging out');108 describe('main-menu', function() {109 it('sidebar should contain three elements for attendee user', async function() {110 await driver.get(loginURL);111 await driver.sleep(1000);112 await driver.findElement(By.name('uname')).sendKeys('test-attendee@bgcengineering.ca');113 await driver.findElement(By.name('pwd')).sendKeys('11111111aA');114 await driver.findElement(By.id('loginSubmit')).click();115 const links = await driver.findElements(By.className('nav-item'));116 await driver.get(logoutURL);117 expect(links.length).to.equal(3);118 });119 it('sidebar should contain four elements for organizer user', async function() {120 await driver.get(loginURL);121 await driver.sleep(1000);122 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');123 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');124 await driver.findElement(By.id('loginSubmit')).click();125 await driver.sleep(1000);126 const links = await driver.findElements(By.className('nav-item'));127 await driver.get(logoutURL);128 expect(links.length).to.equal(4);129 });130 it('on organizer nav, clicking second button should return to /organizer/main', async function() {131 await driver.get(loginURL);132 await driver.sleep(1000);133 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');134 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');135 await driver.findElement(By.id('loginSubmit')).click();136 await driver.findElement(By.id('returnToMain')).click();137 const curURL = await driver.getCurrentUrl();138 await driver.get(logoutURL);139 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/organizer/main');140 });141 it('on organizer nav, clicking third button should go to /organizer/allusers (user config page)', async function() {142 await driver.get(loginURL);143 await driver.sleep(1000);144 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');145 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');146 await driver.findElement(By.id('loginSubmit')).click();147 await driver.findElement(By.id('allusers')).click();148 const curURL = await driver.getCurrentUrl();149 await driver.get(logoutURL);150 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/organizer/allusers');151 });152 it('on attendee nav, clicking second button should return to /main', async function() {153 await driver.get(loginURL);154 await driver.sleep(1000);155 await driver.findElement(By.name('uname')).sendKeys('test-attendee@bgcengineering.ca');156 await driver.findElement(By.name('pwd')).sendKeys('11111111aA');157 await driver.findElement(By.id('loginSubmit')).click();158 await driver.findElement(By.id('attendeeMain')).click();159 const curURL = await driver.getCurrentUrl();160 await driver.get(logoutURL);161 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/main');162 });163 });164 describe('courses', function() {165 //course creation166 describe('course-creation', function() {167 /*it('Attendees should get a 401 Unauthorized status if they try to create a course', async function() {168 await driver.get(loginURL);169 await driver.sleep(1000);170 await driver.findElement(By.name('uname')).sendKeys('test-attendee@bgcengineering.ca');171 await driver.findElement(By.name('pwd')).sendKeys('11111111aA');172 await driver.findElement(By.id('loginSubmit')).click();173 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');174 const message401 = driver.findElement(By.class('pre')).getText();175 expect(message401).to.equal('Unauthorized');176 await driver.get(logoutURL);177 });*/178 it('Setting the registration deadline in the past should prompt an alert', async function() {179 await driver.get(loginURL);180 await driver.sleep(1000);181 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');182 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');183 await driver.findElement(By.id('loginSubmit')).click();184 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');185 //dummy course data186 await driver.findElement(By.id('coursename')).sendKeys('Test Course');187 await driver.findElement(By.id('topic')).sendKeys('Test');188 await driver.findElement(By.id('capacity')).sendKeys('20');189 await driver.findElement(By.id('location')).sendKeys("Meeting Room");190 //April 19, 2020, 11:59 pm191 await driver.findElement(By.id('deadline')).sendKeys('2020\t0419');192 //April 20, 2020 (before this course started)193 //8 AM - 10 AM (legal time)194 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0420');195 await driver.findElement(By.id('startTime1')).sendKeys('08:00A');196 await driver.findElement(By.id('endTime1')).sendKeys('10:00A');197 await driver.findElement(By.id('submitButton')).click();198 await driver.sleep(1000);199 const error = await driver.switchTo().alert().getText();200 await driver.switchTo().alert().accept();201 expect(error).to.equal('Cannot schedule registration deadline in the past.');202 await driver.get(logoutURL);203 });204 it('Creating sessions out of chronological order should prompt an alert', async function() {205 await driver.get(loginURL);206 await driver.sleep(1000);207 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');208 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');209 await driver.findElement(By.id('loginSubmit')).click();210 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');211 //dummy course data212 await driver.findElement(By.id('coursename')).sendKeys('Test Course');213 await driver.findElement(By.id('topic')).sendKeys('Test');214 await driver.findElement(By.id('capacity')).sendKeys('20');215 await driver.findElement(By.id('location')).sendKeys("Meeting Room");216 //April 19, 2020, 11:59 pm217 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');218 //create session on September 1, 10 AM - 12 PM219 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');220 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');221 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');222 //create new session223 await driver.findElement(By.id('addSession')).click();224 //create session on August 31, 10 AM - 12 PM225 await driver.findElement(By.id('sessionDate2')).sendKeys('2020\t0831');226 await driver.findElement(By.id('startTime2')).sendKeys('10:00A');227 await driver.findElement(By.id('endTime2')).sendKeys('12:00P');228 await driver.findElement(By.id('submitButton')).click();229 await driver.sleep(1000);230 const error = await driver.switchTo().alert().getText();231 await driver.switchTo().alert().accept();232 expect(error).to.equal('Sessions should be scheduled in chronological order');233 await driver.get(logoutURL);234 });235 it('Creating sessions with overlapping times should prompt an alert', async function() {236 await driver.get(loginURL);237 await driver.sleep(1000);238 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');239 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');240 await driver.findElement(By.id('loginSubmit')).click();241 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');242 //dummy course data243 await driver.findElement(By.id('coursename')).sendKeys('Test Course');244 await driver.findElement(By.id('topic')).sendKeys('Test');245 await driver.findElement(By.id('capacity')).sendKeys('20');246 await driver.findElement(By.id('location')).sendKeys("Meeting Room");247 //August 20, 2020, 11:59 pm248 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');249 //create session on September 1, 10 AM - 12 PM250 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');251 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');252 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');253 //create new session on September 1, 11 AM - 1 PM254 await driver.findElement(By.id('addSession')).click();255 await driver.findElement(By.id('sessionDate2')).sendKeys('2020\t0901');256 await driver.findElement(By.id('startTime2')).sendKeys('11:00A');257 await driver.findElement(By.id('endTime2')).sendKeys('01:00P');258 await driver.findElement(By.id('submitButton')).click();259 const error = await driver.switchTo().alert().getText();260 await driver.switchTo().alert().accept();261 expect(error).to.equal('Sessions should not overlap (previous session must end before next session starts)');262 await driver.get(logoutURL);263 });264 it('Creating sessions with the end time before the start time should prompt an alert', async function() {265 await driver.get(loginURL);266 await driver.sleep(1000);267 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');268 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');269 await driver.findElement(By.id('loginSubmit')).click();270 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');271 //dummy course data272 await driver.findElement(By.id('coursename')).sendKeys('Test Course');273 await driver.findElement(By.id('topic')).sendKeys('Test');274 await driver.findElement(By.id('capacity')).sendKeys('20');275 await driver.findElement(By.id('location')).sendKeys("Meeting Room");276 //August 20, 2020, 11:59 pm277 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');278 //create session on September 1, 12 PM - 10 AM :thonk:279 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');280 await driver.findElement(By.id('startTime1')).sendKeys('12:00P');281 await driver.findElement(By.id('endTime1')).sendKeys('10:00A');282 await driver.findElement(By.id('submitButton')).click();283 const error = await driver.switchTo().alert().getText();284 await driver.switchTo().alert().accept();285 expect(error).to.equal('End time of course must be after the start');286 await driver.get(logoutURL);287 });288 it('Setting the registration deadline after the first session should prompt an alert', async function() {289 await driver.get(loginURL);290 await driver.sleep(1000);291 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');292 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');293 await driver.findElement(By.id('loginSubmit')).click();294 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');295 //dummy course data296 await driver.findElement(By.id('coursename')).sendKeys('Test Course');297 await driver.findElement(By.id('topic')).sendKeys('Test');298 await driver.findElement(By.id('capacity')).sendKeys('20');299 await driver.findElement(By.id('location')).sendKeys("Meeting Room");300 //September 11, 2020, 11:59 pm301 await driver.findElement(By.id('deadline')).sendKeys('2020\t0911');302 //create session on September 1, 10 AM - 12 PM303 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');304 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');305 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');306 await driver.findElement(By.id('submitButton')).click();307 const error = await driver.switchTo().alert().getText();308 await driver.switchTo().alert().accept();309 expect(error).to.equal('Cannot schedule registration deadline after the first course session.');310 await driver.get(logoutURL);311 });312 it('Successfully creating a new course will redirect back to the organizer main', async function() {313 await driver.get(loginURL);314 await driver.sleep(1000);315 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');316 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');317 await driver.findElement(By.id('loginSubmit')).click();318 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');319 //dummy course data320 await driver.findElement(By.id('coursename')).sendKeys('Test Course');321 await driver.findElement(By.id('topic')).sendKeys('Test');322 await driver.findElement(By.id('capacity')).sendKeys('20');323 await driver.findElement(By.id('location')).sendKeys("Meeting Room");324 //August 20, 2020, 11:59 pm325 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');326 //create session on September 1, 10 AM - 12 PM327 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');328 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');329 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');330 await driver.findElement(By.id('submitButton')).click();331 const curURL = await driver.getCurrentUrl();332 await driver.get(logoutURL);333 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/organizer/main');334 });335 });336 //course access337 describe('course-access', function() {338 //it('Users must be logged in to access a course path');339 //it('Accessing a non-existent course will return a status code')340 it('For a valid course, the title must show up', async function() {341 await driver.get(loginURL);342 await driver.sleep(1000);343 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');344 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');345 await driver.findElement(By.id('loginSubmit')).click();346 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/4');347 const title = driver.findElement(By.class('h1')).getText();348 await driver.get(logoutURL);349 expect(title).to.be.a('string').that.is.not.empty;350 });351 /*352 it('For a valid course, the topic must be present', async function() {353 await driver.get(loginURL);354 await driver.sleep(1000);355 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');356 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');357 await driver.findElement(By.id('loginSubmit')).click();358 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/4');359 const topic = await driver.findElement(By.id('topic')).getText();360 await driver.get(logoutURL);361 expect(topic).to.be.a('string').that.is.not.empty;362 });*/363 it("For a valid course, the location must be present", async function() {364 await driver.get(loginURL);365 await driver.sleep(1000);366 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');367 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');368 await driver.findElement(By.id('loginSubmit')).click();369 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/4');370 const location = await driver.findElement(By.id('location')).getText();371 await driver.get(logoutURL);372 expect(location).to.be.a('string').that.is.not.empty;373 });374 it("For a valid course, the maximum number of seats must be present", async function() {375 await driver.get(loginURL);376 await driver.sleep(1000);377 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');378 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');379 await driver.findElement(By.id('loginSubmit')).click();380 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/4');381 const seats = await driver.findElement(By.id('seatNum')).getText();382 await driver.get(logoutURL);383 expect(seats).to.be.a('string').that.is.not.empty;384 });385 it("For a valid course, there should be at least one session with indicated date, start, and end times")386 });387 //course editing388 describe('course-editing', function() {389 it('should render course information in the proper fields', async function() {390 await driver.get(loginURL);391 await driver.sleep(1000);392 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');393 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');394 await driver.findElement(By.id('loginSubmit')).click();395 await driver.get(orgMain);396 //important: make sure there is a course called "Test Course" that has been created397 await driver.findElement(By.linkText("Test Course")).click()398 const name = await driver.findElement(By.id('coursename')).getText()399 const capacity = parseInt(driver.findElement(By.id('capacity')).getText(), 10)400 const location = await driver.findElement(By.id('location')).getText();401 const deadDate = await driver.findElement(By.id('deadline')).getText();402 const deadTime = await driver.findElement(By.id('deadTime')).getText();403 const sessions = await driver.findElements(By.className('sessionRow'));404 await driver.get(logoutURL);405 expect(name).to.be.a('string').that.is.not.empty;406 expect(loaction).to.be.a('string').that.is.not.empty;407 expect(capacity).to.be.above(0);408 expect(deadDate).to.be.a('string').that.is.not.empty;409 expect(deadTime).to.be.a('string').that.is.not.empty;410 expect(sessions).to.have.lengthOf.at.least(1);411 });412 it('number of enrolled users should be less than or equal to the seat capacity', async function() {413 await driver.get(loginURL);414 await driver.sleep(1000);415 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');416 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');417 await driver.findElement(By.id('loginSubmit')).click();418 await driver.get(orgMain);419 //important: make sure there is a course called "Test Course" that has been created420 await driver.findElement(By.linkText("Test Course")).click();421 const enrolled = await driver.findElements(By.className('enrolledUsers'));422 const capacity = parseInt(driver.findElement(By.id('capacity')).getText(), 10);423 await driver.get(logoutURL)424 expect(enrolled.length).to.be.below(capacity)425 });426 it('when there is a waitlist, number of waitlisted users + number of enrolled users should be more than the seat capacity', async function() {427 await driver.get(loginURL);428 await driver.sleep(1000);429 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');430 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');431 await driver.findElement(By.id('loginSubmit')).click();432 await driver.get(orgMain);433 await driver.findElement(By.linkText("Waitlist Course")).click();434 const enrolled = await driver.findElements(By.className('enrolledUsers')).length;435 const waitlist = await driver.findElements(By.className('waitlistUsers')).length;436 const capacity = parseInt(driver.findElement(By.id('capacity')).getText(), 10);437 await driver.get(logoutURL);438 expect(waitlist + enrolled).to.be.above(capacity);439 });440 });441 describe('course-integration-testing', function() {442 it('creating a course without accepting registration should hide the course in /main. Enabling the course will allow registration, which increases the number of enrolled by 1', async function() {443 await driver.get(loginURL);444 await driver.sleep(1000);445 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');446 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');447 await driver.findElement(By.id('loginSubmit')).click();448 let initCourses = await driver.findElements(By.className('visibleCourses')).length;449 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');450 await driver.findElement(By.id('coursename')).sendKeys('Test Integration Course');451 //await driver.findElement(By.id('topic')).sendKeys('');452 await driver.findElement(By.id('capacity')).sendKeys('20');453 await driver.findElement(By.id('location')).sendKeys("Meeting Room");454 //August 20, 2020, 11:59 pm455 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');456 await driver.findElement(By.id('deadTime')).sendKeys('11:59P');457 //create session on September 2, 10 AM - 12 PM458 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0902');459 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');460 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');461 await driver.findElement(By.id('submitButton')).click();462 await driver.sleep(3000);463 await driver.get(attendeeMain);464 let shouldBeSame = await driver.findElements(By.className('visibleCourses')).length;465 await driver.get(orgMain);466 await driver.findElement(By.linkText('Test Integration Course')).click();467 await driver.findElement(By.name('registration')).click()468 await driver.findElement(By.id('submitButton')).click();469 await driver.sleep(3000);470 await driver.get(attendeeMain);471 let moreByOne = await driver.findElements(By.className('visibleCourses')).length;472 //delete the course473 await driver.get(orgMain);474 await driver.findElement(By.linkText('Test Integration Course')).click();475 await driver.findElement(By.name('delCourse')).click();476 await driver.switchTo().alert().sendKeys('Please delete this course.');477 await driver.switchTo().alert().accept();478 await driver.sleep(4000);479 const testURL = await driver.getCurrentUrl();480 await driver.get(logoutURL);481 expect(initCourses).to.equal(shouldBeSame);482 expect(moreByOne).to.be.above(initCourses);483 expect(testURL).to.equal(orgMain);484 });485 it('Creating a 1-seat course, enrolling, enrolling a separate user, withdrawing the original user, then attempting to enroll the original user will result in that user put on the waitlist', async function() {486 await driver.get(loginURL);487 await driver.sleep(1000);488 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');489 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');490 await driver.findElement(By.id('loginSubmit')).click();491 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/new');492 await driver.findElement(By.id('coursename')).sendKeys('Waitlist Bop Course');493 //await driver.findElement(By.id('topic')).sendKeys('');494 await driver.findElement(By.id('capacity')).sendKeys('1');495 await driver.findElement(By.id('location')).sendKeys("Meeting Room");496 //August 20, 2020, 11:59 pm497 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');498 await driver.findElement(By.id('deadTime')).sendKeys('11:59P');499 //create session on September 2, 10 AM - 12 PM500 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0902');501 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');502 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');503 await driver.findElement(By.name('registration')).click();504 await driver.findElement(By.id('submitButton')).click();505 await driver.sleep(4000);506 await driver.findElement(By.linkText('Waitlist Bop Course')).click();507 const buttonText1 = await driver.findElement(By.id('submitButton')).getText();508 await driver.findElement(By.id('submitButton')).click();509 await driver.sleep(4000);510 await driver.get(logoutURL);511 await driver.sleep(4000);512 await driver.findElement(By.name('uname')).sendKeys('test-attendee@bgcengineering.ca');513 await driver.findElement(By.name('pwd')).sendKeys('11111111aA');514 await driver.findElement(By.id('loginSubmit')).click();515 await driver.findElement(By.linkText('Waitlist Bop Course')).click();516 const buttonText2 = await driver.findElement(By.id('submitButton')).getText();517 await driver.findElement(By.id('submitButton')).click();518 await driver.sleep(4000);519 await driver.get(logoutURL);520 await driver.sleep(4000);521 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');522 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');523 await driver.findElement(By.id('loginSubmit')).click();524 await driver.findElement(By.linkText('Waitlist Bop Course')).click();525 const buttonText3 = await driver.findElement(By.id('submitButton')).getText();526 await driver.findElement(By.id('submitButton')).click();527 await driver.sleep(4000);528 await driver.findElement(By.linkText('Waitlist Bop Course')).click();529 const buttonText4 = await driver.findElement(By.id('submitButton')).getText();530 await driver.findElement(By.id('submitButton')).click();531 const redirectText = await driver.findElement(By.id('redirectMessage')).getText();532 await driver.sleep(4000);533 await driver.get(logoutURL);534 expect(buttonText1).to.equal("Enroll");535 expect(buttonText2).to.equal("Enroll");536 expect(buttonText3).to.equal("Withdraw");537 expect(buttonText4).to.equal("Enroll");538 expect(redirectText).to.equal("Added to waitlist for this course. You will be notified if you move off the waitlist. You will be redirected to the main page.");539 });540 });541 describe('course-enrollment', function() {542 it('when not enrolled, there should be an enroll button', async function() {543 await driver.get(loginURL);544 await driver.sleep(2000);545 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');546 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');547 await driver.findElement(By.id('loginSubmit')).click();548 await driver.findElement(By.linkText('Enrollment Test Course'));549 const buttonText = await driver.findElement(By.id('submitButton')).getText();550 await driver.get(logoutURL);551 expect(buttonText).to.equal('Enroll')552 });553 it('when enrolled, the button should be a withdraw button', async function() {554 await driver.get(loginURL);555 await driver.sleep(2000);556 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');557 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');558 await driver.findElement(By.id('loginSubmit')).click();559 await driver.findElement(By.linkText('Enrollment Test Course')).click();560 await driver.findElement(By.id('submitButton')).click();561 await driver.sleep(4000);562 const testURL = await driver.getCurrentUrl();563 await driver.findElement(By.linkText('Enrollment Test Course')).click();564 const buttonText = await driver.findElement(By.id('submitButton')).getText();565 await driver.get(logoutURL);566 expect(buttonText).to.equal('Withdraw');567 expect(testURL).to.equal(attMain);568 });569 })570 // email paths571 describe('no-users-enrolled', async () => {572 await driver.get(loginURL);573 await driver.sleep(20000);574 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');575 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');576 await driver.findElement(By.id('loginSubmit')).click();577 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/23');578 await driver.findElement(By.id('emailConf')).click();579 await driver.findElement(By.id('emailSendSubmit')).click();580 const message = await driver.findElement(By.id('redirectMessage')).getText();581 await driver.get(logoutURL);582 expect(message).to.equal('No users enrolled, no emails sent. You will be redirected to the course view.');583 });584 describe('email-success', async () => {585 await driver.get(loginURL);586 await driver.sleep(20000);587 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');588 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');589 await driver.findElement(By.id('loginSubmit')).click();590 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/23');591 await driver.findElement(By.id('emailConf')).click();592 await driver.findElement(By.id('emailSendSubmit')).click();593 const message = await driver.findElement(By.id('redirectMessage')).getText();594 await driver.get(logoutURL);595 expect(message).to.equal('Email sent successfully! You will be redirected to the course view.');596 });597 // a true failure will result in an instance when the api fails and throws an err598 // a case where this happens is if the api key is messing599 // to test remove the api key600 // describe('email-api-fail', () => {601 // await driver.get(loginURL);602 // await driver.sleep(20000);603 // await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');604 // await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');605 // await driver.findElement(By.id('loginSubmit')).click();606 // await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/24');607 // await driver.findElement(By.id('emailConf')).click();608 // await driver.findElement(By.id('emailSendSubmit')).click();609 // const message = await driver.findElement(By.id('redirectMessage')).getText();610 // await driver.get(logoutURL);611 // expect(message).to.equal('ERROR: EMAIL NOT SENT! API failure. You will be redirected to the course view.');612 // });613 describe('disable-user', async () => {614 await driver.get(loginURL);615 await driver.sleep(20000);616 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');617 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');618 await driver.findElement(By.id('loginSubmit')).click();619 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/organizer/allusers');620 await driver.findElement(By.id('approvedFalse3')).click();621 await driver.findElement(By.name('updateUserData')).click();622 const message = await driver.findElement(By.id('redirectMessage')).getText();623 await driver.get(logoutURL);624 expect(message).to.equal('User data has been successfully updated! You will be redirected to the main courses page.');625 await driver.get(loginURL);626 await driver.findElement(By.name('uname')).sendKeys('mla283@sfu.ca');627 await driver.findElement(By.name('pwd')).sendKeys('Password123!');628 await driver.findElement(By.id('loginSubmit')).click();629 const curURL = await driver.getCurrentUrl();630 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/login');631 });632 describe('approve-user', async () => {633 await driver.get(loginURL);634 await driver.sleep(20000);635 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');636 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');637 await driver.findElement(By.id('loginSubmit')).click();638 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/organizer/allusers');639 await driver.findElement(By.id('approvedTrue3')).click();640 await driver.findElement(By.name('updateUserData')).click();641 const message = await driver.findElement(By.id('redirectMessage')).getText();642 await driver.get(logoutURL);643 expect(message).to.equal('User data has been successfully updated! You will be redirected to the main courses page.');644 await driver.get(loginURL);645 await driver.findElement(By.name('uname')).sendKeys('mla283@sfu.ca');646 await driver.findElement(By.name('pwd')).sendKeys('Password123!');647 await driver.findElement(By.id('loginSubmit')).click();648 const curURL = await driver.getCurrentUrl();649 expect(curURL).to.equal('https://cmpt276-bgc-coursys.herokuapp.com/main');650 // should check mla283@sfu.ca's inbox to see email received651 });652 653 describe('add-tags', async () => {654 await drive.get(loginURL);655 await (await driver).sleep(20000);656 657 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');658 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');659 await driver.findElement(By.id('loginSubmit')).click();660 661 await driver.get('http://cmpt276-bgc-coursys.herokuapp.com/courses/new');662 663 //dummy course data664 await driver.findElement(By.id('coursename')).sendKeys('Test Course');665 await driver.findElement(By.id('topic')).sendKeys('Test');666 await driver.findElement(By.id('capacity')).sendKeys('20');667 await driver.findElement(By.id('location')).sendKeys("Meeting Room");668 669 //August 20, 2020, 11:59 pm670 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');671 672 //create session on September 1, 10 AM - 12 PM673 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');674 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');675 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');676 await driver.findElement(By.id('tags')).sendKeys('leadership');677 678 await driver.findElement(By.id('submitButton')).click();679 680 await driver.get('http://cmpt276-bgc-coursys.herokuapp.com/main');681 const message = await driver.findElement(By.id('5tags')).getText();682 683 await driver.get(logoutURL);684 685 expect(message2).to.equal('leadership');686 687 });688 689 690 describe('get-status', async () => {691 await drive.get(loginURL);692 await (await driver).sleep(20000);693 694 await driver.findElement(By.name('uname')).sendKeys('test-organizer@bgcengineering.ca');695 await driver.findElement(By.name('pwd')).sendKeys('teamBPtestpassword1');696 await driver.findElement(By.id('loginSubmit')).click();697 await driver.get('http://cmpt276-bgc-coursys.herokuapp.com/courses/new');698 699 //dummy course data700 await driver.findElement(By.id('coursename')).sendKeys('Small Course');701 await driver.findElement(By.id('topic')).sendKeys('Test');702 await driver.findElement(By.id('capacity')).sendKeys('1');703 await driver.findElement(By.id('location')).sendKeys("Meeting Room");704 705 //August 20, 2020, 11:59 pm706 await driver.findElement(By.id('deadline')).sendKeys('2020\t0820');707 708 //create session on September 1, 10 AM - 12 PM709 await driver.findElement(By.id('sessionDate1')).sendKeys('2020\t0901');710 await driver.findElement(By.id('startTime1')).sendKeys('10:00A');711 await driver.findElement(By.id('endTime1')).sendKeys('12:00P');712 await driver.findElement(By.id('tags')).sendKeys('leadership');713 714 await driver.findElement(By.id('submitButton')).click();715 716 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/6');717 718 await driver.findElement(By.id('enroll'))719 720 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/main');721 const message = await driver.findElement(By.id('6status')).getText();722 723 await driver.get(logoutURL);724 725 expect(message).to.equal('Enrolled');726 727 await drive.get(loginURL);728 729 await driver.findElement(By.name('uname')).sendKeys('mla283@sfu.ca');730 await driver.findElement(By.name('pwd')).sendKeys('Password123!');731 await driver.findElement(By.id('loginSubmit')).click();732 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/courses/6');733 734 await driver.findElement(By.id('enroll'))735 736 await driver.get('https://cmpt276-bgc-coursys.herokuapp.com/main');737 const message2 = await driver.findElement(By.id('6status')).getText();738 const message3 = await driver.findElement(By.id('6seats')).getText();739 740 await driver.get(logoutURL);741 742 expect(message2).to.equal('Waitlisted');743 expect(message3).to.equal('2/1 [1]');744 });745});746after(async () => driver.quit());...

Full Screen

Full Screen

dialog-modal_datepicker.js

Source:dialog-modal_datepicker.js Github

copy

Full Screen

...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

...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

...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

...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) {...

Full Screen

Full Screen

redirect_authorize.test.js

Source:redirect_authorize.test.js Github

copy

Full Screen

...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

...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

seleniumtest.js

Source:seleniumtest.js Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .setValue('#lst-ib', 'webdriverio')9 .click('button[name="btnG"]')10 .getTitle().then(function(title) {11 console.log('Title was: ' + title);12 })13 .end();14var webdriver = require('selenium-webdriver');15var driver = new webdriver.Builder()16 .forBrowser('chrome')17 .build();18driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');19driver.findElement(webdriver.By.name('btnG')).click();20driver.getTitle().then(function(title) {21 console.log('Title was: ' + title);22});23driver.quit();24var webdriver = require('selenium-webdriver');25var driver = new webdriver.Builder()26 .forBrowser('chrome')27 .build();28driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');29driver.findElement(webdriver.By.name('btnG')).click();30driver.getTitle().then(function(title) {31 console.log('Title was: ' + title);32});33driver.quit();34var webdriver = require('selenium-webdriver');35var driver = new webdriver.Builder()36 .forBrowser('chrome')37 .build();38driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');39driver.findElement(webdriver.By.name('btnG')).click();40driver.getTitle().then(function(title) {41 console.log('Title was: ' + title);42});43driver.quit();44var webdriver = require('selenium-webdriver');45var driver = new webdriver.Builder()46 .forBrowser('chrome')47 .build();48driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');49driver.findElement(webdriver.By.name('btnG')).click();50driver.getTitle().then(function(title) {51 console.log('Title was

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3 .remote(options)4 .init()5 .setValue('*[name="q"]','WebdriverIO')6 .click('*[name="btnK"]')7 .pause(5000)8 .end();9var webdriverio = require('webdriverio');10var options = { desiredCapabilities: { browserName: 'chrome' } };11 .remote(options)12 .init()13 .setValue('*[name="q"]','WebdriverIO')14 .click('*[name="btnK"]')15 .pause(5000)16 .end();17var webdriverio = require('webdriverio');18var options = { desiredCapabilities: { browserName: 'chrome' } };19 .remote(options)20 .init()21 .setValue('*[name="q"]','WebdriverIO')22 .click('*[name="btnK"]')23 .pause(5000)24 .end();25var webdriverio = require('webdriverio');26var options = { desiredCapabilities: { browserName: 'chrome' } };27 .remote(options)28 .init()29 .setValue('*[name="q"]','WebdriverIO')30 .click('*[name="btnK"]')31 .pause(5000)32 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .getTitle().then(function(title) {6 console.log('Title was: ' + title);7 })8 .setValue('#lst-ib', 'WebdriverIO')9 .click('#tsbb')10 .pause(1000)11 .getTitle().then(function(title) {12 console.log('Title is: ' + title);13 })14 .end();15var webdriverio = require('webdriverio');16var options = { desiredCapabilities: { browserName: 'chrome' } };17var client = webdriverio.remote(options);18 .init()19 .getTitle().then(function(title) {20 console.log('Title was: ' + title);21 })22 .setValue('#lst-ib', 'WebdriverIO')23 .findElement('#tsbb').then(function(element) {24 return element.click();25 })26 .pause(1000)27 .getTitle().then(function(title) {28 console.log('Title is: ' + title);29 })30 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12 console.log('element found');13 console.log(element);14 client.elementIdValue(element.value.ELEMENT, 'WebdriverIO').then(function() {15 console.log('element value set');16 })17});18{ state: 'success',19 value: { ELEMENT: '0.8579119492902652-1' },20 status: 0 }21var webdriverio = require('webdriverio');22var options = {23 desiredCapabilities: {24 }25};26 .remote(options)27 .init()28 .getTitle().then(function(title) {29 console.log('Title was: ' + title);30 })31 .end();32 console.log('element found');33 console.log(element);34 client.elementIdValue(element.value.ELEMENT, 'WebdriverIO').then(function() {35 console.log('element value set');36 })37});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('webdriver.io page', () => {2 it('should have the right title', () => {3 const title = browser.getTitle()4 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')5 })6 it('should have the right title', () => {7 const title = browser.getTitle()8 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')9 })10})11describe('webdriver.io page', () => {12 it('should have the right title', () => {13 const title = browser.getTitle()14 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')15 })16 it('should have the right title', () => {17 const title = browser.getTitle()18 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')19 })20})21describe('webdriver.io page', () => {22 it('should have the right title', () => {23 const title = browser.getTitle()24 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')25 })26 it('should have the right title', () => {27 const title = browser.getTitle()28 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')29 })30})31describe('webdriver.io page', () => {32 it('should have the right title', () => {33 const title = browser.getTitle()34 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')35 })36 it('should have the right title', () => {37 const title = browser.getTitle()38 expect(title).toBe('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')39 })40})

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const options = {3 desiredCapabilities: {4 }5};6const client = webdriverio.remote(options);7 .init()8 .waitForVisible('~digit_1', 5000)9 .click('~digit_1')10 .click('~digit_2')11 .click('~digit_3')12 .click('~digit_4')13 .click('~digit_5')14 .click('~digit_6')15 .click('~digit_7')16 .click('~digit_8')17 .click('~digit_9')18 .click('~digit_0')19 .click('~op_add')20 .click('~digit_1')21 .click('~digit_2')22 .click('~digit_3')23 .click('~digit_4')24 .click('~digit_5')25 .click('~digit_6')26 .click('~digit_7')27 .click('~digit_8')28 .click('~digit_9')29 .click('~digit_0')30 .click('~eq')31 .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test to find an element', () => {2 it('should find the element', () => {3 const element = browser.findElement('css selector', 'h1')4 console.log(element.getText())5 })6})7browser.findElements(selector, selectorValue)8describe('Test to find multiple elements', () => {9 it('should find the elements', () => {10 const elements = browser.findElements('css selector', 'h1')11 console.log(elements[0].getText())12 })13})14element.findElement(selector, selectorValue)15describe('Test to find an element from an element', () => {16 it('should find the element', () => {17 const element = browser.findElement('css selector', 'h1')18 const elementFromElement = element.findElement('css selector', 'a')19 console.log(elementFromElement.getText())20 })21})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('WebdriverIO', function() {2 it('should find an element using a locator strategy', function () {3 const element1 = $('#search_input_react');4 const element2 = $('[name="search"]');5 const element3 = $('.searchBox');6 const element4 = $('input#search_input_react');7 const element5 = $('=API');8 const element6 = $('*=API');9 const element7 = $('header');10 const element9 = $('~search_input_react');11 const element10 = $('android=new UiSelector().resourceId("search_input_react")');12 const element11 = $('ios=UIATarget.localTarget().frontMostApp().mainWindow().buttons()');13 });14});

Full Screen

WebdriverIO Tutorial

Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.

Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.

Chapters

  1. Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?

  4. Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.

  5. How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.

  6. Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.

Run Webdriverio 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