How to use waitForSelector method in Playwright Internal

Best JavaScript code snippet using playwright-internal

casper_course_checkout.js

Source:casper_course_checkout.js Github

copy

Full Screen

...11 }12});13casper.test.begin('Resurrectio test', function(test) {14 casper.start('https://live-georgia-tech-professional-education.pantheonsite.io/');15 casper.waitForSelector(x("//a[normalize-space(text())='Courses']"),16 function success() {17 test.assertExists(x("//a[normalize-space(text())='Courses']"));18 this.click(x("//a[normalize-space(text())='Courses']"));19 },20 function fail() {21 test.assertExists(x("//a[normalize-space(text())='Courses']"));22 });23 casper.waitForSelector(x("//a[normalize-space(text())='Course Details']"),24 function success() {25 test.assertExists(x("//a[normalize-space(text())='Course Details']"));26 this.click(x("//a[normalize-space(text())='Course Details']"));27 },28 function fail() {29 test.assertExists(x("//a[normalize-space(text())='Course Details']"));30 });31 casper.waitForSelector("form#commerce-cart-add-to-cart-form-10511 input[type=submit][value='Register']",32 function success() {33 test.assertExists("form#commerce-cart-add-to-cart-form-10511 input[type=submit][value='Register']");34 this.click("form#commerce-cart-add-to-cart-form-10511 input[type=submit][value='Register']");35 },36 function fail() {37 test.assertExists("form#commerce-cart-add-to-cart-form-10511 input[type=submit][value='Register']");38 });39 /* submit form */40 casper.waitForSelector(x("//a[normalize-space(text())='proceed to your cart']"),41 function success() {42 test.assertExists(x("//a[normalize-space(text())='proceed to your cart']"));43 this.click(x("//a[normalize-space(text())='proceed to your cart']"));44 },45 function fail() {46 test.assertExists(x("//a[normalize-space(text())='proceed to your cart']"));47 });48 casper.waitForSelector("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']",49 function success() {50 test.assertExists("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");51 this.click("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");52 },53 function fail() {54 test.assertExists("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");55 });56 /* submit form */57 casper.waitForSelector(x("//a[normalize-space(text())='Create Attendee Account']"),58 function success() {59 test.assertExists(x("//a[normalize-space(text())='Create Attendee Account']"));60 this.click(x("//a[normalize-space(text())='Create Attendee Account']"));61 },62 function fail() {63 test.assertExists(x("//a[normalize-space(text())='Create Attendee Account']"));64 });65 casper.waitForSelector("form input[name='mail']",66 function success() {67 test.assertExists("form input[name='mail']");68 this.click("form input[name='mail']");69 },70 function fail() {71 test.assertExists("form input[name='mail']");72 });73 email_test = datetime.timestamp()74 casper.waitForSelector("input[name='mail']",75 function success() {76 this.sendKeys("input[name='mail']", "eladio+" + email_test + "@pantheon.io");77 },78 function fail() {79 test.assertExists("input[name='mail']");80 });81 casper.waitForSelector("input[name='verify_email']",82 function success() {83 this.sendKeys("input[name='verify_email']", "eladio+" + email_test + "@pantheon.io");84 },85 function fail() {86 test.assertExists("input[name='verify_email']");87 });88 casper.waitForSelector("input[name='pass[pass1]']",89 function success() {90 this.sendKeys("input[name='pass[pass1]']", "GeorgiaTech1234");91 },92 function fail() {93 test.assertExists("input[name='pass[pass1]']");94 });95 casper.waitForSelector("input[name='pass[pass2]']",96 function success() {97 this.sendKeys("input[name='pass[pass2]']", "GeorgiaTech1234");98 },99 function fail() {100 test.assertExists("input[name='pass[pass2]']");101 });102 casper.waitForSelector("form input[name='pass[pass1]']",103 function success() {104 test.assertExists("form input[name='pass[pass1]']");105 this.click("form input[name='pass[pass1]']");106 },107 function fail() {108 test.assertExists("form input[name='pass[pass1]']");109 });110 casper.waitForSelector("form input[name='pass[pass1]']",111 function success() {112 test.assertExists("form input[name='pass[pass1]']");113 this.click("form input[name='pass[pass1]']");114 },115 function fail() {116 test.assertExists("form input[name='pass[pass1]']");117 });118 casper.waitForSelector("input[name='pass[pass1]']",119 function success() {120 this.sendKeys("input[name='pass[pass1]']", "GeorgiaTech1234");121 },122 function fail() {123 test.assertExists("input[name='pass[pass1]']");124 });125 casper.waitForSelector("input[name='pass[pass2]']",126 function success() {127 this.sendKeys("input[name='pass[pass2]']", "GeorgiaTech1234");128 },129 function fail() {130 test.assertExists("input[name='pass[pass2]']");131 });132 casper.waitForSelector("form input[name='field_person_first_name[und][0][value]']",133 function success() {134 test.assertExists("form input[name='field_person_first_name[und][0][value]']");135 this.click("form input[name='field_person_first_name[und][0][value]']");136 },137 function fail() {138 test.assertExists("form input[name='field_person_first_name[und][0][value]']");139 });140 casper.waitForSelector("input[name='field_person_first_name[und][0][value]']",141 function success() {142 this.sendKeys("input[name='field_person_first_name[und][0][value]']", "Eladio");143 },144 function fail() {145 test.assertExists("input[name='field_person_first_name[und][0][value]']");146 });147 casper.waitForSelector("input[name='field_person_preferred_firstname[und][0][value]']",148 function success() {149 this.sendKeys("input[name='field_person_preferred_firstname[und][0][value]']", "EL");150 },151 function fail() {152 test.assertExists("input[name='field_person_preferred_firstname[und][0][value]']");153 });154 casper.waitForSelector("input[name='field_person_middle_name[und][0][value]']",155 function success() {156 this.sendKeys("input[name='field_person_middle_name[und][0][value]']", "Castro");157 },158 function fail() {159 test.assertExists("input[name='field_person_middle_name[und][0][value]']");160 });161 casper.waitForSelector("input[name='field_person_last_name[und][0][value]']",162 function success() {163 this.sendKeys("input[name='field_person_last_name[und][0][value]']", "Abquina");164 },165 function fail() {166 test.assertExists("input[name='field_person_last_name[und][0][value]']");167 });168 casper.waitForSelector("form input[name='field_person_first_name[und][0][value]']",169 function success() {170 test.assertExists("form input[name='field_person_first_name[und][0][value]']");171 this.click("form input[name='field_person_first_name[und][0][value]']");172 },173 function fail() {174 test.assertExists("form input[name='field_person_first_name[und][0][value]']");175 });176 casper.waitForSelector("input[name='field_person_first_name[und][0][value]']",177 function success() {178 this.sendKeys("input[name='field_person_first_name[und][0][value]']", " JoselEladio Jose");179 },180 function fail() {181 test.assertExists("input[name='field_person_first_name[und][0][value]']");182 });183 casper.waitForSelector(".form-item.form-type-textfield.form-item-field-person-middle-name-und-0-value label",184 function success() {185 test.assertExists(".form-item.form-type-textfield.form-item-field-person-middle-name-und-0-value label");186 this.click(".form-item.form-type-textfield.form-item-field-person-middle-name-und-0-value label");187 },188 function fail() {189 test.assertExists(".form-item.form-type-textfield.form-item-field-person-middle-name-und-0-value label");190 });191 casper.waitForSelector("form input[name='field_person_middle_name[und][0][value]']",192 function success() {193 test.assertExists("form input[name='field_person_middle_name[und][0][value]']");194 this.click("form input[name='field_person_middle_name[und][0][value]']");195 },196 function fail() {197 test.assertExists("form input[name='field_person_middle_name[und][0][value]']");198 });199 casper.waitForSelector("form input[name='field_person_last_name[und][0][value]']",200 function success() {201 test.assertExists("form input[name='field_person_last_name[und][0][value]']");202 this.click("form input[name='field_person_last_name[und][0][value]']");203 },204 function fail() {205 test.assertExists("form input[name='field_person_last_name[und][0][value]']");206 });207 casper.waitForSelector("input[name='mail']",208 function success() {209 this.sendKeys("input[name='mail']", "eladio@pantheon.io");210 },211 function fail() {212 test.assertExists("input[name='mail']");213 });214 casper.waitForSelector("form input[name='verify_email']",215 function success() {216 test.assertExists("form input[name='verify_email']");217 this.click("form input[name='verify_email']");218 },219 function fail() {220 test.assertExists("form input[name='verify_email']");221 });222 casper.waitForSelector("input[name='verify_email']",223 function success() {224 this.sendKeys("input[name='verify_email']", "eladio@pantheon.io");225 },226 function fail() {227 test.assertExists("input[name='verify_email']");228 });229 casper.waitForSelector("form input[name='pass[pass1]']",230 function success() {231 test.assertExists("form input[name='pass[pass1]']");232 this.click("form input[name='pass[pass1]']");233 },234 function fail() {235 test.assertExists("form input[name='pass[pass1]']");236 });237 casper.waitForSelector("input[name='pass[pass1]']",238 function success() {239 this.sendKeys("input[name='pass[pass1]']", "GeorgiaTech1234");240 },241 function fail() {242 test.assertExists("input[name='pass[pass1]']");243 });244 casper.waitForSelector("form input[name='pass[pass2]']",245 function success() {246 test.assertExists("form input[name='pass[pass2]']");247 this.click("form input[name='pass[pass2]']");248 },249 function fail() {250 test.assertExists("form input[name='pass[pass2]']");251 });252 casper.waitForSelector("form input[name='pass[pass2]']",253 function success() {254 test.assertExists("form input[name='pass[pass2]']");255 this.click("form input[name='pass[pass2]']");256 },257 function fail() {258 test.assertExists("form input[name='pass[pass2]']");259 });260 casper.waitForSelector("input[name='pass[pass2]']",261 function success() {262 this.sendKeys("input[name='pass[pass2]']", "GeorgiaTech1234");263 },264 function fail() {265 test.assertExists("input[name='pass[pass2]']");266 });267 casper.waitForSelector("form input[name='field_person_first_name[und][0][value]']",268 function success() {269 test.assertExists("form input[name='field_person_first_name[und][0][value]']");270 this.click("form input[name='field_person_first_name[und][0][value]']");271 },272 function fail() {273 test.assertExists("form input[name='field_person_first_name[und][0][value]']");274 });275 casper.waitForSelector("input[name='field_person_first_name[und][0][value]']",276 function success() {277 this.sendKeys("input[name='field_person_first_name[und][0][value]']", "Eladio Jose");278 },279 function fail() {280 test.assertExists("input[name='field_person_first_name[und][0][value]']");281 });282 casper.waitForSelector("form input[name='field_person_preferred_firstname[und][0][value]']",283 function success() {284 test.assertExists("form input[name='field_person_preferred_firstname[und][0][value]']");285 this.click("form input[name='field_person_preferred_firstname[und][0][value]']");286 },287 function fail() {288 test.assertExists("form input[name='field_person_preferred_firstname[und][0][value]']");289 });290 casper.waitForSelector("input[name='field_person_preferred_firstname[und][0][value]']",291 function success() {292 this.sendKeys("input[name='field_person_preferred_firstname[und][0][value]']", "Elladio");293 },294 function fail() {295 test.assertExists("input[name='field_person_preferred_firstname[und][0][value]']");296 });297 casper.waitForSelector("input[name='field_person_middle_name[und][0][value]']",298 function success() {299 this.sendKeys("input[name='field_person_middle_name[und][0][value]']", "Castro");300 },301 function fail() {302 test.assertExists("input[name='field_person_middle_name[und][0][value]']");303 });304 casper.waitForSelector("form input[name='field_person_last_name[und][0][value]']",305 function success() {306 test.assertExists("form input[name='field_person_last_name[und][0][value]']");307 this.click("form input[name='field_person_last_name[und][0][value]']");308 },309 function fail() {310 test.assertExists("form input[name='field_person_last_name[und][0][value]']");311 });312 casper.waitForSelector("input[name='field_person_last_name[und][0][value]']",313 function success() {314 this.sendKeys("input[name='field_person_last_name[und][0][value]']", "Abquina");315 },316 function fail() {317 test.assertExists("input[name='field_person_last_name[und][0][value]']");318 });319 casper.waitForSelector("#edit-field-person-dob-und-0-value-month",320 function success() {321 test.assertExists("#edit-field-person-dob-und-0-value-month");322 this.click("#edit-field-person-dob-und-0-value-month");323 },324 function fail() {325 test.assertExists("#edit-field-person-dob-und-0-value-month");326 });327 casper.waitForSelector("#edit-field-person-dob-und-0-value-day",328 function success() {329 test.assertExists("#edit-field-person-dob-und-0-value-day");330 this.click("#edit-field-person-dob-und-0-value-day");331 },332 function fail() {333 test.assertExists("#edit-field-person-dob-und-0-value-day");334 });335 casper.waitForSelector("#edit-field-person-dob-und-0-value-year",336 function success() {337 test.assertExists("#edit-field-person-dob-und-0-value-year");338 this.click("#edit-field-person-dob-und-0-value-year");339 },340 function fail() {341 test.assertExists("#edit-field-person-dob-und-0-value-year");342 });343 casper.waitForSelector("#edit-field-person-address-type-und",344 function success() {345 test.assertExists("#edit-field-person-address-type-und");346 this.click("#edit-field-person-address-type-und");347 },348 function fail() {349 test.assertExists("#edit-field-person-address-type-und");350 });351 casper.waitForSelector("#edit-field-person-address-und-0-country",352 function success() {353 test.assertExists("#edit-field-person-address-und-0-country");354 this.click("#edit-field-person-address-und-0-country");355 },356 function fail() {357 test.assertExists("#edit-field-person-address-und-0-country");358 });359 casper.waitForSelector("form input[name='field_person_address[und][0][thoroughfare]']",360 function success() {361 test.assertExists("form input[name='field_person_address[und][0][thoroughfare]']");362 this.click("form input[name='field_person_address[und][0][thoroughfare]']");363 },364 function fail() {365 test.assertExists("form input[name='field_person_address[und][0][thoroughfare]']");366 });367 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",368 function success() {369 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "Calfirniaornia ");370 },371 function fail() {372 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");373 });374 casper.wait(1000);375 casper.then(function() {376 this.captureSelector("screenshot1.png", "html");377 });378 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",379 function success() {380 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "t");381 },382 function fail() {383 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");384 });385 casper.wait(1000);386 casper.then(function() {387 this.captureSelector("screenshot2.png", "html");388 });389 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",390 function success() {391 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "t");392 },393 function fail() {394 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");395 });396 casper.wait(1000);397 casper.then(function() {398 this.captureSelector("screenshot3.png", "html");399 });400 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",401 function success() {402 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "s");403 },404 function fail() {405 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");406 });407 casper.wait(1000);408 casper.then(function() {409 this.captureSelector("screenshot4.png", "html");410 });411 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",412 function success() {413 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "ss");414 },415 function fail() {416 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");417 });418 casper.wait(1000);419 casper.then(function() {420 this.captureSelector("screenshot5.png", "html");421 });422 casper.wait(1000);423 casper.then(function() {424 this.captureSelector("screenshot6.png", "html");425 });426 casper.wait(1000);427 casper.then(function() {428 this.captureSelector("screenshot7.png", "html");429 });430 casper.wait(1000);431 casper.then(function() {432 this.captureSelector("screenshot8.png", "html");433 });434 casper.wait(1000);435 casper.then(function() {436 this.captureSelector("screenshot9.png", "html");437 });438 casper.wait(1000);439 casper.then(function() {440 this.captureSelector("screenshot10.png", "html");441 });442 casper.wait(1000);443 casper.then(function() {444 this.captureSelector("screenshot11.png", "html");445 });446 casper.wait(1000);447 casper.then(function() {448 this.captureSelector("screenshot12.png", "html");449 });450 casper.wait(1000);451 casper.then(function() {452 this.captureSelector("screenshot13.png", "html");453 });454 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",455 function success() {456 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "street");457 },458 function fail() {459 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");460 });461 casper.wait(1000);462 casper.then(function() {463 this.captureSelector("screenshot14.png", "html");464 });465 casper.waitForSelector("input[name='field_person_address[und][0][locality]']",466 function success() {467 this.sendKeys("input[name='field_person_address[und][0][locality]']", "asan Francisco");468 },469 function fail() {470 test.assertExists("input[name='field_person_address[und][0][locality]']");471 });472 casper.wait(1000);473 casper.then(function() {474 this.captureSelector("screenshot15.png", "html");475 });476 casper.wait(1000);477 casper.then(function() {478 this.captureSelector("screenshot16.png", "html");479 });480 casper.wait(1000);481 casper.then(function() {482 this.captureSelector("screenshot17.png", "html");483 });484 casper.wait(1000);485 casper.then(function() {486 this.captureSelector("screenshot18.png", "html");487 });488 casper.wait(1000);489 casper.then(function() {490 this.captureSelector("screenshot19.png", "html");491 });492 casper.wait(1000);493 casper.then(function() {494 this.captureSelector("screenshot20.png", "html");495 });496 casper.waitForSelector("input[name='field_person_address[und][0][locality]']",497 function success() {498 this.sendKeys("input[name='field_person_address[und][0][locality]']", "s");499 },500 function fail() {501 test.assertExists("input[name='field_person_address[und][0][locality]']");502 });503 casper.waitForSelector("#edit-field-person-address-und-0-administrative-area",504 function success() {505 test.assertExists("#edit-field-person-address-und-0-administrative-area");506 this.click("#edit-field-person-address-und-0-administrative-area");507 },508 function fail() {509 test.assertExists("#edit-field-person-address-und-0-administrative-area");510 });511 casper.waitForSelector("form input[name='field_person_address[und][0][postal_code]']",512 function success() {513 test.assertExists("form input[name='field_person_address[und][0][postal_code]']");514 this.click("form input[name='field_person_address[und][0][postal_code]']");515 },516 function fail() {517 test.assertExists("form input[name='field_person_address[und][0][postal_code]']");518 });519 casper.waitForSelector("input[name='field_person_address[und][0][postal_code]']",520 function success() {521 this.sendKeys("input[name='field_person_address[und][0][postal_code]']", "90");522 },523 function fail() {524 test.assertExists("input[name='field_person_address[und][0][postal_code]']");525 });526 casper.waitForSelector("input[name='field_person_address[und][0][postal_code]']",527 function success() {528 this.sendKeys("input[name='field_person_address[und][0][postal_code]']", "894110");529 },530 function fail() {531 test.assertExists("input[name='field_person_address[und][0][postal_code]']");532 });533 casper.waitForSelector("form input[name='field_person_company_name[und][0][value]']",534 function success() {535 test.assertExists("form input[name='field_person_company_name[und][0][value]']");536 this.click("form input[name='field_person_company_name[und][0][value]']");537 },538 function fail() {539 test.assertExists("form input[name='field_person_company_name[und][0][value]']");540 });541 casper.waitForSelector("input[name='field_person_company_name[und][0][value]']",542 function success() {543 this.sendKeys("input[name='field_person_company_name[und][0][value]']", "Pantheon ");544 },545 function fail() {546 test.assertExists("input[name='field_person_company_name[und][0][value]']");547 });548 casper.wait(1000);549 casper.then(function() {550 this.captureSelector("screenshot21.png", "html");551 });552 casper.wait(1000);553 casper.then(function() {554 this.captureSelector("screenshot22.png", "html");555 });556 casper.waitForSelector("input[name='field_person_company_name[und][0][value]']",557 function success() {558 this.sendKeys("input[name='field_person_company_name[und][0][value]']", "Aystems");559 },560 function fail() {561 test.assertExists("input[name='field_person_company_name[und][0][value]']");562 });563 casper.wait(1000);564 casper.then(function() {565 this.captureSelector("screenshot23.png", "html");566 });567 casper.waitForSelector("input[name='field_person_company_name[und][0][value]']",568 function success() {569 this.sendKeys("input[name='field_person_company_name[und][0][value]']", " s");570 },571 function fail() {572 test.assertExists("input[name='field_person_company_name[und][0][value]']");573 });574 casper.waitForSelector("input[name='field_person_job_title[und][0][value]']",575 function success() {576 this.sendKeys("input[name='field_person_job_title[und][0][value]']", "Engagement Manager");577 },578 function fail() {579 test.assertExists("input[name='field_person_job_title[und][0][value]']");580 });581 casper.waitForSelector(".form-item.form-type-select.form-item-field-person-nation-citizenship-und .styled-select",582 function success() {583 test.assertExists(".form-item.form-type-select.form-item-field-person-nation-citizenship-und .styled-select");584 this.click(".form-item.form-type-select.form-item-field-person-nation-citizenship-und .styled-select");585 },586 function fail() {587 test.assertExists(".form-item.form-type-select.form-item-field-person-nation-citizenship-und .styled-select");588 });589 casper.waitForSelector("#edit-field-person-nation-citizenship-und",590 function success() {591 test.assertExists("#edit-field-person-nation-citizenship-und");592 this.click("#edit-field-person-nation-citizenship-und");593 },594 function fail() {595 test.assertExists("#edit-field-person-nation-citizenship-und");596 });597 casper.waitForSelector("#edit-field-person-nation-citizenship-und",598 function success() {599 test.assertExists("#edit-field-person-nation-citizenship-und");600 this.click("#edit-field-person-nation-citizenship-und");601 },602 function fail() {603 test.assertExists("#edit-field-person-nation-citizenship-und");604 });605 casper.waitForSelector("#edit-field-person-phone-type-und",606 function success() {607 test.assertExists("#edit-field-person-phone-type-und");608 this.click("#edit-field-person-phone-type-und");609 },610 function fail() {611 test.assertExists("#edit-field-person-phone-type-und");612 });613 casper.waitForSelector("form input[name='field_person_phone_area_code[und][0][value]']",614 function success() {615 test.assertExists("form input[name='field_person_phone_area_code[und][0][value]']");616 this.click("form input[name='field_person_phone_area_code[und][0][value]']");617 },618 function fail() {619 test.assertExists("form input[name='field_person_phone_area_code[und][0][value]']");620 });621 casper.waitForSelector("input[name='field_person_phone_area_code[und][0][value]']",622 function success() {623 this.sendKeys("input[name='field_person_phone_area_code[und][0][value]']", "63");624 },625 function fail() {626 test.assertExists("input[name='field_person_phone_area_code[und][0][value]']");627 });628 casper.waitForSelector("input[name='field_person_phone_number[und][0][value]']",629 function success() {630 this.sendKeys("input[name='field_person_phone_number[und][0][value]']", "9088772988");631 },632 function fail() {633 test.assertExists("input[name='field_person_phone_number[und][0][value]']");634 });635 /* submit form */636 casper.waitForSelector("form input[name='field_person_address[und][0][thoroughfare]']",637 function success() {638 test.assertExists("form input[name='field_person_address[und][0][thoroughfare]']");639 this.click("form input[name='field_person_address[und][0][thoroughfare]']");640 },641 function fail() {642 test.assertExists("form input[name='field_person_address[und][0][thoroughfare]']");643 });644 casper.waitForSelector("input[name='field_person_address[und][0][thoroughfare]']",645 function success() {646 this.sendKeys("input[name='field_person_address[und][0][thoroughfare]']", "717 ");647 },648 function fail() {649 test.assertExists("input[name='field_person_address[und][0][thoroughfare]']");650 });651 /* submit form */652 casper.waitForSelector("input[name='pass[pass1]']",653 function success() {654 this.sendKeys("input[name='pass[pass1]']", "GeorgiaTech1234");655 },656 function fail() {657 test.assertExists("input[name='pass[pass1]']");658 });659 casper.waitForSelector("input[name='pass[pass2]']",660 function success() {661 this.sendKeys("input[name='pass[pass2]']", "GeorgiaTech1234");662 },663 function fail() {664 test.assertExists("input[name='pass[pass2]']");665 });666 casper.waitForSelector("form input[type=submit][value='Create Attendee Account']",667 function success() {668 test.assertExists("form input[type=submit][value='Create Attendee Account']");669 this.click("form input[type=submit][value='Create Attendee Account']");670 },671 function fail() {672 test.assertExists("form input[type=submit][value='Create Attendee Account']");673 });674 /* submit form */675 casper.waitForSelector(".gtpe-header__utility-bar.wrapper .user-menu.icon-menu .icon-menu__item:nth-child(2) .icon-menu__text",676 function success() {677 test.assertExists(".gtpe-header__utility-bar.wrapper .user-menu.icon-menu .icon-menu__item:nth-child(2) .icon-menu__text");678 this.click(".gtpe-header__utility-bar.wrapper .user-menu.icon-menu .icon-menu__item:nth-child(2) .icon-menu__text");679 },680 function fail() {681 test.assertExists(".gtpe-header__utility-bar.wrapper .user-menu.icon-menu .icon-menu__item:nth-child(2) .icon-menu__text");682 });683 casper.waitForSelector("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']",684 function success() {685 test.assertExists("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");686 this.click("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");687 },688 function fail() {689 test.assertExists("form#views-form-commerce-cart-form-gtpe-default input[type=submit][value='Checkout']");690 });691 /* submit form */692 casper.waitForSelector("form#commerce-checkout-form-checkout input[name='commerce_coupon[coupon_code]']",693 function success() {694 test.assertExists("form#commerce-checkout-form-checkout input[name='commerce_coupon[coupon_code]']");695 this.click("form#commerce-checkout-form-checkout input[name='commerce_coupon[coupon_code]']");696 },697 function fail() {698 test.assertExists("form#commerce-checkout-form-checkout input[name='commerce_coupon[coupon_code]']");699 });700 casper.waitForSelector("input[name='commerce_coupon[coupon_code]']",701 function success() {702 this.sendKeys("input[name='commerce_coupon[coupon_code]']", "GT-50");703 },704 function fail() {705 test.assertExists("input[name='commerce_coupon[coupon_code]']");706 });707 casper.waitForSelector(x("//a[normalize-space(text())='/page_manager_node_view_page/course']"),708 function success() {709 test.assertExists(x("//a[normalize-space(text())='/page_manager_node_view_page/course']"));710 this.click(x("//a[normalize-space(text())='/page_manager_node_view_page/course']"));711 },712 function fail() {713 test.assertExists(x("//a[normalize-space(text())='/page_manager_node_view_page/course']"));714 });715 casper.waitForSelector("#drilldown_column",716 function success() {717 test.assertExists("#drilldown_column");718 this.click("#drilldown_column");719 },720 function fail() {721 test.assertExists("#drilldown_column");722 });723 casper.waitForSelector(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"),724 function success() {725 test.assertExists(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));726 this.click(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));727 },728 function fail() {729 test.assertExists(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));730 });731 casper.waitForSelector(x("//a[@id='drilldown_close']"),732 function success() {733 test.assertExists(x("//a[@id='drilldown_close']"));734 this.click(x("//a[@id='drilldown_close']"));735 },736 function fail() {737 test.assertExists(x("//a[@id='drilldown_close']"));738 });739 casper.waitForSelector(x("//a[normalize-space(text())='/drupal_get_form/commerce_checkout_form_checkout']"),740 function success() {741 test.assertExists(x("//a[normalize-space(text())='/drupal_get_form/commerce_checkout_form_checkout']"));742 this.click(x("//a[normalize-space(text())='/drupal_get_form/commerce_checkout_form_checkout']"));743 },744 function fail() {745 test.assertExists(x("//a[normalize-space(text())='/drupal_get_form/commerce_checkout_form_checkout']"));746 });747 casper.waitForSelector("input[name='permalink_text']",748 function success() {749 test.assertExists("input[name='permalink_text']");750 this.click("input[name='permalink_text']");751 },752 function fail() {753 test.assertExists("input[name='permalink_text']");754 });755 casper.waitForSelector(x("//a[normalize-space(text())='Permalink']"),756 function success() {757 test.assertExists(x("//a[normalize-space(text())='Permalink']"));758 this.click(x("//a[normalize-space(text())='Permalink']"));759 },760 function fail() {761 test.assertExists(x("//a[normalize-space(text())='Permalink']"));762 });763 casper.waitForSelector("input[name='permalink_text']",764 function success() {765 test.assertExists("input[name='permalink_text']");766 this.click("input[name='permalink_text']");767 },768 function fail() {769 test.assertExists("input[name='permalink_text']");770 });771 casper.waitForSelector("input[name='permalink_text']",772 function success() {773 test.assertExists("input[name='permalink_text']");774 this.click("input[name='permalink_text']");775 },776 function fail() {777 test.assertExists("input[name='permalink_text']");778 });779 casper.waitForSelector(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(3) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content",780 function success() {781 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(3) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");782 this.click(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(3) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");783 },784 function fail() {785 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(3) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");786 });787 casper.waitForSelector(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content > span > .goog-inline-block.kix-lineview-text-block > .kix-wordhtmlgenerator-word-node > .goog-inline-block",788 function success() {789 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content > span > .goog-inline-block.kix-lineview-text-block > .kix-wordhtmlgenerator-word-node > .goog-inline-block");790 this.click(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content > span > .goog-inline-block.kix-lineview-text-block > .kix-wordhtmlgenerator-word-node > .goog-inline-block");791 },792 function fail() {793 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content > span > .goog-inline-block.kix-lineview-text-block > .kix-wordhtmlgenerator-word-node > .goog-inline-block");794 });795 casper.waitForSelector("input[name='permalink_text']",796 function success() {797 test.assertExists("input[name='permalink_text']");798 this.click("input[name='permalink_text']");799 },800 function fail() {801 test.assertExists("input[name='permalink_text']");802 });803 casper.waitForSelector(x("//a[normalize-space(text())='Permalink']"),804 function success() {805 test.assertExists(x("//a[normalize-space(text())='Permalink']"));806 this.click(x("//a[normalize-space(text())='Permalink']"));807 },808 function fail() {809 test.assertExists(x("//a[normalize-space(text())='Permalink']"));810 });811 casper.waitForSelector("input[name='permalink_text']",812 function success() {813 test.assertExists("input[name='permalink_text']");814 this.click("input[name='permalink_text']");815 },816 function fail() {817 test.assertExists("input[name='permalink_text']");818 });819 casper.waitForSelector("input[name='permalink_text']",820 function success() {821 test.assertExists("input[name='permalink_text']");822 this.click("input[name='permalink_text']");823 },824 function fail() {825 test.assertExists("input[name='permalink_text']");826 });827 casper.waitForSelector(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content",828 function success() {829 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");830 this.click(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");831 },832 function fail() {833 test.assertExists(".kix-paginateddocumentplugin .kix-page.kix-page-paginated:nth-child(6) .kix-page-column > div:nth-child(1) > div > .kix-paragraphrenderer > .kix-lineview > .kix-lineview-content");834 });835 casper.waitForSelector("form#commerce-checkout-form-checkout input[type=submit][value='Continue to next step']",836 function success() {837 test.assertExists("form#commerce-checkout-form-checkout input[type=submit][value='Continue to next step']");838 this.click("form#commerce-checkout-form-checkout input[type=submit][value='Continue to next step']");839 },840 function fail() {841 test.assertExists("form#commerce-checkout-form-checkout input[type=submit][value='Continue to next step']");842 });843 /* submit form */844 casper.waitForSelector(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"),845 function success() {846 test.assertExists(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));847 this.click(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));848 },849 function fail() {850 test.assertExists(x("//a[@href='/accounts/2428863/applications/307879305/transactions#']"));851 });852 casper.waitForSelector(x("//a[normalize-space(text())='Overview']"),853 function success() {854 test.assertExists(x("//a[normalize-space(text())='Overview']"));855 this.click(x("//a[normalize-space(text())='Overview']"));856 },857 function fail() {858 test.assertExists(x("//a[normalize-space(text())='Overview']"));859 });860 casper.waitForSelector(".form-item.form-type-radio.form-item-commerce-payment-payment-method:nth-child(4) .option",861 function success() {862 test.assertExists(".form-item.form-type-radio.form-item-commerce-payment-payment-method:nth-child(4) .option");863 this.click(".form-item.form-type-radio.form-item-commerce-payment-payment-method:nth-child(4) .option");864 },865 function fail() {866 test.assertExists(".form-item.form-type-radio.form-item-commerce-payment-payment-method:nth-child(4) .option");867 });868 casper.waitForSelector("form#commerce-checkout-form-review input[name='commerce_payment[payment_method]']",869 function success() {870 test.assertExists("form#commerce-checkout-form-review input[name='commerce_payment[payment_method]']");871 this.click("form#commerce-checkout-form-review input[name='commerce_payment[payment_method]']");872 },873 function fail() {874 test.assertExists("form#commerce-checkout-form-review input[name='commerce_payment[payment_method]']");875 });876 casper.waitForSelector("form#commerce-checkout-form-review input#html5_1dhp2viu85as29q1c38109tfc44",877 function success() {878 test.assertExists("form#commerce-checkout-form-review input#html5_1dhp2viu85as29q1c38109tfc44");879 this.click("form#commerce-checkout-form-review input#html5_1dhp2viu85as29q1c38109tfc44");880 },881 function fail() {882 test.assertExists("form#commerce-checkout-form-review input#html5_1dhp2viu85as29q1c38109tfc44");883 });884 casper.waitForSelector(x("//a[normalize-space(text())='Add Files']"),885 function success() {886 test.assertExists(x("//a[normalize-space(text())='Add Files']"));887 this.click(x("//a[normalize-space(text())='Add Files']"));888 },889 function fail() {890 test.assertExists(x("//a[normalize-space(text())='Add Files']"));891 });892 casper.waitForSelector("form#commerce-checkout-form-review input[name='extra_pane__node__1985[termsofservice]']",893 function success() {894 test.assertExists("form#commerce-checkout-form-review input[name='extra_pane__node__1985[termsofservice]']");895 this.click("form#commerce-checkout-form-review input[name='extra_pane__node__1985[termsofservice]']");896 },897 function fail() {898 test.assertExists("form#commerce-checkout-form-review input[name='extra_pane__node__1985[termsofservice]']");899 });900 casper.waitForSelector("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']",901 function success() {902 test.assertExists("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");903 this.click("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");904 },905 function fail() {906 test.assertExists("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");907 });908 /* submit form */909 casper.waitForSelector("form#commerce-checkout-form-review input#html5_1dhp30uq6vlb1g8dp371ch8m6o4",910 function success() {911 test.assertExists("form#commerce-checkout-form-review input#html5_1dhp30uq6vlb1g8dp371ch8m6o4");912 this.click("form#commerce-checkout-form-review input#html5_1dhp30uq6vlb1g8dp371ch8m6o4");913 },914 function fail() {915 test.assertExists("form#commerce-checkout-form-review input#html5_1dhp30uq6vlb1g8dp371ch8m6o4");916 });917 casper.waitForSelector(x("//a[normalize-space(text())='Add Files']"),918 function success() {919 test.assertExists(x("//a[normalize-space(text())='Add Files']"));920 this.click(x("//a[normalize-space(text())='Add Files']"));921 },922 function fail() {923 test.assertExists(x("//a[normalize-space(text())='Add Files']"));924 });925 casper.waitForSelector("#o_1dhp31c9u17lksuakbh2ejj7b",926 function success() {927 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");928 this.click("#o_1dhp31c9u17lksuakbh2ejj7b");929 },930 function fail() {931 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");932 });933 casper.waitForSelector("#o_1dhp31c9u17lksuakbh2ejj7b",934 function success() {935 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");936 this.click("#o_1dhp31c9u17lksuakbh2ejj7b");937 },938 function fail() {939 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");940 });941 casper.waitForSelector("#o_1dhp31c9u17lksuakbh2ejj7b",942 function success() {943 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");944 this.click("#o_1dhp31c9u17lksuakbh2ejj7b");945 },946 function fail() {947 test.assertExists("#o_1dhp31c9u17lksuakbh2ejj7b");948 });949 casper.waitForSelector("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']",950 function success() {951 test.assertExists("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");952 this.click("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");953 },954 function fail() {955 test.assertExists("form#commerce-checkout-form-review input[type=submit][value='Continue to next step']");956 });957 /* submit form */958 casper.waitForSelector(".main-navigation__item:nth-child(1) .main-navigation__navbar-text",959 function success() {960 test.assertExists(".main-navigation__item:nth-child(1) .main-navigation__navbar-text");961 this.click(".main-navigation__item:nth-child(1) .main-navigation__navbar-text");962 },963 function fail() {964 test.assertExists(".main-navigation__item:nth-child(1) .main-navigation__navbar-text");965 });966 casper.run(function() {test.done();});...

Full Screen

Full Screen

waittask.spec.js

Source:waittask.spec.js Github

copy

Full Screen

...203 const addElement = tag => document.body.appendChild(document.createElement(tag));204 it('should immediately resolve promise if node exists', async({page, server}) => {205 await page.goto(server.EMPTY_PAGE);206 const frame = page.mainFrame();207 await frame.waitForSelector('*');208 await frame.evaluate(addElement, 'div');209 await frame.waitForSelector('div');210 });211 it('should work with removed MutationObserver', async({page, server}) => {212 await page.evaluate(() => delete window.MutationObserver);213 const [handle] = await Promise.all([214 page.waitForSelector('.zombo'),215 page.setContent(`<div class='zombo'>anything</div>`),216 ]);217 expect(await page.evaluate(x => x.textContent, handle)).toBe('anything');218 });219 it('should resolve promise when node is added', async({page, server}) => {220 await page.goto(server.EMPTY_PAGE);221 const frame = page.mainFrame();222 const watchdog = frame.waitForSelector('div');223 await frame.evaluate(addElement, 'br');224 await frame.evaluate(addElement, 'div');225 const eHandle = await watchdog;226 const tagName = await eHandle.getProperty('tagName').then(e => e.jsonValue());227 expect(tagName).toBe('DIV');228 });229 it('should work when node is added through innerHTML', async({page, server}) => {230 await page.goto(server.EMPTY_PAGE);231 const watchdog = page.waitForSelector('h3 div');232 await page.evaluate(addElement, 'span');233 await page.evaluate(() => document.querySelector('span').innerHTML = '<h3><div></div></h3>');234 await watchdog;235 });236 it('Page.waitForSelector is shortcut for main frame', async({page, server}) => {237 await page.goto(server.EMPTY_PAGE);238 await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);239 const otherFrame = page.frames()[1];240 const watchdog = page.waitForSelector('div');241 await otherFrame.evaluate(addElement, 'div');242 await page.evaluate(addElement, 'div');243 const eHandle = await watchdog;244 expect(eHandle.executionContext().frame()).toBe(page.mainFrame());245 });246 it('should run in specified frame', async({page, server}) => {247 await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);248 await utils.attachFrame(page, 'frame2', server.EMPTY_PAGE);249 const frame1 = page.frames()[1];250 const frame2 = page.frames()[2];251 const waitForSelectorPromise = frame2.waitForSelector('div');252 await frame1.evaluate(addElement, 'div');253 await frame2.evaluate(addElement, 'div');254 const eHandle = await waitForSelectorPromise;255 expect(eHandle.executionContext().frame()).toBe(frame2);256 });257 it('should throw when frame is detached', async({page, server}) => {258 await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);259 const frame = page.frames()[1];260 let waitError = null;261 const waitPromise = frame.waitForSelector('.box').catch(e => waitError = e);262 await utils.detachFrame(page, 'frame1');263 await waitPromise;264 expect(waitError).toBeTruthy();265 expect(waitError.message).toContain('waitForFunction failed: frame got detached.');266 });267 it('should survive cross-process navigation', async({page, server}) => {268 let boxFound = false;269 const waitForSelector = page.waitForSelector('.box').then(() => boxFound = true);270 await page.goto(server.EMPTY_PAGE);271 expect(boxFound).toBe(false);272 await page.reload();273 expect(boxFound).toBe(false);274 await page.goto(server.CROSS_PROCESS_PREFIX + '/grid.html');275 await waitForSelector;276 expect(boxFound).toBe(true);277 });278 it_fails_ffox('should wait for visible', async({page, server}) => {279 let divFound = false;280 const waitForSelector = page.waitForSelector('div', {visible: true}).then(() => divFound = true);281 await page.setContent(`<div style='display: none; visibility: hidden;'>1</div>`);282 expect(divFound).toBe(false);283 await page.evaluate(() => document.querySelector('div').style.removeProperty('display'));284 expect(divFound).toBe(false);285 await page.evaluate(() => document.querySelector('div').style.removeProperty('visibility'));286 expect(await waitForSelector).toBe(true);287 expect(divFound).toBe(true);288 });289 it_fails_ffox('should wait for visible recursively', async({page, server}) => {290 let divVisible = false;291 const waitForSelector = page.waitForSelector('div#inner', {visible: true}).then(() => divVisible = true);292 await page.setContent(`<div style='display: none; visibility: hidden;'><div id="inner">hi</div></div>`);293 expect(divVisible).toBe(false);294 await page.evaluate(() => document.querySelector('div').style.removeProperty('display'));295 expect(divVisible).toBe(false);296 await page.evaluate(() => document.querySelector('div').style.removeProperty('visibility'));297 expect(await waitForSelector).toBe(true);298 expect(divVisible).toBe(true);299 });300 it_fails_ffox('hidden should wait for visibility: hidden', async({page, server}) => {301 let divHidden = false;302 await page.setContent(`<div style='display: block;'></div>`);303 const waitForSelector = page.waitForSelector('div', {hidden: true}).then(() => divHidden = true);304 await page.waitForSelector('div'); // do a round trip305 expect(divHidden).toBe(false);306 await page.evaluate(() => document.querySelector('div').style.setProperty('visibility', 'hidden'));307 expect(await waitForSelector).toBe(true);308 expect(divHidden).toBe(true);309 });310 it_fails_ffox('hidden should wait for display: none', async({page, server}) => {311 let divHidden = false;312 await page.setContent(`<div style='display: block;'></div>`);313 const waitForSelector = page.waitForSelector('div', {hidden: true}).then(() => divHidden = true);314 await page.waitForSelector('div'); // do a round trip315 expect(divHidden).toBe(false);316 await page.evaluate(() => document.querySelector('div').style.setProperty('display', 'none'));317 expect(await waitForSelector).toBe(true);318 expect(divHidden).toBe(true);319 });320 it_fails_ffox('hidden should wait for removal', async({page, server}) => {321 await page.setContent(`<div></div>`);322 let divRemoved = false;323 const waitForSelector = page.waitForSelector('div', {hidden: true}).then(() => divRemoved = true);324 await page.waitForSelector('div'); // do a round trip325 expect(divRemoved).toBe(false);326 await page.evaluate(() => document.querySelector('div').remove());327 expect(await waitForSelector).toBe(true);328 expect(divRemoved).toBe(true);329 });330 it_fails_ffox('should return null if waiting to hide non-existing element', async({page, server}) => {331 const handle = await page.waitForSelector('non-existing', { hidden: true });332 expect(handle).toBe(null);333 });334 it('should respect timeout', async({page, server}) => {335 let error = null;336 await page.waitForSelector('div', {timeout: 10}).catch(e => error = e);337 expect(error).toBeTruthy();338 expect(error.message).toContain('waiting for selector "div" failed: timeout');339 expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);340 });341 it_fails_ffox('should have an error message specifically for awaiting an element to be hidden', async({page, server}) => {342 await page.setContent(`<div></div>`);343 let error = null;344 await page.waitForSelector('div', {hidden: true, timeout: 10}).catch(e => error = e);345 expect(error).toBeTruthy();346 expect(error.message).toContain('waiting for selector "div" to be hidden failed: timeout');347 });348 it_fails_ffox('should respond to node attribute mutation', async({page, server}) => {349 let divFound = false;350 const waitForSelector = page.waitForSelector('.zombo').then(() => divFound = true);351 await page.setContent(`<div class='notZombo'></div>`);352 expect(divFound).toBe(false);353 await page.evaluate(() => document.querySelector('div').className = 'zombo');354 expect(await waitForSelector).toBe(true);355 });356 it_fails_ffox('should return the element handle', async({page, server}) => {357 const waitForSelector = page.waitForSelector('.zombo');358 await page.setContent(`<div class='zombo'>anything</div>`);359 expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything');360 });361 it('should have correct stack trace for timeout', async({page, server}) => {362 let error;363 await page.waitForSelector('.zombo', {timeout: 10}).catch(e => error = e);364 expect(error.stack).toContain('waittask.spec.js');365 });366 });367 describe('Frame.waitForXPath', function() {368 const addElement = tag => document.body.appendChild(document.createElement(tag));369 it('should support some fancy xpath', async({page, server}) => {370 await page.setContent(`<p>red herring</p><p>hello world </p>`);371 const waitForXPath = page.waitForXPath('//p[normalize-space(.)="hello world"]');372 expect(await page.evaluate(x => x.textContent, await waitForXPath)).toBe('hello world ');373 });374 it('should respect timeout', async({page}) => {375 let error = null;376 await page.waitForXPath('//div', {timeout: 10}).catch(e => error = e);377 expect(error).toBeTruthy();...

Full Screen

Full Screen

secfit.test.js

Source:secfit.test.js Github

copy

Full Screen

...33 await page.goto(url);34 });35 // log in36 test("Log in", async () => {37 await page.waitForSelector("#btn-login-nav");38 await page.evaluate((selector) => {39 document.querySelector(selector).click();40 }, "#btn-login-nav");41 await page.waitForNavigation();42 await login(user);43 }, 25000);44});45// Exercises46describe("exercise page", () => {47 beforeAll(async () => {48 await page.goto(url)49 })50 //access exercise page51 test("access exercise page", async () =>{52 await page.waitForSelector("#btn-login-nav");53 await page.evaluate((selector) => {54 document.querySelector(selector).click();55 }, "#btn-login-nav");56 await page.waitForNavigation();57 await login(user);58 await page.waitForSelector("#nav-exercises");59 await page.evaluate((selector) => {60 document.querySelector(selector).click();61 }, "#nav-exercises");62 await page.waitForNavigation();63 await page.waitForSelector("#btn-create-exercise");64 })65 // new exercise66 test("create exercise", async () =>{67 await page.waitForSelector("#btn-create-exercise");68 await page.evaluate((selector) => {69 document.querySelector(selector).click();70 }, "#btn-create-exercise");71 await page.waitForNavigation();72 await page.waitForSelector("#inputName");73 await page.type("#inputName", exercise.name)74 await page.waitForSelector("#inputDescription");75 await page.type("#inputDescription", exercise.description)76 await page.waitForSelector("#inputUnit");77 await page.type("#inputUnit", exercise.unit)78 await page.waitForSelector("#btn-ok-exercise");79 await page.evaluate((selector) => {80 document.querySelector(selector).click();81 }, "#btn-ok-exercise");82 await page.waitForNavigation();83 await page.waitForSelector("#btn-create-exercise");84 85 }, 25000)86 // read exercise87 test("look at exercise", async () =>{88 await page.waitForSelector("#div-content");89 const exercises = await page.$$("a");90 await page.evaluate((field) => field.click(), exercises[exercises.length -1]);91 92 await page.waitForSelector("#inputName");93 const name = await page.evaluate(94 (field) => document.querySelector(field).value,95 "#inputName"96 );97 expect(name).toEqual(exercise.name);98 await page.waitForSelector("#inputDescription");99 const desc = await page.evaluate(100 (field) => document.querySelector(field).value,101 "#inputDescription"102 );103 expect(desc).toEqual(exercise.description);104 await page.waitForSelector("#inputUnit");105 const unit = await page.evaluate(106 (field) => document.querySelector(field).value,107 "#inputUnit"108 );109 expect(unit).toEqual(exercise.unit);110 }, 25000)111 // edit exercise112 test("edit exercise", async () =>{113 await page.evaluate((selector) => {114 document.querySelector(selector).click();115 }, "#btn-edit-exercise");116 117 await page.waitForSelector("#inputName");118 await page.evaluate(119 (field) => document.querySelector(field).value = "sit-ups",120 '#inputName'121 );122 await page.waitForSelector("#inputDescription");123 await page.evaluate(124 (field) => document.querySelector(field).value = "sit up and down",125 '#inputDescription'126 );127 128 await page.waitForSelector("#inputUnit");129 await page.evaluate(130 (field) => document.querySelector(field).value = "num",131 '#inputUnit'132 );133 await page.evaluate((selector) => {134 document.querySelector(selector).click();135 }, "#btn-ok-exercise");136 await page.waitForSelector("#btn-edit-exercise");137 }, 25000)138})139// Workouts140describe("workout page", () => {141 beforeAll(async () => {142 await page.goto(url)143 })144 //access workout page145 test("access workout page", async () =>{146 await page.waitForSelector("#btn-login-nav");147 await page.evaluate((selector) => {148 document.querySelector(selector).click();149 }, "#btn-login-nav");150 await page.waitForNavigation();151 await login(user);152 await page.waitForSelector("#btn-create-workout");153 })154 // new workout155 test("create workout", async () =>{156 await page.waitForSelector("#btn-create-workout");157 await page.evaluate((selector) => {158 document.querySelector(selector).click();159 }, "#btn-create-workout");160 await page.waitForNavigation();161 await page.waitForSelector("#inputName");162 await page.type("#inputName", workout.name)163 await page.waitForSelector("#inputDateTime");164 await page.type("#inputDateTime", String.fromCharCode(32));165 await page.type("#inputDateTime", String.fromCharCode(13));166 await page.evaluate((selector) => {167 document.querySelector(selector).click();168 }, "#btn-add-athelte");169 await page.waitForSelector("#inputSearchForUser");170 await page.type("#inputSearchForUser", "Annika");171 await page.evaluate((selector) => {172 document.querySelector(selector).click();173 }, '[value="Annika"]');174 await page.select('#inputVisibility', 'PU')175 await page.waitForSelector("#inputNotes");176 await page.type("#inputNotes", workout.notes);177 await page.select('select[name=type]', '4')178 179 await page.waitForSelector('input[name=sets]');180 await page.type('input[name=sets]', "1");181 await page.waitForSelector('[name=number]');182 await page.type('input[name=number]', "1");183 await page.waitForSelector("#btn-ok-workout");184 await page.evaluate((selector) => {185 document.querySelector(selector).click();186 }, "#btn-ok-workout");187 await page.waitForNavigation();188 await page.waitForSelector("#btn-create-workout");189 190 }, 25000)191 // read workout192 test("look at workout", async () =>{193 await page.waitForSelector("#div-content");194 const workouts = await page.$$(".workout");195 await page.evaluate((field) => field.click(), workouts[0]);196 197 await page.waitForSelector("#inputName");198 const name = await page.evaluate(199 (field) => document.querySelector(field).value,200 "#inputName"201 );202 expect(name).toEqual(workout.name);203 await page.waitForSelector("#inputNotes");204 const notes = await page.evaluate(205 (field) => document.querySelector(field).value,206 "#inputNotes"207 );208 expect(notes).toEqual(workout.notes);209 await page.waitForSelector("#inputOwner");210 const owner = await page.evaluate(211 (field) => document.querySelector(field).value,212 "#inputOwner"213 );214 expect(owner).toEqual("Anna");215 }, 25000)216 // edit workout217 test("edit workout", async () =>{218 await page.evaluate((selector) => {219 document.querySelector(selector).click();220 }, "#btn-edit-workout");221 222 await page.waitForSelector("#inputName");223 await page.evaluate(224 (field) => document.querySelector(field).value = "lame workout",225 '#inputName'226 );227 await page.waitForSelector("#inputDateTime");228 await page.type("#inputDateTime", String.fromCharCode(32));229 await page.type("#inputDateTime", String.fromCharCode(13));230 await page.select('#inputVisibility', 'PR')231 await page.waitForSelector("#inputNotes");232 await page.evaluate(233 (field) => document.querySelector(field).value = "new notes",234 '#inputNotes'235 );236 await page.evaluate((selector) => {237 document.querySelector(selector).click();238 }, "#btn-ok-workout");239 await page.waitForSelector("#btn-edit-workout");240 }, 25000)241 // delete workout242 test("delete workout", async () =>{243 await page.evaluate((selector) => {244 document.querySelector(selector).click();245 }, "#btn-edit-workout");246 247 await page.evaluate((selector) => {248 document.querySelector(selector).click();249 }, "#btn-delete-workout");250 await page.waitForSelector("#btn-create-workout");251 }, 25000)252})253// Athlete page254describe("athlete page", () => {255 beforeAll(async () => {256 await page.goto(url)257 })258 //access athlete page259 test("access athlete page", async () =>{260 await page.waitForSelector("#btn-login-nav");261 await page.evaluate((selector) => {262 document.querySelector(selector).click();263 }, "#btn-login-nav");264 await page.waitForNavigation();265 await login(user);266 await page.waitForSelector("#nav-myathletes");267 await page.evaluate((selector) => {268 document.querySelector(selector).click();269 }, "#nav-myathletes");270 await page.waitForNavigation();271 await page.waitForSelector("#button-submit-roster");272 })273 // new athlete274 test("add athlete", async () =>{275 await page.waitForSelector("#button-submit-roster");276 await page.waitForSelector("input[name='athlete']");277 await page.type("input[name='athlete']", "Annika")278 await page.evaluate((selector) => {279 document.querySelector(selector).click();280 }, '.btn-success');281 await page.waitForSelector(".btn-danger");282 await page.evaluate((selector) => {283 document.querySelector(selector).click();284 }, '#button-submit-roster');285 await page.waitForSelector("#controls");286 }, 25000)287})288// Coach page289describe("coach page", () => {290 beforeAll(async () => {291 await page.goto(url)292 })293 //access coach page294 test("access coach page", async () =>{295 await page.waitForSelector("#btn-login-nav");296 await page.evaluate((selector) => {297 document.querySelector(selector).click();298 }, "#btn-login-nav");299 await page.waitForNavigation();300 await login(user);301 await page.waitForSelector("#nav-mycoach");302 await page.evaluate((selector) => {303 document.querySelector(selector).click();304 }, "#nav-mycoach");305 await page.waitForNavigation();306 await page.waitForSelector("#button-edit-coach");307 }, 25000)308 // new coach309 test("add coach", async () =>{310 await page.waitForSelector("#button-edit-coach");311 await page.evaluate((selector) => {312 document.querySelector(selector).click();313 }, '#button-edit-coach');314 await page.waitForSelector("input[name='coach']");315 await page.type("input[name='coach']", "Annika")316 await page.evaluate((selector) => {317 document.querySelector(selector).click();318 }, '#button-set-coach');319 await page.waitForSelector("#button-edit-coach");320 const coach = await page.evaluate(321 (field) => document.querySelector(field).value,322 'input[name="coach"]'323 );324 expect(coach).toEqual("Annika");325 }, 25000)326})327describe("Profile functionality", () => {328 beforeAll(async () => {329 await page.goto(url);330 });331 test("access to profile page", async () => {332 await page.waitForSelector("#btn-login-nav");333 await page.evaluate((selector) => {334 document.querySelector(selector).click();335 }, "#btn-login-nav");336 await page.waitForNavigation();337 await login(user);338 await page.waitForSelector("#nav-profile");339 await page.evaluate((selector) => {340 document.querySelector(selector).click();341 }, "#nav-profile");342 await page.waitForNavigation();343 await page.waitForSelector("#form-profile");344 }, 25000);345 // Read profile info346 test("read profile info", async () => {347 await page.waitForSelector('input[name="username"]');348 const username = await page.evaluate(349 (field) => document.querySelector(field).value,350 "#inputUsername"351 );352 expect(username).toEqual(user.username);353 await page.waitForSelector('input[name="email"]');354 const email = await page.evaluate(355 (field) => document.querySelector(field).value,356 'input[name="email"]'357 );358 expect(email).toEqual(user.email);359 await page.waitForSelector('input[name="phone_number"]');360 const phone_number = await page.evaluate(361 (field) => document.querySelector(field).value,362 'input[name="phone_number"]'363 );364 expect(phone_number).toEqual(user.phone_numer);365 await page.waitForSelector('input[name="street_address"]');366 const street_address = await page.evaluate(367 (field) => document.querySelector(field).value,368 'input[name="street_address"]'369 );370 expect(street_address).toEqual(user.street_name);371 await page.waitForSelector('input[name="city"]');372 const city = await page.evaluate(373 (field) => document.querySelector(field).value,374 'input[name="city"]'375 );376 expect(city).toEqual(user.city);377 await page.waitForSelector('input[name="country"]');378 const country = await page.evaluate(379 (field) => document.querySelector(field).value,380 'input[name="country"]'381 );382 expect(country).toEqual(user.country);383 }, 20000);384 // Cancel edit profile385 test("cancel edit email", async () => {386 await page.waitForSelector("#btn-edit-profile");387 await page.evaluate((selector) => {388 document.querySelector(selector).click();389 }, "#btn-edit-profile");390 console.log("clicked edit button")391 await page.waitForSelector("#btn-cancel-edit");392 await page.evaluate((selector) => {393 document.querySelector(selector).click();394 }, "#btn-cancel-edit");395 console.log("clicked cancel edit button")396 await page.waitForSelector("#btn-edit-profile");397 console.log("cancelled edit")398 })399 // Edit profile400 test("edit profile", async () => {401 await page.waitForSelector("#btn-edit-profile");402 await page.evaluate((selector) => {403 document.querySelector(selector).click();404 }, "#btn-edit-profile");405 console.log("clicked edit button")406 await page.waitForSelector('input[name="username"]');407 await page.evaluate(408 (field) => document.querySelector(field).value = "Anita",409 "#inputUsername"410 );411 await page.waitForSelector('input[name="email"]');412 await page.evaluate(413 (field) => document.querySelector(field).value = "new@email.com",414 'input[name="email"]'415 );416 await page.waitForSelector('input[name="phone_number"]');417 await page.evaluate(418 (field) => document.querySelector(field).value = "123",419 'input[name="phone_number"]'420 );421 await page.waitForSelector('input[name="street_address"]');422 await page.evaluate(423 (field) => document.querySelector(field).value = "munkegata 36",424 'input[name="street_address"]'425 );426 await page.waitForSelector('input[name="city"]');427 await page.evaluate(428 (field) => document.querySelector(field).value = "Trondheim",429 'input[name="city"]'430 );431 await page.waitForSelector('input[name="country"]');432 await page.evaluate(433 (field) => document.querySelector(field).value = "Sweden",434 'input[name="country"]'435 );436 await page.evaluate((selector) => {437 document.querySelector(selector).click();438 }, "#btn-confirm-edit");439 console.log("clicked confirm edit button")440 await page.waitForSelector('input[name="username"]');441 const username = await page.evaluate(442 (field) => document.querySelector(field).value,443 "#inputUsername"444 );445 expect(username).toEqual("Anita");446 })447 // cancel delete profile448 test("cancel delete profile", async () => {449 await page.waitForSelector("#btn-edit-profile");450 await page.evaluate((selector) => {451 document.querySelector(selector).click();452 }, "#btn-edit-profile");453 console.log("clicked edit profile button")454 await page.waitForSelector("#btn-initiate-delete");455 await page.evaluate((selector) => {456 document.querySelector(selector).click();457 }, "#btn-initiate-delete");458 console.log("clicked delete profile button")459 await page.waitForSelector("#btn-cancel-delete");460 await page.evaluate((selector) => {461 document.querySelector(selector).click();462 }, "#btn-cancel-delete");463 console.log("clicked cancel delete profile button")464 await page.waitForSelector('input[name="username"]');465 })466 //delete profile467 test("delete profile", async () => {468 await page.waitForSelector("#btn-edit-profile");469 await page.evaluate((selector) => {470 document.querySelector(selector).click();471 }, "#btn-edit-profile");472 console.log("clicked edit profile button")473 await page.waitForSelector("#btn-initiate-delete");474 await page.evaluate((selector) => {475 document.querySelector(selector).click();476 }, "#btn-initiate-delete");477 console.log("clicked delete profile button")478 await page.waitForSelector("#btn-delete-user");479 await page.evaluate((selector) => {480 document.querySelector(selector).click();481 }, "#btn-delete-user");482 console.log("clicked confirm delete profile button")483 await page.waitForNavigation();484 await page.waitForSelector("#btn-login-nav");485 console.log("user deleted")486 })487});488describe("Cleanup", () => {489 beforeAll(async () => {490 await page.goto(url);491 });492 test("access to profile page", async () => {493 await page.waitForSelector("#btn-login-nav");494 await page.evaluate((selector) => {495 document.querySelector(selector).click();496 }, "#btn-login-nav");497 await page.waitForNavigation();498 await login(user2);499 await page.waitForSelector("#nav-profile");500 await page.evaluate((selector) => {501 document.querySelector(selector).click();502 }, "#nav-profile");503 await page.waitForNavigation();504 await page.waitForSelector("#form-profile");505 }, 25000);506 507 //delete profile508 test("delete profile", async () => {509 await page.waitForSelector("#btn-edit-profile");510 await page.evaluate((selector) => {511 document.querySelector(selector).click();512 }, "#btn-edit-profile");513 console.log("clicked edit profile button")514 await page.waitForSelector("#btn-initiate-delete");515 await page.evaluate((selector) => {516 document.querySelector(selector).click();517 }, "#btn-initiate-delete");518 console.log("clicked delete profile button")519 await page.waitForSelector("#btn-delete-user");520 await page.evaluate((selector) => {521 document.querySelector(selector).click();522 }, "#btn-delete-user");523 console.log("clicked confirm delete profile button")524 await page.waitForNavigation();525 await page.waitForSelector("#btn-login-nav");526 console.log("user deleted")527 })...

Full Screen

Full Screen

to_crawl_page_take.js

Source:to_crawl_page_take.js Github

copy

Full Screen

...31 const page = await browser.newPage()32 await page.emulate(devices['iPhone X'])33 // await page.emulate(devices['iPad Pro'])34 await page.goto('https://h.bilibili.com/ywh/h5/home#/photo', { waitUntil: 'networkidle2' })35 await page.waitForSelector('.img-container')36 await (async function () {37 for (let j = 0; j < 4; j++) {38 await page.waitForSelector('.img-container')39 for (let i = 0; i < 10; i++) {40 await page.keyboard.press('ArrowDown')41 }42 }43 })();44 await page.waitForSelector('.img-container')45 await (async function () {46 for (let j = 0; j < 4; j++) {47 await page.waitForSelector('.img-container')48 for (let i = 0; i < 10; i++) {49 await page.keyboard.press('ArrowDown')50 }51 }52 })();53 await page.waitForSelector('.img-container')54 await (async function () {55 for (let j = 0; j < 4; j++) {56 await page.waitForSelector('.img-container')57 for (let i = 0; i < 10; i++) {58 await page.keyboard.press('ArrowDown')59 }60 }61 })();62 await page.waitForSelector('.img-container')63 await (async function () {64 for (let j = 0; j < 4; j++) {65 await page.waitForSelector('.img-container')66 for (let i = 0; i < 10; i++) {67 await page.keyboard.press('ArrowDown')68 }69 }70 })();71 await page.waitForSelector('.img-container')72 await (async function () {73 for (let j = 0; j < 4; j++) {74 await page.waitForSelector('.img-container')75 for (let i = 0; i < 10; i++) {76 await page.keyboard.press('ArrowDown')77 }78 }79 })();80 await page.waitForSelector('.img-container')81 await (async function () {82 for (let j = 0; j < 4; j++) {83 await page.waitForSelector('.img-container')84 for (let i = 0; i < 10; i++) {85 await page.keyboard.press('ArrowDown')86 }87 }88 })();89 await page.waitForSelector('.img-container')90 await (async function () {91 for (let j = 0; j < 4; j++) {92 await page.waitForSelector('.img-container')93 for (let i = 0; i < 10; i++) {94 await page.keyboard.press('ArrowDown')95 }96 }97 })();98 await page.waitForSelector('.img-container')99 await (async function () {100 for (let j = 0; j < 4; j++) {101 await page.waitForSelector('.img-container')102 for (let i = 0; i < 10; i++) {103 await page.keyboard.press('ArrowDown')104 }105 }106 })();107 await page.waitForSelector('.img-container')108 await (async function () {109 for (let j = 0; j < 4; j++) {110 await page.waitForSelector('.img-container')111 for (let i = 0; i < 10; i++) {112 await page.keyboard.press('ArrowDown')113 }114 }115 })();116 await page.waitForSelector('.img-container')117 await (async function () {118 for (let j = 0; j < 4; j++) {119 await page.waitForSelector('.img-container')120 for (let i = 0; i < 10; i++) {121 await page.keyboard.press('ArrowDown')122 }123 }124 })();125 await page.waitForSelector('.img-container')126 await (async function () {127 for (let j = 0; j < 4; j++) {128 await page.waitForSelector('.img-container')129 for (let i = 0; i < 10; i++) {130 await page.keyboard.press('ArrowDown')131 }132 }133 })();134 await page.waitForSelector('.img-container')135 await (async function () {136 for (let j = 0; j < 4; j++) {137 await page.waitForSelector('.img-container')138 for (let i = 0; i < 10; i++) {139 await page.keyboard.press('ArrowDown')140 }141 }142 })();143 await page.waitForSelector('.img-container')144 await (async function () {145 for (let j = 0; j < 4; j++) {146 await page.waitForSelector('.img-container')147 for (let i = 0; i < 10; i++) {148 await page.keyboard.press('ArrowDown')149 }150 }151 })();152 await page.waitForSelector('.img-container')153 await (async function () {154 for (let j = 0; j < 4; j++) {155 await page.waitForSelector('.img-container')156 for (let i = 0; i < 10; i++) {157 await page.keyboard.press('ArrowDown')158 }159 }160 })();161 await page.waitForSelector('.img-container')162 await (async function () {163 for (let j = 0; j < 4; j++) {164 await page.waitForSelector('.img-container')165 for (let i = 0; i < 10; i++) {166 await page.keyboard.press('ArrowDown')167 }168 }169 })();170 await page.waitForSelector('.img-container')171 await (async function () {172 for (let j = 0; j < 4; j++) {173 await page.waitForSelector('.img-container')174 for (let i = 0; i < 10; i++) {175 await page.keyboard.press('ArrowDown')176 }177 }178 })();179 await page.waitForSelector('.img-container')180 await (async function () {181 for (let j = 0; j < 4; j++) {182 await page.waitForSelector('.img-container')183 for (let i = 0; i < 10; i++) {184 await page.keyboard.press('ArrowDown')185 }186 }187 })();188 await page.waitForSelector('.img-container')189 await (async function () {190 for (let j = 0; j < 4; j++) {191 await page.waitForSelector('.img-container')192 for (let i = 0; i < 10; i++) {193 await page.keyboard.press('ArrowDown')194 }195 }196 })();197 await page.waitForSelector('.img-container')198 await (async function () {199 for (let j = 0; j < 4; j++) {200 await page.waitForSelector('.img-container')201 for (let i = 0; i < 10; i++) {202 await page.keyboard.press('ArrowDown')203 }204 }205 })();206 await page.waitForSelector('.img-container')207 await (async function () {208 for (let j = 0; j < 4; j++) {209 await page.waitForSelector('.img-container')210 for (let i = 0; i < 10; i++) {211 await page.keyboard.press('ArrowDown')212 }213 }214 })();215 await page.waitForSelector('.img-container')216 await (async function () {217 for (let j = 0; j < 4; j++) {218 await page.waitForSelector('.img-container')219 for (let i = 0; i < 10; i++) {220 await page.keyboard.press('ArrowDown')221 }222 }223 })();224 await page.waitForSelector('.img-container')225 await (async function () {226 for (let j = 0; j < 4; j++) {227 await page.waitForSelector('.img-container')228 for (let i = 0; i < 10; i++) {229 await page.keyboard.press('ArrowDown')230 }231 }232 })();233 await page.waitForSelector('.img-container')234 await (async function () {235 for (let j = 0; j < 4; j++) {236 await page.waitForSelector('.img-container')237 for (let i = 0; i < 10; i++) {238 await page.keyboard.press('ArrowDown')239 }240 }241 })();242 await page.waitForSelector('.img-container')243 await (async function () {244 for (let j = 0; j < 4; j++) {245 await page.waitForSelector('.img-container')246 for (let i = 0; i < 10; i++) {247 await page.keyboard.press('ArrowDown')248 }249 }250 })();251 await page.waitForSelector('.img-container')252 await (async function () {253 for (let j = 0; j < 4; j++) {254 await page.waitForSelector('.img-container')255 for (let i = 0; i < 10; i++) {256 await page.keyboard.press('ArrowDown')257 }258 }259 })();260 await page.waitForSelector('.img-container')261 await (async function () {262 for (let j = 0; j < 4; j++) {263 await page.waitForSelector('.img-container')264 for (let i = 0; i < 10; i++) {265 await page.keyboard.press('ArrowDown')266 }267 }268 })();269 await page.waitForSelector('.img-container')270 await (async function () {271 for (let j = 0; j < 4; j++) {272 await page.waitForSelector('.img-container')273 for (let i = 0; i < 10; i++) {274 await page.keyboard.press('ArrowDown')275 }276 }277 })();278 await page.waitForSelector('.img-container')279 await (async function () {280 for (let j = 0; j < 4; j++) {281 await page.waitForSelector('.img-container')282 for (let i = 0; i < 10; i++) {283 await page.keyboard.press('ArrowDown')284 }285 }286 })();287 await page.waitForSelector('.img-container')288 await (async function () {289 for (let j = 0; j < 4; j++) {290 await page.waitForSelector('.img-container')291 for (let i = 0; i < 10; i++) {292 await page.keyboard.press('ArrowDown')293 }294 }295 })();296 await page.waitForSelector('.img-container')297 await (async function () {298 for (let j = 0; j < 4; j++) {299 await page.waitForSelector('.img-container')300 for (let i = 0; i < 10; i++) {301 await page.keyboard.press('ArrowDown')302 }303 }304 })();305 await page.waitForSelector('.img-container')306 await (async function () {307 for (let j = 0; j < 4; j++) {308 await page.waitForSelector('.img-container')309 for (let i = 0; i < 10; i++) {310 await page.keyboard.press('ArrowDown')311 }312 }313 })();314 await page.waitForSelector('.img-container')315 await (async function () {316 for (let j = 0; j < 4; j++) {317 await page.waitForSelector('.img-container')318 for (let i = 0; i < 10; i++) {319 await page.keyboard.press('ArrowDown')320 }321 }322 })();323 await page.waitForSelector('.img-container')324 await (async function () {325 for (let j = 0; j < 4; j++) {326 await page.waitForSelector('.img-container')327 for (let i = 0; i < 10; i++) {328 await page.keyboard.press('ArrowDown')329 }330 }331 })();332 await page.waitForSelector('.img-container')333 await (async function () {334 for (let j = 0; j < 4; j++) {335 await page.waitForSelector('.img-container')336 for (let i = 0; i < 10; i++) {337 await page.keyboard.press('ArrowDown')338 }339 }340 })();341 await page.waitForSelector('.img-container')342 await (async function () {343 for (let j = 0; j < 4; j++) {344 await page.waitForSelector('.img-container')345 for (let i = 0; i < 10; i++) {346 await page.keyboard.press('ArrowDown')347 }348 }349 })();350 await page.waitForSelector('.img-container')351 await (async function () {352 for (let j = 0; j < 4; j++) {353 await page.waitForSelector('.img-container')354 for (let i = 0; i < 10; i++) {355 await page.keyboard.press('ArrowDown')356 }357 }358 })();359 await page.waitForSelector('.img-container')360 await (async function () {361 for (let j = 0; j < 4; j++) {362 await page.waitForSelector('.img-container')363 for (let i = 0; i < 10; i++) {364 await page.keyboard.press('ArrowDown')365 }366 }367 })();368 await page.waitForSelector('.img-container')369 await (async function () {370 for (let j = 0; j < 4; j++) {371 await page.waitForSelector('.img-container')372 for (let i = 0; i < 10; i++) {373 await page.keyboard.press('ArrowDown')374 }375 }376 })();377 await page.waitForSelector('.img-container')378 await (async function () {379 for (let j = 0; j < 4; j++) {380 await page.waitForSelector('.img-container')381 for (let i = 0; i < 10; i++) {382 await page.keyboard.press('ArrowDown')383 }384 }385 })();386 await page.waitForSelector('.img-container')387 await (async function () {388 for (let j = 0; j < 4; j++) {389 await page.waitForSelector('.img-container')390 for (let i = 0; i < 10; i++) {391 await page.keyboard.press('ArrowDown')392 }393 }394 })();395 await page.waitForSelector('.img-container')396 await (async function () {397 for (let j = 0; j < 4; j++) {398 await page.waitForSelector('.img-container')399 for (let i = 0; i < 10; i++) {400 await page.keyboard.press('ArrowDown')401 }402 }403 })();404 await page.waitForSelector('.img-container')405 await (async function () {406 for (let j = 0; j < 4; j++) {407 await page.waitForSelector('.img-container')408 for (let i = 0; i < 10; i++) {409 await page.keyboard.press('ArrowDown')410 }411 }412 })();413 await page.waitForSelector('.img-container')414 await (async function () {415 for (let j = 0; j < 4; j++) {416 await page.waitForSelector('.img-container')417 for (let i = 0; i < 10; i++) {418 await page.keyboard.press('ArrowDown')419 }420 }421 })();422 await page.waitForSelector('.img-container')423 await (async function () {424 for (let j = 0; j < 4; j++) {425 await page.waitForSelector('.img-container')426 for (let i = 0; i < 10; i++) {427 await page.keyboard.press('ArrowDown')428 }429 }430 })();431 await page.waitForSelector('.img-container')432 await (async function () {433 for (let j = 0; j < 4; j++) {434 await page.waitForSelector('.img-container')435 for (let i = 0; i < 10; i++) {436 await page.keyboard.press('ArrowDown')437 }438 }439 })();440 await page.waitForSelector('.img-container')441 await (async function () {442 for (let j = 0; j < 4; j++) {443 await page.waitForSelector('.img-container')444 for (let i = 0; i < 10; i++) {445 await page.keyboard.press('ArrowDown')446 }447 }448 })();449 await page.waitForSelector('.img-container')450 await page.waitForSelector('.img-container')451 await page.waitForSelector('.img-container')452 await page.waitForSelector('.img-container')453 await page.waitForSelector('.img-container')454 await page.waitForSelector('img')455 await page.waitForSelector('img')456 await page.waitForSelector('img')457 await page.waitForSelector('img')458 await page.waitForSelector('img')459 await page.waitForSelector('img')460 await page.waitForSelector('img')461 await page.waitForSelector('img')462 await page.waitForSelector('img')463 await page.waitForSelector('img')464 await page.waitForSelector('img')465 await page.waitForSelector('.waterfall-item a')466 let link = await page.$$eval('.waterfall-item a', elements => {467 let a = []468 elements.forEach(e => {469 let h = e.href.split('/')470 let obj = {471 mid: h[h.length - 1],472 href: e.href473 }474 a.push(obj)475 })476 return a477 }).then(res => {478 return res479 })480 // 图片481 await page.waitForSelector('.img-container')482 let img = await page.$$eval('.img-container', elements => {483 484 let a = []485 elements.forEach(e => {486 let b = e.style.backgroundImage.split('url("')[1]487 let r = b.split('")')[0]488 a.push(r)489 })490 491 return a492 }).then(res => {493 return res494 })495 // 多P496 // await page.waitForSelector('.counts')497 // let mul = await page.$$eval('.counts', elements => {498 499 // let a = []500 // elements.forEach(e => {501 // a.push(e.innerText)502 // })503 504 // return a505 // }).then(res => {506 // return res507 // })508 // 标题509 await page.waitForSelector('.title')510 let title = await page.$$eval('.title', elements => {511 512 let a = []513 elements.forEach(e => {514 a.push(e.innerText)515 })516 517 return a518 }).then(res => {519 return res520 })521 // logo522 await page.waitForSelector('i img')523 let logo = await page.$$eval('i img', elements => {524 525 let a = []526 elements.forEach(e => {527 a.push(e.src)528 })529 530 return a531 }).then(res => {532 return res533 })534 // name535 await page.waitForSelector('span')536 let name = await page.$$eval('span', elements => {537 538 let a = []539 elements.forEach(e => {540 a.push(e.innerText)541 })542 543 return a544 }).then(res => {545 return res546 })547 let page_take = []548 for (let i = 0; i < link.length; i++) {549 let location = `E:/VScode/bilibili/bilibili_data/album_data/take_data/${link[i].mid}/`...

Full Screen

Full Screen

to_crawl_page_draw.js

Source:to_crawl_page_draw.js Github

copy

Full Screen

...31 const page = await browser.newPage()32 await page.emulate(devices['iPhone X'])33 // await page.emulate(devices['iPad Pro'])34 await page.goto('https://h.bilibili.com/ywh/h5/home#/draw', { waitUntil: 'networkidle2' })35 await page.waitForSelector('.img-container')36 await (async function () {37 for (let j = 0; j < 4; j++) {38 await page.waitForSelector('.img-container')39 for (let i = 0; i < 10; i++) {40 await page.keyboard.press('ArrowDown')41 }42 }43 })();44 await page.waitForSelector('.img-container')45 await (async function () {46 for (let j = 0; j < 4; j++) {47 await page.waitForSelector('.img-container')48 for (let i = 0; i < 10; i++) {49 await page.keyboard.press('ArrowDown')50 }51 }52 })();53 await page.waitForSelector('.img-container')54 await (async function () {55 for (let j = 0; j < 4; j++) {56 await page.waitForSelector('.img-container')57 for (let i = 0; i < 10; i++) {58 await page.keyboard.press('ArrowDown')59 }60 }61 })();62 await page.waitForSelector('.img-container')63 await (async function () {64 for (let j = 0; j < 4; j++) {65 await page.waitForSelector('.img-container')66 for (let i = 0; i < 10; i++) {67 await page.keyboard.press('ArrowDown')68 }69 }70 })();71 await page.waitForSelector('.img-container')72 await (async function () {73 for (let j = 0; j < 4; j++) {74 await page.waitForSelector('.img-container')75 for (let i = 0; i < 10; i++) {76 await page.keyboard.press('ArrowDown')77 }78 }79 })();80 await page.waitForSelector('.img-container')81 await (async function () {82 for (let j = 0; j < 4; j++) {83 await page.waitForSelector('.img-container')84 for (let i = 0; i < 10; i++) {85 await page.keyboard.press('ArrowDown')86 }87 }88 })();89 await page.waitForSelector('.img-container')90 await (async function () {91 for (let j = 0; j < 4; j++) {92 await page.waitForSelector('.img-container')93 for (let i = 0; i < 10; i++) {94 await page.keyboard.press('ArrowDown')95 }96 }97 })();98 await page.waitForSelector('.img-container')99 await (async function () {100 for (let j = 0; j < 4; j++) {101 await page.waitForSelector('.img-container')102 for (let i = 0; i < 10; i++) {103 await page.keyboard.press('ArrowDown')104 }105 }106 })();107 await page.waitForSelector('.img-container')108 await (async function () {109 for (let j = 0; j < 4; j++) {110 await page.waitForSelector('.img-container')111 for (let i = 0; i < 10; i++) {112 await page.keyboard.press('ArrowDown')113 }114 }115 })();116 await page.waitForSelector('.img-container')117 await (async function () {118 for (let j = 0; j < 4; j++) {119 await page.waitForSelector('.img-container')120 for (let i = 0; i < 10; i++) {121 await page.keyboard.press('ArrowDown')122 }123 }124 })();125 await page.waitForSelector('.img-container')126 await (async function () {127 for (let j = 0; j < 4; j++) {128 await page.waitForSelector('.img-container')129 for (let i = 0; i < 10; i++) {130 await page.keyboard.press('ArrowDown')131 }132 }133 })();134 await page.waitForSelector('.img-container')135 await (async function () {136 for (let j = 0; j < 4; j++) {137 await page.waitForSelector('.img-container')138 for (let i = 0; i < 10; i++) {139 await page.keyboard.press('ArrowDown')140 }141 }142 })();143 await page.waitForSelector('.img-container')144 await (async function () {145 for (let j = 0; j < 4; j++) {146 await page.waitForSelector('.img-container')147 for (let i = 0; i < 10; i++) {148 await page.keyboard.press('ArrowDown')149 }150 }151 })();152 await page.waitForSelector('.img-container')153 await (async function () {154 for (let j = 0; j < 4; j++) {155 await page.waitForSelector('.img-container')156 for (let i = 0; i < 10; i++) {157 await page.keyboard.press('ArrowDown')158 }159 }160 })();161 await page.waitForSelector('.img-container')162 await (async function () {163 for (let j = 0; j < 4; j++) {164 await page.waitForSelector('.img-container')165 for (let i = 0; i < 10; i++) {166 await page.keyboard.press('ArrowDown')167 }168 }169 })();170 await page.waitForSelector('.img-container')171 await (async function () {172 for (let j = 0; j < 4; j++) {173 await page.waitForSelector('.img-container')174 for (let i = 0; i < 10; i++) {175 await page.keyboard.press('ArrowDown')176 }177 }178 })();179 await page.waitForSelector('.img-container')180 await (async function () {181 for (let j = 0; j < 4; j++) {182 await page.waitForSelector('.img-container')183 for (let i = 0; i < 10; i++) {184 await page.keyboard.press('ArrowDown')185 }186 }187 })();188 await page.waitForSelector('.img-container')189 await (async function () {190 for (let j = 0; j < 4; j++) {191 await page.waitForSelector('.img-container')192 for (let i = 0; i < 10; i++) {193 await page.keyboard.press('ArrowDown')194 }195 }196 })();197 await page.waitForSelector('.img-container')198 await (async function () {199 for (let j = 0; j < 4; j++) {200 await page.waitForSelector('.img-container')201 for (let i = 0; i < 10; i++) {202 await page.keyboard.press('ArrowDown')203 }204 }205 })();206 await page.waitForSelector('.img-container')207 await (async function () {208 for (let j = 0; j < 4; j++) {209 await page.waitForSelector('.img-container')210 for (let i = 0; i < 10; i++) {211 await page.keyboard.press('ArrowDown')212 }213 }214 })();215 await page.waitForSelector('.img-container')216 await (async function () {217 for (let j = 0; j < 4; j++) {218 await page.waitForSelector('.img-container')219 for (let i = 0; i < 10; i++) {220 await page.keyboard.press('ArrowDown')221 }222 }223 })();224 await page.waitForSelector('.img-container')225 await (async function () {226 for (let j = 0; j < 4; j++) {227 await page.waitForSelector('.img-container')228 for (let i = 0; i < 10; i++) {229 await page.keyboard.press('ArrowDown')230 }231 }232 })();233 await page.waitForSelector('.img-container')234 await (async function () {235 for (let j = 0; j < 4; j++) {236 await page.waitForSelector('.img-container')237 for (let i = 0; i < 10; i++) {238 await page.keyboard.press('ArrowDown')239 }240 }241 })();242 await page.waitForSelector('.img-container')243 await (async function () {244 for (let j = 0; j < 4; j++) {245 await page.waitForSelector('.img-container')246 for (let i = 0; i < 10; i++) {247 await page.keyboard.press('ArrowDown')248 }249 }250 })();251 await page.waitForSelector('.img-container')252 await (async function () {253 for (let j = 0; j < 4; j++) {254 await page.waitForSelector('.img-container')255 for (let i = 0; i < 10; i++) {256 await page.keyboard.press('ArrowDown')257 }258 }259 })();260 await page.waitForSelector('.img-container')261 await (async function () {262 for (let j = 0; j < 4; j++) {263 await page.waitForSelector('.img-container')264 for (let i = 0; i < 10; i++) {265 await page.keyboard.press('ArrowDown')266 }267 }268 })();269 await page.waitForSelector('.img-container')270 await (async function () {271 for (let j = 0; j < 4; j++) {272 await page.waitForSelector('.img-container')273 for (let i = 0; i < 10; i++) {274 await page.keyboard.press('ArrowDown')275 }276 }277 })();278 await page.waitForSelector('.img-container')279 await (async function () {280 for (let j = 0; j < 4; j++) {281 await page.waitForSelector('.img-container')282 for (let i = 0; i < 10; i++) {283 await page.keyboard.press('ArrowDown')284 }285 }286 })();287 await page.waitForSelector('.img-container')288 await (async function () {289 for (let j = 0; j < 4; j++) {290 await page.waitForSelector('.img-container')291 for (let i = 0; i < 10; i++) {292 await page.keyboard.press('ArrowDown')293 }294 }295 })();296 await page.waitForSelector('.img-container')297 await (async function () {298 for (let j = 0; j < 4; j++) {299 await page.waitForSelector('.img-container')300 for (let i = 0; i < 10; i++) {301 await page.keyboard.press('ArrowDown')302 }303 }304 })();305 await page.waitForSelector('.img-container')306 await (async function () {307 for (let j = 0; j < 4; j++) {308 await page.waitForSelector('.img-container')309 for (let i = 0; i < 10; i++) {310 await page.keyboard.press('ArrowDown')311 }312 }313 })();314 await page.waitForSelector('.img-container')315 await (async function () {316 for (let j = 0; j < 4; j++) {317 await page.waitForSelector('.img-container')318 for (let i = 0; i < 10; i++) {319 await page.keyboard.press('ArrowDown')320 }321 }322 })();323 await page.waitForSelector('.img-container')324 await (async function () {325 for (let j = 0; j < 4; j++) {326 await page.waitForSelector('.img-container')327 for (let i = 0; i < 10; i++) {328 await page.keyboard.press('ArrowDown')329 }330 }331 })();332 await page.waitForSelector('.img-container')333 await (async function () {334 for (let j = 0; j < 4; j++) {335 await page.waitForSelector('.img-container')336 for (let i = 0; i < 10; i++) {337 await page.keyboard.press('ArrowDown')338 }339 }340 })();341 await page.waitForSelector('.img-container')342 await (async function () {343 for (let j = 0; j < 4; j++) {344 await page.waitForSelector('.img-container')345 for (let i = 0; i < 10; i++) {346 await page.keyboard.press('ArrowDown')347 }348 }349 })();350 await page.waitForSelector('.img-container')351 await (async function () {352 for (let j = 0; j < 4; j++) {353 await page.waitForSelector('.img-container')354 for (let i = 0; i < 10; i++) {355 await page.keyboard.press('ArrowDown')356 }357 }358 })();359 await page.waitForSelector('.img-container')360 await (async function () {361 for (let j = 0; j < 4; j++) {362 await page.waitForSelector('.img-container')363 for (let i = 0; i < 10; i++) {364 await page.keyboard.press('ArrowDown')365 }366 }367 })();368 await page.waitForSelector('.img-container')369 await (async function () {370 for (let j = 0; j < 4; j++) {371 await page.waitForSelector('.img-container')372 for (let i = 0; i < 10; i++) {373 await page.keyboard.press('ArrowDown')374 }375 }376 })();377 await page.waitForSelector('.img-container')378 await (async function () {379 for (let j = 0; j < 4; j++) {380 await page.waitForSelector('.img-container')381 for (let i = 0; i < 10; i++) {382 await page.keyboard.press('ArrowDown')383 }384 }385 })();386 await page.waitForSelector('.img-container')387 await (async function () {388 for (let j = 0; j < 4; j++) {389 await page.waitForSelector('.img-container')390 for (let i = 0; i < 10; i++) {391 await page.keyboard.press('ArrowDown')392 }393 }394 })();395 await page.waitForSelector('.img-container')396 await (async function () {397 for (let j = 0; j < 4; j++) {398 await page.waitForSelector('.img-container')399 for (let i = 0; i < 10; i++) {400 await page.keyboard.press('ArrowDown')401 }402 }403 })();404 await page.waitForSelector('.img-container')405 await (async function () {406 for (let j = 0; j < 4; j++) {407 await page.waitForSelector('.img-container')408 for (let i = 0; i < 10; i++) {409 await page.keyboard.press('ArrowDown')410 }411 }412 })();413 await page.waitForSelector('.img-container')414 await (async function () {415 for (let j = 0; j < 4; j++) {416 await page.waitForSelector('.img-container')417 for (let i = 0; i < 10; i++) {418 await page.keyboard.press('ArrowDown')419 }420 }421 })();422 await page.waitForSelector('.img-container')423 await (async function () {424 for (let j = 0; j < 4; j++) {425 await page.waitForSelector('.img-container')426 for (let i = 0; i < 10; i++) {427 await page.keyboard.press('ArrowDown')428 }429 }430 })();431 await page.waitForSelector('.img-container')432 await (async function () {433 for (let j = 0; j < 4; j++) {434 await page.waitForSelector('.img-container')435 for (let i = 0; i < 10; i++) {436 await page.keyboard.press('ArrowDown')437 }438 }439 })();440 await page.waitForSelector('.img-container')441 await (async function () {442 for (let j = 0; j < 4; j++) {443 await page.waitForSelector('.img-container')444 for (let i = 0; i < 10; i++) {445 await page.keyboard.press('ArrowDown')446 }447 }448 })();449 await page.waitForSelector('.img-container')450 await page.waitForSelector('.img-container')451 await page.waitForSelector('.img-container')452 await page.waitForSelector('.img-container')453 await page.waitForSelector('.img-container')454 await page.waitForSelector('img')455 await page.waitForSelector('img')456 await page.waitForSelector('img')457 await page.waitForSelector('img')458 await page.waitForSelector('img')459 await page.waitForSelector('img')460 await page.waitForSelector('img')461 await page.waitForSelector('img')462 await page.waitForSelector('img')463 await page.waitForSelector('img')464 await page.waitForSelector('img')465 await page.waitForSelector('.waterfall-item a')466 let link = await page.$$eval('.waterfall-item a', elements => {467 let a = []468 elements.forEach(e => {469 let h = e.href.split('/')470 let obj = {471 mid: h[h.length - 1],472 href: e.href473 }474 a.push(obj)475 })476 return a477 }).then(res => {478 return res479 })480 // 图片481 await page.waitForSelector('.img-container')482 let img = await page.$$eval('.img-container', elements => {483 484 let a = []485 elements.forEach(e => {486 let b = e.style.backgroundImage.split('url("')[1]487 let r = b.split('")')[0]488 a.push(r)489 })490 491 return a492 }).then(res => {493 return res494 })495 // 多P496 // await page.waitForSelector('.counts')497 // let mul = await page.$$eval('.counts', elements => {498 499 // let a = []500 // elements.forEach(e => {501 // a.push(e.innerText)502 // })503 504 // return a505 // }).then(res => {506 // return res507 // })508 // 标题509 await page.waitForSelector('.title')510 let title = await page.$$eval('.title', elements => {511 512 let a = []513 elements.forEach(e => {514 a.push(e.innerText)515 })516 517 return a518 }).then(res => {519 return res520 })521 // logo522 await page.waitForSelector('i img')523 let logo = await page.$$eval('i img', elements => {524 525 let a = []526 elements.forEach(e => {527 a.push(e.src)528 })529 530 return a531 }).then(res => {532 return res533 })534 // name535 await page.waitForSelector('span')536 let name = await page.$$eval('span', elements => {537 538 let a = []539 elements.forEach(e => {540 a.push(e.innerText)541 })542 543 return a544 }).then(res => {545 return res546 })547 let page_draw = []548 for (let i = 0; i < link.length; i++) {549 let location = `E:/VScode/bilibili/bilibili_data/album_data/draw_data/${link[i].mid}/`...

Full Screen

Full Screen

weather-app.js

Source:weather-app.js Github

copy

Full Screen

...23 },24} = require("../constants");25const validateMainWidget = async ({ page }) => {26 try {27 await page.waitForSelector(MAIN_WIDGET);28 await page.waitFor(1500);29 return true;30 } catch (error) {31 console.log("Error", error);32 return false;33 }34};35const validateHeadquarterOnMainWidget = async ({ page }) => {36 await page.waitForSelector(MAIN_WIDGET_HEADQUARTER);37 await page.waitFor(1500);38 const widget = await page.$eval(39 MAIN_WIDGET_HEADQUARTER,40 (el) => el.innerText41 );42 return widget;43};44const validateIconOnMainWidget = async ({ page }) => {45 try {46 await page.waitForSelector(MAIN_WIDGET_ICON);47 await page.waitFor(1500);48 return true;49 } catch (error) {50 console.log("Error", error);51 return false;52 }53};54const validateTemperatureOnMainWidget = async ({ page }) => {55 await page.waitForSelector(MAIN_WIDGET_TEMPERATURE);56 await page.waitFor(1500);57 const widget = await page.$eval(58 MAIN_WIDGET_TEMPERATURE,59 (el) => el.innerText60 );61 return widget;62};63const validateHumidityOnMainWidget = async ({ page }) => {64 await page.waitForSelector(MAIN_WIDGET_HUMIDITY);65 await page.waitFor(1500);66 const widget = await page.$eval(MAIN_WIDGET_HUMIDITY, (el) => el.innerText);67 return widget;68};69const validateWindOnMainWidget = async ({ page }) => {70 await page.waitForSelector(MAIN_WIDGET_WIND);71 await page.waitFor(1500);72 const widget = await page.$eval(MAIN_WIDGET_WIND, (el) => el.innerText);73 return widget;74};75const validateCarouselWidget = async ({ page }) => {76 await page.waitForSelector(CAROUSEL_WIDGET);77 await page.waitFor(1500);78 const widget = await page.$eval(CAROUSEL_WIDGET, (el) => el.textContent);79 return widget;80};81const validateItemsOnWidgetCarousel = async ({ page }) => {82 await page.waitForSelector(CAROUSEL_WIDGET_ITEM);83 await page.waitFor(1500);84 const widget = await page.$eval(CAROUSEL_WIDGET_ITEM, () =>85 Array.from(86 document.querySelectorAll("#widget-carousel .widget-carousel-item"),87 (el) => el.textContent88 )89 );90 return widget;91};92const validateTempItemOnWidgetCarousel = async ({ page }) => {93 await page.waitForSelector(CAROUSEL_WIDGET_ITEM);94 await page.waitFor(1500);95 const widget = await page.$eval(CAROUSEL_WIDGET_ITEM, () =>96 Array.from(97 document.querySelectorAll(98 "#widget-carousel .widget-carousel-item .widget-temperature"99 ),100 (el) => el.textContent101 )102 );103 return widget;104};105const validateHumidityItemOnWidgetCarousel = async ({ page }) => {106 await page.waitForSelector(CAROUSEL_WIDGET_ITEM);107 await page.waitFor(1500);108 const widget = await page.$eval(CAROUSEL_WIDGET_ITEM, () =>109 Array.from(110 document.querySelectorAll(111 "#widget-carousel .widget-carousel-item .widget-humidity"112 ),113 (el) => el.textContent114 )115 );116 return widget;117};118const validateWindItemOnWidgetCarousel = async ({ page }) => {119 await page.waitForSelector(CAROUSEL_WIDGET_ITEM);120 await page.waitFor(1500);121 const widget = await page.$eval(CAROUSEL_WIDGET_ITEM, () =>122 Array.from(123 document.querySelectorAll(124 "#widget-carousel .widget-carousel-item .widget-wind"125 ),126 (el) => el.textContent127 )128 );129 return widget;130};131const validateFavoritesWidget = async ({ page }) => {132 try {133 await page.waitForSelector(FAVORITES_WIDGET);134 await page.waitFor(1500);135 return true;136 } catch (error) {137 console.log(error);138 return false;139 }140};141const validateItemsOnFavoritesWidget = async ({ page }) => {142 await page.waitForSelector(FAVORITES_WIDGET_CARD);143 await page.waitFor(1500);144 const widget = await page.$eval(FAVORITES_WIDGET_CARD, () =>145 Array.from(146 document.querySelectorAll("#widget-favorite .widget-card"),147 (el) => el.textContent148 )149 );150 return widget;151};152const validateItemsByNameOnFavoritesWidget = async ({ page }) => {153 await page.waitForSelector(FAVORITES_WIDGET_CARD_NAME);154 await page.waitFor(1500);155 const widget = await page.$eval(FAVORITES_WIDGET_CARD_NAME, () =>156 Array.from(157 document.querySelectorAll(158 "#widget-favorite .widget-card .widget-headquarter-name"159 ),160 (el) => el.textContent161 )162 );163 return widget;164};165const validateItemsByTempOnFavoritesWidget = async ({ page }) => {166 await page.waitForSelector(FAVORITES_WIDGET_CARD);167 await page.waitFor(1500);168 const widget = await page.$eval(FAVORITES_WIDGET_CARD, () =>169 Array.from(170 document.querySelectorAll(171 "#widget-favorite .widget-card .widget-temperature"172 ),173 (el) => el.textContent174 )175 );176 return widget;177};178const validateItemsByHumidityOnFavoritesWidget = async ({ page }) => {179 await page.waitForSelector(FAVORITES_WIDGET_CARD);180 await page.waitFor(1500);181 const widget = await page.$eval(FAVORITES_WIDGET_CARD, () =>182 Array.from(183 document.querySelectorAll(184 "#widget-favorite .widget-card .widget-humidity"185 ),186 (el) => el.textContent187 )188 );189 return widget;190};191const validateItemsByWindOnFavoritesWidget = async ({ page }) => {192 await page.waitForSelector(FAVORITES_WIDGET_CARD);193 await page.waitFor(1500);194 const widget = await page.$eval(FAVORITES_WIDGET_CARD, () =>195 Array.from(196 document.querySelectorAll("#widget-favorite .widget-card .widget-wind"),197 (el) => el.textContent198 )199 );200 return widget;201};202const validateItemsByIconOnFavoritesWidget = async ({ page }) => {203 await page.waitForSelector(FAVORITES_WIDGET_CARD);204 await page.waitFor(1500);205 const widget = await page.$eval(FAVORITES_WIDGET_CARD, () =>206 Array.from(207 document.querySelectorAll("#widget-favorite .widget-card i.widget-icon"),208 () => true209 )210 );211 return widget;212};213const validateSuggestsWidget = async ({ page }) => {214 try {215 await page.waitForSelector(SUGGESTS_WIDGET);216 await page.waitFor(1500);217 return true;218 } catch (error) {219 console.log(error);220 return false;221 }222};223const validateIconOnSuggestsWidget = async ({ page }) => {224 try {225 await page.waitForSelector(SUGGESTS_WIDGET_ICON);226 await page.waitFor(1500);227 return true;228 } catch (error) {229 console.log(error);230 return false;231 }232};233const validateHeadquarterOnSuggestsWidget = async ({ page }) => {234 await page.waitForSelector(SUGGESTS_WIDGET_NAME);235 await page.waitFor(1500);236 const widget = await page.$eval(SUGGESTS_WIDGET_NAME, (el) => el.innerText);237 return widget;238};239const validateTemperatureOnSuggestsWidget = async ({ page }) => {240 await page.waitForSelector(SUGGESTS_WIDGET_TEMPERATURE);241 await page.waitFor(1500);242 const widget = await page.$eval(243 SUGGESTS_WIDGET_TEMPERATURE,244 (el) => el.innerText245 );246 return widget;247};248const validateHumidityOnSuggestsWidget = async ({ page }) => {249 await page.waitForSelector(SUGGESTS_WIDGET_HUMIDITY);250 await page.waitFor(1500);251 const widget = await page.$eval(252 SUGGESTS_WIDGET_HUMIDITY,253 (el) => el.innerText254 );255 return widget;256};257const validateWindOnSuggestsWidget = async ({ page }) => {258 await page.waitForSelector(SUGGESTS_WIDGET_WIND);259 await page.waitFor(1500);260 const widget = await page.$eval(SUGGESTS_WIDGET_WIND, (el) => el.innerText);261 return widget;262};263const validateDayOnSuggestsWidget = async ({ page }) => {264 await page.waitForSelector(SUGGESTS_WIDGET_DAY);265 await page.waitFor(1500);266 const widget = await page.$eval(SUGGESTS_WIDGET_DAY, (el) => el.innerText);267 return widget;268};269const validateCitiesWidget = async ({ page }) => {270 await page.waitForSelector(CITIES_WIDGET);271 await page.waitFor(1500);272 const widget = await page.$eval(CITIES_WIDGET, (el) => el.textContent);273 return widget;274};275const validateListCitiesWidget = async ({ page }) => {276 await page.waitForSelector(CITIES_WIDGET_CARD);277 await page.waitFor(1500);278 const widget = await page.$eval(CITIES_WIDGET_CARD, () =>279 Array.from(280 document.querySelectorAll("#widget-cities .widget-card"),281 (el) => el.textContent282 )283 );284 return widget;285};286const validateListByNameCitiesWidget = async ({ page }) => {287 await page.waitForSelector(CITIES_WIDGET_CARD);288 await page.waitFor(1500);289 const widget = await page.$eval(CITIES_WIDGET_CARD, () =>290 Array.from(291 document.querySelectorAll(292 "#widget-cities .widget-card .widget-city-name"293 ),294 (el) => el.textContent295 )296 );297 return widget;298};299const validateListByAnchorWidgetCity = async ({ page }) => {300 await page.waitForSelector(CITIES_WIDGET_CARD);301 await page.waitFor(1500);302 const widget = await page.$eval(CITIES_WIDGET_CARD, () =>303 Array.from(304 document.querySelectorAll("#widget-cities .widget-card a"),305 (el) => el.textContent306 )307 );308 return widget;309};310module.exports = {311 validateMainWidget,312 validateHeadquarterOnMainWidget,313 validateIconOnMainWidget,314 validateTemperatureOnMainWidget,...

Full Screen

Full Screen

Proposta.actions.js

Source:Proposta.actions.js Github

copy

Full Screen

...23 await this.#fillDataUser();24 }25 async #fillIdentClient(cpf) {26 try {27 await this.page.waitForSelector(Selectors.inputCpf, 5000);28 await this.page.fill(Selectors.inputCpf, cpf);29 } catch (error) {30 throw error;31 }32 }33 async #fillIdentPrestacao(installment) {34 try {35 await this.page.waitForSelector(Selectors.inputValorPres, 5000);36 await this.page.fill(Selectors.inputValorPres, installment);37 } catch (error) {38 throw error;39 }40 }41 async #buttonClick(button) {42 await this.page.waitForSelector(button, 5000);43 await this.page.click(button);44 }45 async #fillSelector(selector) {46 if (selector == "conveniada") {47 await this.page.waitForSelector(Selectors.selectConveniada);48 await this.page.click(Selectors.selectConveniada);49 await this.page.waitForSelector(Selectors.optionConveniada, 8000);50 await this.page.click(Selectors.optionConveniada);51 } else if (selector == "orgao") {52 await this.page.waitForSelector(Selectors.selectOrgao);53 await this.page.click(Selectors.selectOrgao);54 await this.page.click(Selectors.selectOrgao);55 await this.page.fill(Selectors.inputOrgao, "70000");56 await this.page.waitForSelector(Selectors.optionOrgao, 8000);57 await this.page.click(Selectors.optionOrgao);58 } else if (selector == "plano") {59 await this.page.waitForSelector(Selectors.selectPlano);60 await this.page.click(Selectors.selectPlano);61 await this.page.waitForSelector(Selectors.optionPlano, 8000);62 await this.page.click(Selectors.optionPlano);63 } else if (selector == "consultor") {64 await this.page.waitForSelector(Selectors.selectConsultor);65 await this.page.click(Selectors.selectConsultor);66 await this.page.waitForSelector(Selectors.optionConsultor, 8000);67 await this.page.click(Selectors.optionConsultor);68 } else if (selector == "grauInstituicao") {69 await this.page.waitForSelector(Selectors.selectSchool);70 await this.page.click(Selectors.selectSchool);71 await this.page.waitForSelector(Selectors.optionSchool, 8000);72 await this.page.click(Selectors.optionSchool);73 } else if (selector == "estadoCivil") {74 await this.page.waitForSelector(Selectors.selectCivil);75 await this.page.click(Selectors.selectCivil);76 await this.page.waitForSelector(Selectors.optionCivil, 8000);77 await this.page.click(Selectors.optionCivil);78 } else if (selector == "defVisual") {79 await this.page.waitForSelector(Selectors.selectDefVision, {80 timeout: 5000,81 });82 await this.page.click(Selectors.selectDefVision);83 await this.page.waitForSelector(Selectors.optionDefVision, 8000);84 await this.page.click(Selectors.optionDefVision);85 } else if (selector == "nacionalidade") {86 await this.page.waitForSelector(Selectors.selectNationality);87 await this.page.click(Selectors.selectNationality);88 await this.page.waitForSelector(Selectors.optionNationality, 8000);89 await this.page.click(Selectors.optionNationality);90 } else if (selector == "naturalidade") {91 await this.page.waitForSelector(Selectors.selectRegion);92 await this.page.click(Selectors.selectRegion);93 await this.page.fill(Selectors.inputRegion, "RS");94 await this.page.waitForSelector(Selectors.optionRegion, 8000);95 await this.page.click(Selectors.optionRegion);96 } else if (selector == "cidade") {97 await this.page.waitForSelector(Selectors.selectCity);98 await this.page.click(Selectors.selectCity);99 await this.page.waitForSelector(Selectors.optionCity, 8000);100 await this.page.click(Selectors.optionCity);101 } else if (selector == "tipo documento") {102 await this.page.waitForSelector(Selectors.selectTipoDocumento, 5000);103 await this.page.click(Selectors.selectTipoDocumento);104 await this.page.waitForSelector(Selectors.optionTipoDocumento, 8000);105 await this.page.click(Selectors.optionTipoDocumento);106 } else if (selector == "org emissor") {107 await this.page.waitForSelector(Selectors.selectOrgEmissor, 5000);108 await this.page.click(Selectors.selectOrgEmissor);109 await this.page.waitForSelector(Selectors.optionOrgEmissor, 8000);110 await this.page.click(Selectors.optionOrgEmissor);111 } else if (selector == "org emissor") {112 await this.page.waitForSelector(Selectors.selectUf, 5000);113 await this.page.click(Selectors.selectUf);114 await this.page.fill(Selectors.inputUf, "RS");115 await this.page.waitForSelector(Selectors.optionUf, 8000);116 await this.page.click(Selectors.optionUf);117 }118 }119 async #fillDataUser() {120 const person = this.utils.generatePerson();121 await this.page.waitForSelector(Selectors.inputName, 5000);122 const value = await this.page.getAttribute(Selectors.inputName, "value");123 if (value !== "") {124 await this.page.click(Selectors.btnDadosBasicos);125 return;126 }127 await this.page.fill(Selectors.inputName, person.name);128 await this.page.fill(Selectors.inputMother, person.nomeMae);129 await this.page.fill(Selectors.inputFather, person.nomePai);130 await this.page.fill(Selectors.inputBirth, person.birthday);131 await this.page.fill(Selectors.inputEmail, person.email);132 await this.#fillSelector("grauInstituicao");133 await this.#fillSelector("estadoCivil");134 await this.#fillSelector("defVisual");135 await this.#fillSelector("nacionalidade");...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1async function registerUser(user) {2 await page.waitForSelector("#btn-register");3 await page.evaluate(4 (selector) => document.querySelector(selector).click(),5 "#btn-register"6 );7 console.log("Register button clicked");8 await page.waitForNavigation();9 console.log("Using user: ", user)10 await page.waitForSelector('input[name="username"]');11 await page.type('input[name="username"]', user.username);12 await page.waitForSelector('input[name="email"]');13 await page.type('input[name="email"]', user.email);14 await page.waitForSelector('input[name="password"]');15 await page.type('input[name="password"]', user.password);16 await page.waitForSelector('input[name="password1"]');17 await page.type('input[name="password1"]', user.password);18 await page.waitForSelector('input[name="phone_number"]');19 await page.type('input[name="phone_number"]', user.phone_numer);20 await page.waitForSelector('input[name="country"]');21 await page.type('input[name="country"]', user.country);22 await page.waitForSelector('input[name="city"]');23 await page.type('input[name="city"]', user.city);24 await page.waitForSelector('input[name="street_address"]');25 await page.type('input[name="street_address"]', user.street_name);26 27 await page.evaluate(28 (selector) => document.querySelector(selector).click(),29 "#btn-create-account"30 );31 console.log("Create account button clicked");32 await page.waitForNavigation();33 const logoutButton = await page.$("#btn-logout");34 const logoutText = await page.evaluate((title) => title.innerText, logoutButton);35 expect(logoutText).toBe("Log out");36}37async function login(user) {38 console.log("Login as user: ", user)39 await page.waitForSelector("#form-login");40 await page.waitForSelector('input[name="username"]');41 await page.waitForSelector('input[name="password"]');42 await page.waitForSelector("#btn-login");43 await page.type('input[name="username"]', user.username);44 await page.type('input[name="password"]', user.password);45 await page.evaluate((selector) => {46 document.querySelector(selector).click();47 }, "#btn-login");48 await page.waitForNavigation();49 const logoutButton = await page.$("#btn-logout");50 const logoutText = await page.evaluate(51 (title) => title.innerText,52 logoutButton53 );54 expect(logoutText).toBe("Log out");55}56module.exports = {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('.navbar__inner .navbar__title');7 await page.screenshot({ path: 'example.png' });8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('text=Get Started');7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.waitForSelector('text=Get Started');15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.waitForSelector('text=Get Started');23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.waitForSelector('text=Get Started');31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.waitForSelector('text=Get Started');39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();46 await page.waitForSelector('text=Get Started');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('input[name=q]');7 await page.fill('input[name=q]', 'Playwright');8 await page.click('input[name="btnK"]');9 await page.waitForSelector('div[class="g"]');10 await page.waitForSelector('text=Playwright is a Node library to automate');11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.waitForSelector('#start');6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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