How to use screen_shot method in SeleniumLibrary

Best Python code snippet using SeleniumLibrary

populate_data.py

Source:populate_data.py Github

copy

Full Screen

1import datetime2from essentials_kit_management.models import (3 User, Item, Brand, Section, Form, Transaction, Order, Account4 )5users_list = [6 {7 "name": "prudhvi",8 "username": "prudhvi",9 "password": "prudhvi123",10 "is_admin": False11 },12 {13 "name": "sulthan",14 "username": "12345",15 "password": "12345",16 "is_admin": False17 },18 {19 "name": "johncena",20 "username": "johncena",21 "password": "johncena123",22 "is_admin": False23 },24 25 {26 "name": "che guevara",27 "username": "che",28 "password": "che123",29 "is_admin": False30 },31 {32 "name": "Admin1",33 "username": "admin1123",34 "password": "admin1@",35 "is_admin": True36 },37 {38 "name": "Admin2",39 "username": "admin2123",40 "password": "admin2@",41 "is_admin": True42 }43 ]44def create_users():45 for user in users_list:46 User.objects.create(name=user["name"],47 username=user["username"],48 password=user["password"],49 is_admin=user["is_admin"])50account_list = [51 {52 "upi_id": "1234567890@SBI"53 }54]55def create_account():56 for account in account_list:57 Account.objects.create(upi_id=account["upi_id"])58def populate_data():59 create_users()60 print("users created")61 create_account()62 print("accounts created")63 for form in new_forms_list:64 form_obj = Form.objects.create(name=form["name"], status=form["status"],65 description=form["description"],66 close_date=form["close_date"],67 expected_delivery_date=form["expected_delivery_date"])68 for section in form["sections"]:69 section_obj = Section.objects.create(name=section["name"],70 description=section["description"])71 form_obj.sections.add(section_obj)72 for item in section["items"]:73 item_obj = Item.objects.create(name=item["name"],74 description=item["description"])75 section_obj.items.add(item_obj)76 for brand in item["brands"]:77 brand_obj = Brand.objects.create(name=brand["name"],78 min_quantity=brand["min_quantity"],79 max_quantity=brand["max_quantity"],80 price_per_item=brand["price_per_item"])81 item_obj.brand.add(brand_obj)82 print("forms data created")83 create_transactions()84 print("transactions created")85 86 create_orders()87 print("orders created")88 print("data populated successfully Hurrah!.......")89def create_orders():90 for order in new_orders_list:91 Order.objects.create(92 user_id=order["user_id"],93 item_id=order["item_id"],94 brand_id=order["brand_id"],95 form_id=order["form_id"],96 section_id=order["section_id"],97 count=order["count"],98 pending_count=order["pending_count"],99 out_of_stock=order["out_of_stock"]100 )101transaction_list = [102 # user 1 transactions103 {104 "transaction_id": 1,105 "user_id": 1,106 "amount": 1000,107 "status": "APPROVED",108 "payment_type": "PHONE_PAY",109 "screen_shot": "screen_shot/payment.png",110 "remark": "wallet"111 },112 {113 "transaction_id": 2,114 "user_id": 1,115 "amount": 300,116 "status": "APPROVED",117 "payment_type": "GOOGLE_PAY",118 "screen_shot": "screen_shot/payment.png",119 "remark": "wallet"120 },121 {122 "transaction_id": 3,123 "user_id": 1,124 "amount": -100,125 "status": "APPROVED",126 "payment_type": "PHONE_PAY",127 "screen_shot": "",128 "remark": "form1"129 },130 {131 "transaction_id": 4,132 "user_id": 1,133 "amount": -600,134 "status": "APPROVED",135 "payment_type": "PHONE_PAY",136 "screen_shot": "screen_shot/payment.png",137 "remark": "form2"138 },139 {140 "transaction_id": 5,141 "user_id": 1,142 "amount": 700,143 "status": "PENDING",144 "payment_type": "PHONE_PAY",145 "screen_shot": "screen_shot/payment.png",146 "remark": "wallet"147 },148 {149 "transaction_id": 6,150 "user_id": 1,151 "amount": 500,152 "status": "PENDING",153 "payment_type": "GOOGLE_PAY",154 "screen_shot": "screen_shot/payment.png",155 "remark": "wallet"156 },157 {158 "transaction_id": 7,159 "user_id": 1,160 "amount": 1000,161 "status": "REJECTED",162 "payment_type": "PHONE_PAY",163 "screen_shot": "screen_shot/payment.png",164 "remark": "wallet"165 },166 {167 "transaction_id": 8,168 "user_id": 1,169 "amount": 700,170 "status": "REJECTED",171 "payment_type": "PAYTM",172 "screen_shot": "screen_shot/payment.png",173 "remark": "wallet"174 },175# user 2 transactions176 {177 "transaction_id": 9,178 "user_id": 2,179 "amount": 900,180 "status": "APPROVED",181 "payment_type": "PHONE_PAY",182 "screen_shot": "screen_shot/payment.png",183 "remark": "wallet"184 },185 {186 "transaction_id": 10,187 "user_id": 2,188 "amount": 600,189 "status": "APPROVED",190 "payment_type": "GOOGLE_PAY",191 "screen_shot": "screen_shot/payment.png",192 "remark": "wallet"193 },194 {195 "transaction_id": 11,196 "user_id": 2,197 "amount": -400,198 "status": "APPROVED",199 "payment_type": "PHONE_PAY",200 "screen_shot": "",201 "remark": "form1"202 },203 {204 "transaction_id": 12,205 "user_id": 2,206 "amount": -300,207 "status": "APPROVED",208 "payment_type": "PHONE_PAY",209 "screen_shot": "screen_shot/payment.png",210 "remark": "form2"211 },212 {213 "transaction_id": 13,214 "user_id": 2,215 "amount": 700,216 "status": "PENDING",217 "payment_type": "PHONE_PAY",218 "screen_shot": "screen_shot/payment.png",219 "remark": "wallet"220 },221 {222 "transaction_id": 14,223 "user_id": 2,224 "amount": 500,225 "status": "PENDING",226 "payment_type": "GOOGLE_PAY",227 "screen_shot": "screen_shot/payment.png",228 "remark": "wallet"229 },230 {231 "transaction_id": 15,232 "user_id": 2,233 "amount": 900,234 "status": "REJECTED",235 "payment_type": "PHONE_PAY",236 "screen_shot": "screen_shot/payment.png",237 "remark": "wallet"238 },239 {240 "transaction_id": 16,241 "user_id": 2,242 "amount": 700,243 "status": "REJECTED",244 "payment_type": "PAYTM",245 "screen_shot": "screen_shot/payment.png",246 "remark": "wallet"247 },248# user 3 transactions249 {250 "transaction_id": 17,251 "user_id": 3,252 "amount": 1100,253 "status": "APPROVED",254 "payment_type": "PHONE_PAY",255 "screen_shot": "screen_shot/payment.png",256 "remark": "wallet"257 },258 {259 "transaction_id": 18,260 "user_id": 3,261 "amount": 200,262 "status": "APPROVED",263 "payment_type": "GOOGLE_PAY",264 "screen_shot": "screen_shot/payment.png",265 "remark": "wallet"266 },267 {268 "transaction_id": 19,269 "user_id": 3,270 "amount": -300,271 "status": "APPROVED",272 "payment_type": "PHONE_PAY",273 "screen_shot": "",274 "remark": "form1"275 },276 {277 "transaction_id": 20,278 "user_id": 3,279 "amount": -400,280 "status": "APPROVED",281 "payment_type": "PHONE_PAY",282 "screen_shot": "screen_shot/payment.png",283 "remark": "form2"284 },285 {286 "transaction_id": 21,287 "user_id": 3,288 "amount": 800,289 "status": "PENDING",290 "payment_type": "PHONE_PAY",291 "screen_shot": "screen_shot/payment.png",292 "remark": "wallet"293 },294 {295 "transaction_id": 22,296 "user_id": 3,297 "amount": 500,298 "status": "PENDING",299 "payment_type": "GOOGLE_PAY",300 "screen_shot": "screen_shot/payment.png",301 "remark": "wallet"302 },303 {304 "transaction_id": 23,305 "user_id": 3,306 "amount": 800,307 "status": "REJECTED",308 "payment_type": "PHONE_PAY",309 "screen_shot": "screen_shot/payment.png",310 "remark": "wallet"311 },312 {313 "transaction_id": 24,314 "user_id": 3,315 "amount": 700,316 "status": "REJECTED",317 "payment_type": "PAYTM",318 "screen_shot": "screen_shot/payment.png",319 "remark": "wallet"320 }321]322def create_transactions():323 for transaction in transaction_list:324 Transaction.objects.create(325 transaction_id=transaction['transaction_id'],326 user_id=transaction['user_id'],327 amount=transaction['amount'],328 status=transaction['status'],329 payment_type=transaction["payment_type"],330 screen_shot=transaction["screen_shot"],331 remark=transaction["remark"])332new_forms_list = [333 {334 "name": "Snack form 1",335 "description": "Snack form 1 description",336 "close_date": datetime.datetime(2020, 6, 1, 0, 0, 0),337 "expected_delivery_date": datetime.datetime(2020, 6, 10, 0, 0, 0),338 "status": "LIVE",339 "sections": [340 {341 "name": "Chocolates", "description": "Chocolates description",342 "items": [343 {344 "name": "Cadbury", "description": "description",345 "brands": [346 {347 "name": "brand1", "min_quantity": 0, 348 "max_quantity": 10, "price_per_item": 50349 },350 {351 "name": "brand2", "min_quantity": 0,352 "max_quantity": 8, "price_per_item": 60353 },354 {355 "name": "brand3", "min_quantity": 0,356 "max_quantity": 9, "price_per_item": 70357 }358 359 ]360 },361 {362 "name": "Diary milk silk", "description": "description",363 "brands": [364 {365 "name": "brand4", "min_quantity": 0, 366 "max_quantity": 10, "price_per_item": 40367 },368 {369 "name": "brand5", "min_quantity": 0,370 "max_quantity": 5, "price_per_item": 80371 },372 {373 "name": "brand6", "min_quantity": 0,374 "max_quantity": 6, "price_per_item": 50375 }376 377 ]378 }379 ]380 },381 {382 "name": "Chips",383 "description": "Chips description",384 "items": [385 {386 "name": "Lays",387 "description": "description",388 "brands": [389 {390 "name": "brand7", "min_quantity": 0, 391 "max_quantity": 20, "price_per_item": 80392 },393 {394 "name": "brand8", "min_quantity": 0,395 "max_quantity": 8, "price_per_item": 90396 },397 {398 "name": "brand9", "min_quantity": 0,399 "max_quantity": 7, "price_per_item": 50400 }401 402 ]403 },404 {405 "name": "Bingo",406 "description": " description",407 "brands": [408 {409 "name": "brand10", "min_quantity": 0, 410 "max_quantity": 5, "price_per_item": 100411 },412 {413 "name": "brand11", "min_quantity": 0,414 "max_quantity": 5, "price_per_item": 200415 },416 {417 "name": "brand12", "min_quantity": 0,418 "max_quantity": 6, "price_per_item": 50419 }420 421 ]422 }423 424 ]425 }426 ]427 },428 {429 "name": "Accommodation",430 "description": "description",431 "close_date": datetime.datetime(2020, 6, 1, 0, 0, 0),432 "expected_delivery_date": datetime.datetime(2020, 6, 6, 0, 0, 0),433 "status": "CLOSED",434 "sections": [435 {436 "name": "Shampoos", "description": "Shampoos description",437 "items": [438 {439 "name": "Tresemme", "description": "Tresemme description",440 "brands": [441 {442 "name": "brand13", "min_quantity": 0, 443 "max_quantity": 5, "price_per_item": 100444 },445 {446 "name": "brand14", "min_quantity": 0,447 "max_quantity": 8, "price_per_item": 150448 },449 {450 "name": "brand15", "min_quantity": 0,451 "max_quantity": 7, "price_per_item": 50452 }453 454 ]455 },456 {457 "name": "Dove", "description": "Dove description",458 "brands": [459 {460 "name": "brand16", "min_quantity": 0, 461 "max_quantity": 5, "price_per_item": 100462 },463 {464 "name": "brand17", "min_quantity": 0,465 "max_quantity": 8, "price_per_item": 150466 },467 {468 "name": "brand18", "min_quantity": 0,469 "max_quantity": 6, "price_per_item": 50470 }471 472 ]473 }474 ]475 }, 476 {477 "name": "Hair oil",478 "description": "Hair oil description",479 "items": [480 {481 "name": "Coconut oil",482 "description": "Coconut oil description",483 "brands": [484 {485 "name": "brand19", "min_quantity": 0, 486 "max_quantity": 5, "price_per_item": 100487 },488 {489 "name": "brand20", "min_quantity": 0,490 "max_quantity": 8, "price_per_item": 150491 },492 {493 "name": "brand21", "min_quantity": 0,494 "max_quantity": 7, "price_per_item": 50495 }496 497 ]498 },499 {500 "name": "indulekha",501 "description": "indulekha description",502 "brands": [503 {504 "name": "brand22", "min_quantity": 0, 505 "max_quantity": 5, "price_per_item": 100506 },507 {508 "name": "brand23", "min_quantity": 0,509 "max_quantity": 5, "price_per_item": 150510 },511 {512 "name": "brand24", "min_quantity": 0,513 "max_quantity": 6, "price_per_item": 50514 }515 516 ]517 }518 519 ]520 }521 ]522 },523 # form3524 {525 "name": "Fruits form",526 "description": "Fruits form description",527 "close_date": datetime.datetime(2020, 5, 10, 0, 0, 0),528 "expected_delivery_date": datetime.datetime(2020, 5, 20, 0, 0, 0),529 "status": "DONE",530 "sections": [531 {532 "name": "section5", "description": "section5 description",533 "items": [534 {535 "name": "Apples", "description": "Apples description",536 "brands": [537 {538 "name": "brand25", "min_quantity": 0, 539 "max_quantity": 5, "price_per_item": 100540 },541 {542 "name": "brand26", "min_quantity": 0,543 "max_quantity": 8, "price_per_item": 200544 },545 {546 "name": "brand27", "min_quantity": 0,547 "max_quantity": 7, "price_per_item": 50548 }549 550 ]551 },552 {553 "name": "Mango", "description": "Mango description",554 "brands": [555 {556 "name": "brand28", "min_quantity": 0, 557 "max_quantity": 5, "price_per_item": 100558 },559 {560 "name": "brand29", "min_quantity": 0,561 "max_quantity": 5, "price_per_item": 200562 },563 {564 "name": "brand30", "min_quantity": 0,565 "max_quantity": 6, "price_per_item": 50566 }567 568 ]569 }570 ]571 },572 {573 "name": "section6",574 "description": "section6 description",575 "items": [576 {577 "name": "Oranges",578 "description": "Oranges description",579 "brands": [580 {581 "name": "brand31", "min_quantity": 0, 582 "max_quantity": 5, "price_per_item": 100583 },584 {585 "name": "brand32", "min_quantity": 0,586 "max_quantity": 8, "price_per_item": 200587 },588 {589 "name": "brand33", "min_quantity": 0,590 "max_quantity": 7, "price_per_item": 50591 }592 593 ]594 },595 {596 "name": "grapes",597 "description": "grapes description",598 "brands": [599 {600 "name": "brand34", "min_quantity": 0, 601 "max_quantity": 5, "price_per_item": 100602 },603 {604 "name": "brand35", "min_quantity": 0,605 "max_quantity": 5, "price_per_item": 200606 },607 {608 "name": "brand36", "min_quantity": 0,609 "max_quantity": 6, "price_per_item": 50610 }611 612 ]613 }614 615 ]616 }617 ]618 },619 {620 "name": "form4",621 "description": "form4 description",622 "close_date": datetime.datetime(2020, 5, 25, 0, 0, 0),623 "expected_delivery_date": datetime.datetime(2020, 6, 1, 0, 0, 0),624 "status": "LIVE",625 "sections": [626 {627 "name": "section7", "description": "section7 description",628 "items": [629 {630 "name": "item13", "description": "item13 description",631 "brands": [632 {633 "name": "brand37", "min_quantity": 0, 634 "max_quantity": 5, "price_per_item": 100635 },636 {637 "name": "brand38", "min_quantity": 0,638 "max_quantity": 8, "price_per_item": 200639 },640 {641 "name": "brand39", "min_quantity": 0,642 "max_quantity": 7, "price_per_item": 50643 }644 645 ]646 },647 {648 "name": "item14", "description": "item14 description",649 "brands": [650 {651 "name": "brand40", "min_quantity": 0, 652 "max_quantity": 5, "price_per_item": 100653 },654 {655 "name": "brand41", "min_quantity": 0,656 "max_quantity": 5, "price_per_item": 200657 },658 {659 "name": "brand142", "min_quantity": 0,660 "max_quantity": 6, "price_per_item": 50661 }662 663 ]664 }665 ]666 },667 {668 "name": "section8",669 "description": "section8 description",670 "items": [671 {672 "name": "item15",673 "description": "item15 description",674 "brands": [675 {676 "name": "brand43", "min_quantity": 1, 677 "max_quantity": 5, "price_per_item": 100678 },679 {680 "name": "brand44", "min_quantity": 2,681 "max_quantity": 8, "price_per_item": 200682 },683 {684 "name": "brand45", "min_quantity": 5,685 "max_quantity": 7, "price_per_item": 50686 }687 688 ]689 },690 {691 "name": "item16",692 "description": "item16 description",693 "brands": [694 {695 "name": "brand146", "min_quantity": 1, 696 "max_quantity": 5, "price_per_item": 100697 },698 {699 "name": "brand47", "min_quantity": 2,700 "max_quantity": 5, "price_per_item": 200701 },702 {703 "name": "brand48", "min_quantity": 2,704 "max_quantity": 6, "price_per_item": 50705 }706 707 ]708 }709 710 ]711 }712 ]713 },714 {715 "name": "form5",716 "description": "form5 description",717 "close_date": datetime.datetime(2020, 6, 3, 0, 0, 0),718 "expected_delivery_date": datetime.datetime(2020, 6, 6, 0, 0, 0),719 "status": "LIVE",720 "sections": [721 {722 "name": "section9", "description": "section9 description",723 "items": [724 {725 "name": "item17", "description": "item17 description",726 "brands": [727 {728 "name": "brand50", "min_quantity": 0, 729 "max_quantity": 5, "price_per_item": 100730 },731 {732 "name": "brand51", "min_quantity": 0,733 "max_quantity": 8, "price_per_item": 200734 },735 {736 "name": "brand52", "min_quantity": 0,737 "max_quantity": 7, "price_per_item": 50738 }739 740 ]741 },742 {743 "name": "item118", "description": "item18 description",744 "brands": [745 {746 "name": "brand53", "min_quantity": 0, 747 "max_quantity": 5, "price_per_item": 100748 },749 {750 "name": "brand54", "min_quantity": 0,751 "max_quantity": 5, "price_per_item": 200752 },753 {754 "name": "brand55", "min_quantity": 0,755 "max_quantity": 6, "price_per_item": 50756 }757 758 ]759 }760 ]761 },762 {763 "name": "section10",764 "description": "section10 description",765 "items": [766 {767 "name": "item19",768 "description": "item19 description",769 "brands": [770 {771 "name": "brand56", "min_quantity": 1, 772 "max_quantity": 5, "price_per_item": 100773 },774 {775 "name": "brand57", "min_quantity": 2,776 "max_quantity": 8, "price_per_item": 200777 },778 {779 "name": "brand58", "min_quantity": 5,780 "max_quantity": 7, "price_per_item": 50781 }782 783 ]784 },785 {786 "name": "item20",787 "description": "item20 description",788 "brands": [789 {790 "name": "brand159", "min_quantity": 1, 791 "max_quantity": 5, "price_per_item": 100792 },793 {794 "name": "brand60", "min_quantity": 2,795 "max_quantity": 5, "price_per_item": 200796 },797 {798 "name": "brand61", "min_quantity": 2,799 "max_quantity": 6, "price_per_item": 50800 }801 802 ]803 }804 805 ]806 }807 ]808 },809 {810 "name": "form6",811 "description": "form6 description",812 "close_date": datetime.datetime(2020, 5, 10, 0, 0, 0),813 "expected_delivery_date": datetime.datetime(2020, 5, 11, 0, 0, 0),814 "status": "CLOSED",815 "sections": [816 {817 "name": "section21", "description": "section21 description",818 "items": [819 {820 "name": "item13", "description": "item13 description",821 "brands": [822 {823 "name": "brand62", "min_quantity": 0, 824 "max_quantity": 5, "price_per_item": 100825 },826 {827 "name": "brand63", "min_quantity": 0,828 "max_quantity": 8, "price_per_item": 200829 },830 {831 "name": "brand64", "min_quantity": 0,832 "max_quantity": 7, "price_per_item": 50833 }834 835 ]836 },837 {838 "name": "item22", "description": "item22 description",839 "brands": [840 {841 "name": "brand65", "min_quantity": 0, 842 "max_quantity": 5, "price_per_item": 100843 },844 {845 "name": "brand66", "min_quantity": 0,846 "max_quantity": 5, "price_per_item": 200847 },848 {849 "name": "brand167", "min_quantity": 0,850 "max_quantity": 6, "price_per_item": 50851 }852 853 ]854 }855 ]856 },857 {858 "name": "section12",859 "description": "section12 description",860 "items": [861 {862 "name": "item23",863 "description": "item23 description",864 "brands": [865 {866 "name": "brand68", "min_quantity": 1, 867 "max_quantity": 5, "price_per_item": 100868 },869 {870 "name": "brand69", "min_quantity": 2,871 "max_quantity": 8, "price_per_item": 200872 },873 {874 "name": "brand70", "min_quantity": 5,875 "max_quantity": 7, "price_per_item": 50876 }877 878 ]879 },880 {881 "name": "item24",882 "description": "item24 description",883 "brands": [884 {885 "name": "brand71", "min_quantity": 1, 886 "max_quantity": 5, "price_per_item": 100887 },888 {889 "name": "brand72", "min_quantity": 2,890 "max_quantity": 5, "price_per_item": 200891 },892 {893 "name": "brand73", "min_quantity": 2,894 "max_quantity": 6, "price_per_item": 50895 }896 897 ]898 }899 900 ]901 }902 ]903 },904 {905 "name": "form7",906 "description": "form7 description",907 "close_date": datetime.datetime(2020, 6, 6, 0, 0, 0),908 "expected_delivery_date": datetime.datetime(2020, 6, 10, 0, 0, 0),909 "status": "LIVE",910 "sections": [911 {912 "name": "section13", "description": "section13 description",913 "items": [914 {915 "name": "item25", "description": "item25 description",916 "brands": [917 {918 "name": "brand74", "min_quantity": 0, 919 "max_quantity": 5, "price_per_item": 100920 },921 {922 "name": "brand75", "min_quantity": 0,923 "max_quantity": 8, "price_per_item": 200924 },925 {926 "name": "brand76", "min_quantity": 0,927 "max_quantity": 7, "price_per_item": 50928 }929 930 ]931 },932 {933 "name": "item26", "description": "item26 description",934 "brands": [935 {936 "name": "brand77", "min_quantity": 0, 937 "max_quantity": 5, "price_per_item": 100938 },939 {940 "name": "brand78", "min_quantity": 0,941 "max_quantity": 5, "price_per_item": 200942 },943 {944 "name": "brand79", "min_quantity": 0,945 "max_quantity": 6, "price_per_item": 50946 }947 948 ]949 }950 ]951 },952 {953 "name": "section14",954 "description": "section14 description",955 "items": [956 {957 "name": "item27",958 "description": "item27 description",959 "brands": [960 {961 "name": "brand80", "min_quantity": 1, 962 "max_quantity": 5, "price_per_item": 100963 },964 {965 "name": "brand81", "min_quantity": 2,966 "max_quantity": 8, "price_per_item": 200967 },968 {969 "name": "brand82", "min_quantity": 5,970 "max_quantity": 7, "price_per_item": 50971 }972 973 ]974 },975 {976 "name": "item28",977 "description": "item28 description",978 "brands": [979 {980 "name": "brand83", "min_quantity": 1, 981 "max_quantity": 5, "price_per_item": 100982 },983 {984 "name": "brand84", "min_quantity": 2,985 "max_quantity": 5, "price_per_item": 200986 },987 {988 "name": "brand85", "min_quantity": 2,989 "max_quantity": 6, "price_per_item": 50990 }991 992 ]993 }994 995 ]996 }997 ]998 },999 {1000 "name": "form8",1001 "description": "form8 description",1002 "close_date": datetime.datetime(2020, 4, 4, 0, 0, 0),1003 "expected_delivery_date": datetime.datetime(2020, 4, 4, 0, 0, 0),1004 "status": "CLOSED",1005 "sections": [1006 {1007 "name": "section15", "description": "section15 description",1008 "items": [1009 {1010 "name": "item28", "description": "item28 description",1011 "brands": [1012 {1013 "name": "brand86", "min_quantity": 0, 1014 "max_quantity": 5, "price_per_item": 1001015 },1016 {1017 "name": "brand87", "min_quantity": 0,1018 "max_quantity": 8, "price_per_item": 2001019 },1020 {1021 "name": "brand88", "min_quantity": 0,1022 "max_quantity": 7, "price_per_item": 501023 }1024 1025 ]1026 },1027 {1028 "name": "item29", "description": "item29 description",1029 "brands": [1030 {1031 "name": "brand89", "min_quantity": 0, 1032 "max_quantity": 5, "price_per_item": 1001033 },1034 {1035 "name": "brand90", "min_quantity": 0,1036 "max_quantity": 5, "price_per_item": 2001037 },1038 {1039 "name": "brand91", "min_quantity": 0,1040 "max_quantity": 6, "price_per_item": 501041 }1042 1043 ]1044 }1045 ]1046 },1047 {1048 "name": "section16",1049 "description": "section16 description",1050 "items": [1051 {1052 "name": "item30",1053 "description": "item30 description",1054 "brands": [1055 {1056 "name": "brand92", "min_quantity": 1, 1057 "max_quantity": 5, "price_per_item": 1001058 },1059 {1060 "name": "brand93", "min_quantity": 2,1061 "max_quantity": 8, "price_per_item": 2001062 },1063 {1064 "name": "brand94", "min_quantity": 5,1065 "max_quantity": 7, "price_per_item": 501066 }1067 1068 ]1069 },1070 {1071 "name": "item31",1072 "description": "item31 description",1073 "brands": [1074 {1075 "name": "brand95", "min_quantity": 1, 1076 "max_quantity": 5, "price_per_item": 1001077 },1078 {1079 "name": "brand96", "min_quantity": 2,1080 "max_quantity": 5, "price_per_item": 2001081 },1082 {1083 "name": "brand97", "min_quantity": 2,1084 "max_quantity": 6, "price_per_item": 501085 }1086 1087 ]1088 }1089 1090 ]1091 }1092 ]1093 },1094 {1095 "name": "form9",1096 "description": "form9 description",1097 "close_date": datetime.datetime(2020, 3, 10, 0, 0, 0),1098 "expected_delivery_date": datetime.datetime(2020, 10, 10, 0, 0, 0),1099 "status": "LIVE",1100 "sections": [1101 {1102 "name": "section17", "description": "section17 description",1103 "items": [1104 {1105 "name": "item32", "description": "item32 description",1106 "brands": [1107 {1108 "name": "brand98", "min_quantity": 0, 1109 "max_quantity": 5, "price_per_item": 1001110 },1111 {1112 "name": "brand99", "min_quantity": 0,1113 "max_quantity": 8, "price_per_item": 501114 },1115 {1116 "name": "brand100", "min_quantity": 0,1117 "max_quantity": 7, "price_per_item": 501118 }1119 1120 ]1121 },1122 {1123 "name": "item33", "description": "item33 description",1124 "brands": [1125 {1126 "name": "brand101", "min_quantity": 0, 1127 "max_quantity": 5, "price_per_item": 1001128 },1129 {1130 "name": "brand102", "min_quantity": 0,1131 "max_quantity": 5, "price_per_item": 901132 },1133 {1134 "name": "brand103", "min_quantity": 0,1135 "max_quantity": 6, "price_per_item": 501136 }1137 1138 ]1139 }1140 ]1141 },1142 {1143 "name": "section18",1144 "description": "section18 description",1145 "items": [1146 {1147 "name": "item34",1148 "description": "item34 description",1149 "brands": [1150 {1151 "name": "brand105", "min_quantity": 1, 1152 "max_quantity": 5, "price_per_item": 1001153 },1154 {1155 "name": "brand106", "min_quantity": 2,1156 "max_quantity": 8, "price_per_item": 801157 },1158 {1159 "name": "brand107", "min_quantity": 5,1160 "max_quantity": 7, "price_per_item": 501161 }1162 1163 ]1164 },1165 {1166 "name": "item35",1167 "description": "item35 description",1168 "brands": [1169 {1170 "name": "brand108", "min_quantity": 1, 1171 "max_quantity": 5, "price_per_item": 1001172 },1173 {1174 "name": "brand109", "min_quantity": 2,1175 "max_quantity": 5, "price_per_item": 701176 },1177 {1178 "name": "brand110", "min_quantity": 2,1179 "max_quantity": 6, "price_per_item": 501180 }1181 1182 ]1183 }1184 1185 ]1186 }1187 ]1188 },1189 {1190 "name": "form20",1191 "description": "form20 description",1192 "close_date": datetime.datetime(2020, 11, 8, 0, 0, 0),1193 "expected_delivery_date": datetime.datetime(2020, 1, 10, 0, 0, 0),1194 "status": "CLOSED",1195 "sections": []},1196 {1197 "name": "form22",1198 "description": "form22 description",1199 "close_date": datetime.datetime(2020, 10, 8, 0, 0, 0),1200 "expected_delivery_date": datetime.datetime(2020, 2, 10, 0, 0, 0),1201 "status": "CLOSED",1202 "sections": []},1203 {1204 "name": "form23",1205 "description": "form23 description",1206 "close_date": datetime.datetime(2020, 10, 8, 0, 0, 0),1207 "expected_delivery_date": datetime.datetime(2020, 3, 10, 0, 0, 0),1208 "status": "CLOSED",1209 "sections": []},1210 {1211 "name": "form24",1212 "description": "form24 description",1213 "close_date": datetime.datetime(2020, 10, 8, 0, 0, 0),1214 "expected_delivery_date": datetime.datetime(2020, 5, 3, 0, 0, 0),1215 "status": "CLOSED",1216 "sections": []1217 },1218 {1219 "name": "form25",1220 "description": "form25 description",1221 "close_date": datetime.datetime(2020, 1, 8, 0, 0, 0),1222 "expected_delivery_date": datetime.datetime(2020, 1, 9, 0, 0, 0),1223 "status": "CLOSED",1224 "sections": []1225 },1226 {1227 "name": "form26",1228 "description": "form26 description",1229 "close_date": datetime.datetime(2020, 10, 8, 0, 0, 0),1230 "expected_delivery_date": datetime.datetime(2020, 10, 10, 0, 0, 0),1231 "status": "CLOSED",1232 "sections": []},1233 {1234 "name": "form27",1235 "description": "form27 description",1236 "close_date": datetime.datetime(2019, 10, 8, 0, 0, 0),1237 "expected_delivery_date": datetime.datetime(2019, 10, 10, 0, 0, 0),1238 "status": "CLOSED",1239 "sections": []1240 },1241 {1242 "name": "form28",1243 "description": "form28 description",1244 "close_date": datetime.datetime(2019, 10, 8, 0, 0, 0),1245 "expected_delivery_date": datetime.datetime(2019, 10, 10, 0, 0, 0),1246 "status": "CLOSED",1247 "sections": []1248 },1249 {1250 "name": "form29",1251 "description": "form29 description",1252 "close_date": datetime.datetime(2019, 10, 8, 0, 0, 0),1253 "expected_delivery_date": datetime.datetime(2019, 10, 10, 0, 0, 0),1254 "status": "CLOSED",1255 "sections": []},1256 {1257 "name": "form30",1258 "description": "form30 description",1259 "close_date": datetime.datetime(2019, 10, 8, 0, 0, 0),1260 "expected_delivery_date": datetime.datetime(2019, 10, 10, 0, 0, 0),1261 "status": "CLOSED",1262 "sections": []1263 },1264 ]1265new_orders_list = [1266# user 1 order live1267 { 1268 "user_id":1,1269 "form_id": 1,1270 "section_id":1,1271 "item_id": 1,1272 "brand_id": 1,1273 "count": 7,1274 "pending_count": 0,1275 "out_of_stock": 01276 },1277 { 1278 "user_id":1,1279 "form_id": 1,1280 "section_id":2,1281 "item_id": 3,1282 "brand_id": 7,1283 "count": 10,1284 "pending_count": 0,1285 "out_of_stock": 01286 },1287 { 1288 "user_id":1,1289 "form_id": 1,1290 "section_id": 1,1291 "item_id": 2,1292 "brand_id": 4,1293 "count": 5,1294 "pending_count": 0,1295 "out_of_stock": 01296 },1297 { 1298 "user_id":1,1299 "form_id": 2,1300 "section_id": 3,1301 "item_id": 5,1302 "brand_id": 13,1303 "count": 3,1304 "pending_count": 3,1305 "out_of_stock": 01306 },1307 { 1308 "user_id":1,1309 "form_id": 2,1310 "section_id": 3,1311 "item_id": 6,1312 "brand_id": 16,1313 "count": 7,1314 "pending_count": 0,1315 "out_of_stock": 01316 },1317 { 1318 "user_id": 1,1319 "form_id": 2,1320 "section_id": 4,1321 "item_id": 7,1322 "brand_id": 18,1323 "count": 6,1324 "pending_count": 3,1325 "out_of_stock": 01326 },1327 { 1328 "user_id": 1,1329 "form_id": 2,1330 "section_id": 4,1331 "item_id": 8,1332 "brand_id": 24,1333 "count": 3,1334 "pending_count": 0,1335 "out_of_stock": 01336 },1337# done form done1338 { 1339 "user_id": 1,1340 "form_id": 3,1341 "section_id": 5,1342 "item_id": 9,1343 "brand_id": 25,1344 "count": 3,1345 "pending_count": 0,1346 "out_of_stock": 01347 },1348 { 1349 "user_id": 1,1350 "form_id": 3,1351 "section_id": 5,1352 "item_id": 10,1353 "brand_id": 29,1354 "count": 3,1355 "pending_count": 0,1356 "out_of_stock": 01357 },1358 { 1359 "user_id": 1,1360 "form_id": 3,1361 "section_id": 6,1362 "item_id": 11,1363 "brand_id": 32,1364 "count": 4,1365 "pending_count": 0,1366 "out_of_stock": 01367 },1368 { 1369 "user_id": 1,1370 "form_id": 3,1371 "section_id": 6,1372 "item_id": 12,1373 "brand_id": 35,1374 "count": 5,1375 "pending_count": 0,1376 "out_of_stock": 01377 },1378# user 2 order live1379 { 1380 "user_id": 2,1381 "form_id": 1,1382 "section_id":1,1383 "item_id": 1,1384 "brand_id": 1,1385 "count": 7,1386 "pending_count": 0,1387 "out_of_stock": 01388 },1389 { 1390 "user_id": 2,1391 "form_id": 1,1392 "section_id":2,1393 "item_id": 3,1394 "brand_id": 7,1395 "count": 10,1396 "pending_count": 0,1397 "out_of_stock": 01398 },1399 { 1400 "user_id": 2,1401 "form_id": 1,1402 "section_id": 1,1403 "item_id": 2,1404 "brand_id": 4,1405 "count": 5,1406 "pending_count": 0,1407 "out_of_stock": 01408 },1409# closed form1410 { 1411 "user_id": 2,1412 "form_id": 2,1413 "section_id": 3,1414 "item_id": 5,1415 "brand_id": 13,1416 "count": 3,1417 "pending_count": 3,1418 "out_of_stock": 01419 },1420 { 1421 "user_id": 2,1422 "form_id": 2,1423 "section_id": 3,1424 "item_id": 6,1425 "brand_id": 16,1426 "count": 7,1427 "pending_count": 0,1428 "out_of_stock": 01429 },1430 { 1431 "user_id": 2,1432 "form_id": 2,1433 "section_id": 4,1434 "item_id": 7,1435 "brand_id": 18,1436 "count": 6,1437 "pending_count": 3,1438 "out_of_stock": 01439 },1440 { 1441 "user_id": 2,1442 "form_id": 2,1443 "section_id": 4,1444 "item_id": 8,1445 "brand_id": 24,1446 "count": 3,1447 "pending_count": 0,1448 "out_of_stock": 01449 },1450# done form done1451 { 1452 "user_id": 2,1453 "form_id": 3,1454 "section_id": 5,1455 "item_id": 9,1456 "brand_id": 25,1457 "count": 3,1458 "pending_count": 0,1459 "out_of_stock": 01460 },1461 { 1462 "user_id": 2,1463 "form_id": 3,1464 "section_id": 5,1465 "item_id": 10,1466 "brand_id": 29,1467 "count": 3,1468 "pending_count": 0,1469 "out_of_stock": 01470 },1471 { 1472 "user_id": 2,1473 "form_id": 3,1474 "section_id": 6,1475 "item_id": 11,1476 "brand_id": 32,1477 "count": 4,1478 "pending_count": 0,1479 "out_of_stock": 01480 },1481 { 1482 "user_id": 2,1483 "form_id": 3,1484 "section_id": 6,1485 "item_id": 12,1486 "brand_id": 35,1487 "count": 5,1488 "pending_count": 0,1489 "out_of_stock": 01490 },1491# user 3 order live1492 { 1493 "user_id": 3,1494 "form_id": 1,1495 "section_id":1,1496 "item_id": 1,1497 "brand_id": 1,1498 "count": 7,1499 "pending_count": 0,1500 "out_of_stock": 01501 },1502 { 1503 "user_id": 3,1504 "form_id": 1,1505 "section_id":2,1506 "item_id": 3,1507 "brand_id": 7,1508 "count": 10,1509 "pending_count": 0,1510 "out_of_stock": 01511 },1512 { 1513 "user_id": 3,1514 "form_id": 1,1515 "section_id": 1,1516 "item_id": 2,1517 "brand_id": 4,1518 "count": 5,1519 "pending_count": 0,1520 "out_of_stock": 01521 },1522# closed form1523 { 1524 "user_id": 3,1525 "form_id": 2,1526 "section_id": 3,1527 "item_id": 5,1528 "brand_id": 13,1529 "count": 3,1530 "pending_count": 3,1531 "out_of_stock": 01532 },1533 { 1534 "user_id": 3,1535 "form_id": 2,1536 "section_id": 3,1537 "item_id": 6,1538 "brand_id": 16,1539 "count": 7,1540 "pending_count": 0,1541 "out_of_stock": 01542 },1543 { 1544 "user_id": 3,1545 "form_id": 2,1546 "section_id": 4,1547 "item_id": 7,1548 "brand_id": 18,1549 "count": 6,1550 "pending_count": 3,1551 "out_of_stock": 01552 },1553 { 1554 "user_id": 3,1555 "form_id": 2,1556 "section_id": 4,1557 "item_id": 8,1558 "brand_id": 24,1559 "count": 3,1560 "pending_count": 0,1561 "out_of_stock": 01562 },1563# done form done1564 { 1565 "user_id": 3,1566 "form_id": 3,1567 "section_id": 5,1568 "item_id": 9,1569 "brand_id": 25,1570 "count": 3,1571 "pending_count": 0,1572 "out_of_stock": 01573 },1574 { 1575 "user_id": 3,1576 "form_id": 3,1577 "section_id": 5,1578 "item_id": 10,1579 "brand_id": 29,1580 "count": 3,1581 "pending_count": 0,1582 "out_of_stock": 01583 },1584 { 1585 "user_id": 3,1586 "form_id": 3,1587 "section_id": 6,1588 "item_id": 11,1589 "brand_id": 32,1590 "count": 4,1591 "pending_count": 0,1592 "out_of_stock": 01593 },1594 { 1595 "user_id": 3,1596 "form_id": 3,1597 "section_id": 6,1598 "item_id": 12,1599 "brand_id": 35,1600 "count": 5,1601 "pending_count": 0,1602 "out_of_stock": 01603 }...

Full Screen

Full Screen

test_login.py

Source:test_login.py Github

copy

Full Screen

...37 try:38 self.assertEqual(login_dict["expected"], actual)39 except AssertionError as e:40 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))41 self.login_page.screen_shot("phone_incorrect")42 raise e43 else:44 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))45 @ddt.data(*phone_format_incorrect)46 def test_login_phone_format_incorrect(self, login_dict):47 self.login_page.click_login_register_btn()48 self.login_page.login_phone(login_dict["phone"])49 actual = self.login_page.get_phone_format_incorrect50 try:51 self.assertEqual(login_dict["expected"], actual)52 except AssertionError as e:53 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))54 self.login_page.screen_shot("phone_format_incorrect")55 raise e56 else:57 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))58 @ddt.data(*phone_registered)59 def test_login_phone_registered(self, login_dict):60 self.login_page.click_login_register_btn()61 self.login_page.login_phone(login_dict["phone"])62 actual = self.login_page.get_password_label_info63 try:64 self.assertEqual(login_dict["expected"], actual)65 except AssertionError as e:66 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))67 self.login_page.screen_shot("phone_registered")68 raise e69 else:70 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))71 @ddt.data(*phone_unregister)72 def test_login_phone_unregister(self, login_dict):73 self.login_page.click_login_register_btn()74 self.login_page.login_phone(login_dict["phone"])75 actual = self.register_page.get_register_text76 try:77 self.assertEqual(login_dict["expected"], actual)78 except AssertionError as e:79 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))80 self.login_page.screen_shot("phone_unregister")81 raise e82 else:83 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))84 @ddt.data(*password_error)85 def test_login_password_error(self, login_dict):86 self.login_page.click_login_register_btn()87 self.login_page.login(login_dict["phone"], login_dict["password"])88 actual = self.login_page.get_password_error_info89 try:90 self.assertEqual(login_dict["expected"], actual)91 except AssertionError as e:92 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))93 self.login_page.screen_shot("password_error")94 raise e95 else:96 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))97 @ddt.data(*password_null)98 def test_login_password_null(self, login_dict):99 self.login_page.click_login_register_btn()100 self.login_page.login(login_dict["phone"], login_dict["password"])101 actual = self.login_page.assert_commit_is_exist102 try:103 self.assertTrue(login_dict["expected"], actual)104 except AssertionError as e:105 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))106 self.login_page.screen_shot("password_null")107 raise e108 else:109 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))110 @ddt.data(*login_success)111 def test_a_login_success(self, login_dict):112 self.login_page.click_login_register_btn()113 self.login_page.login(login_dict["phone"], login_dict["password"])114 self.user_page.click_cancel()115 self.home_page.click_myself()116 actual = self.user_page.get_name117 try:118 self.assertIn(login_dict["expected"], actual)119 except AssertionError as e:120 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))121 self.login_page.screen_shot("login_success")122 raise e123 else:124 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))125 # 点击[我的]登录流程126 @ddt.data(*phone_incorrect_data)127 def test_myself_phone_incorrect(self, login_dict):128 self.home_page.click_myself()129 self.login_page.login_phone(login_dict["phone"])130 actual = self.login_page.get_phone_error_info131 try:132 self.assertEqual(login_dict["expected"], actual)133 except AssertionError as e:134 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))135 self.login_page.screen_shot("phone_incorrect")136 raise e137 else:138 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))139 @ddt.data(*phone_format_incorrect)140 def test_myself_phone_format_incorrect(self, login_dict):141 self.home_page.click_myself()142 self.login_page.login_phone(login_dict["phone"])143 actual = self.login_page.get_phone_format_incorrect144 try:145 self.assertEqual(login_dict["expected"], actual)146 except AssertionError as e:147 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))148 self.login_page.screen_shot("phone_format_incorrect")149 raise e150 else:151 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))152 @ddt.data(*phone_registered)153 def test_myself_phone_registered(self, login_dict):154 self.home_page.click_myself()155 self.login_page.login_phone(login_dict["phone"])156 actual = self.login_page.get_password_label_info157 try:158 self.assertEqual(login_dict["expected"], actual)159 except AssertionError as e:160 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))161 self.login_page.screen_shot("phone_registered")162 raise e163 else:164 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))165 @ddt.data(*phone_unregister)166 def test_myself_phone_unregister(self, login_dict):167 self.home_page.click_myself()168 self.login_page.login_phone(login_dict["phone"])169 actual = self.register_page.get_register_text170 try:171 self.assertEqual(login_dict["expected"], actual)172 except AssertionError as e:173 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))174 self.login_page.screen_shot("phone_unregister")175 raise e176 else:177 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))178 @ddt.data(*password_error)179 def test_myself_password_error(self, login_dict):180 self.home_page.click_myself()181 self.login_page.login(login_dict["phone"], login_dict["password"])182 actual = self.login_page.get_password_error_info183 try:184 self.assertEqual(login_dict["expected"], actual)185 except AssertionError as e:186 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))187 self.login_page.screen_shot("password_error")188 raise e189 else:190 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))191 @ddt.data(*login_success)192 def test_myself_login_success(self, login_dict):193 self.home_page.click_myself()194 self.login_page.login(login_dict["phone"], login_dict["password"])195 self.user_page.click_cancel()196 actual = self.user_page.get_name197 try:198 self.assertIn(login_dict["expected"], actual)199 except AssertionError as e:200 logger.debug("测试用例:{}->失败:{}".format(inspect.stack()[0][3], e))201 self.login_page.screen_shot("login_success")202 raise e203 else:204 logger.info("测试用例:{}->通过".format(inspect.stack()[0][3]))205 def tearDown(self):206 self.driver.reset()207 logger.info("测试用例执行结束")208if __name__ == '__main__':...

Full Screen

Full Screen

BasePage.py

Source:BasePage.py Github

copy

Full Screen

1# 用来存放一些公用的方法,比如查找元素、查找一组元素、输入、左右上下滑动、截图等2# -*- encoding: utf-8 -*-3'''4@File : BasePage.py5@Time : 2021/08/15 21:46:526@Author : wangbj7@Version : 1.08@Contact : wang_bao_jin@163.com9@WebSite : https://me.csdn.net/u01009876010'''11# here put the import lib12from selenium.webdriver.support.wait import WebDriverWait13# from appium import webdriver14from selenium.webdriver.common.by import By15from selenium.webdriver.support import expected_conditions as EC16import time17from util.LoggingUtil import LoggingUtil18import logging19import datetime20class BasePage(object):21 '''类注释22 详细描述23 Attributes:24 属性说明25 '''26 def __init__(self, driver):27 '''Class1类初始化方法28 Args:29 paramter1: 入参说明30 paramter2: 入参说明31 '''32 self.driver = driver33 LoggingUtil.setup_logging(LoggingUtil)34 self.logger = logging.getLogger()35 def find_element(self, *loc):36 '''重写查找单个元素方法37 '''38 try:39 WebDriverWait(self.driver, 5, 0.5).until(40 EC.visibility_of_element_located(loc))41 return self.driver.find_element(*loc)42 except Exception:43 # print('页面未找到元素')44 self.logger.error('未找到元素:%s 请检查!' % loc[1])45 screen_shot = self.get_screen('screen_shot/')46 self.logger.error('已截图,路径:%s' % screen_shot)47 def find_elements(self, *loc):48 '''重写查找多个元素方法49 '''50 try:51 WebDriverWait(self.driver, 5, 0.5).until(52 EC.visibility_of_element_located(loc))53 return self.driver.find_elements(*loc)54 except AttributeError:55 # print('页面未找到元素')56 self.logger.error('未找到元素:%s 请检查!' % loc[1])57 screen_shot = self.get_screen('screen_shot/')58 self.logger.error('已截图,路径:%s' % screen_shot)59 def send_keys(self, loc, vaule, clear_first=True, click_first=True):60 '''重写send_keys方法61 '''62 try:63 loc = getattr(self, "_%s" % loc) # getattr相当于实现self.loc64 if click_first:65 self.find_element(*loc).click()66 if clear_first:67 self.find_element(*loc).clear()68 self.find_element(*loc).send_keys(vaule)69 except AttributeError:70 # print("页面中未能找到元素")71 self.logger.error('未找到元素:%s 请检查!' % loc[1])72 screen_shot = self.get_screen('screen_shot/')73 self.logger.error('已截图,路径:%s' % screen_shot)74 def is_toast_exist(self, text):75 '''is toast exist, return True or False76 :Agrs:77 - text - 页面上看到的文本内容78 :Usage:79 is_toast_exist("看到的内容")80 '''81 try:82 toast_loc = (By.XPATH, ".//*[contains(@text,'%s')]" % text)83 WebDriverWait(self.driver, 5, 0.5).until(84 EC.presence_of_element_located(toast_loc))85 return True86 except Exception as e:87 print(e)88 self.logger.error('未找到元素:%s 请检查!' % text)89 screen_shot = self.get_screen('screen_shot/')90 self.logger.error('已截图,路径:%s' % screen_shot)91 return False92 def is_element_exist(self, *loc):93 try:94 WebDriverWait(self.driver, 5, 0.5).until(95 EC.visibility_of_element_located(loc))96 self.driver.find_element(*loc)97 return True98 except Exception:99 # print('页面未找到%s元素' % (loc))100 self.logger.error('未找到元素:%s 请检查!' % loc[1])101 screen_shot = self.get_screen('screen_shot/')102 self.logger.error('已截图,路径:%s' % screen_shot)103 return False104 def get_size(self):105 '''获取屏幕大小106 '''107 try:108 size = self.driver.get_window_size()109 return size110 except Exception:111 self.get_screen('screen_shot/')112 return None113 def swipe_to_left(self):114 '''左滑115 '''116 window_size = self.get_size()117 width = window_size.get("width")118 height = window_size.get("height")119 try:120 self.driver.swipe(width*0.9, height*0.5, width*0.1, height*0.5)121 time.sleep(0.5)122 except Exception:123 self.get_screen('screen_shot/')124 # self.driver.swipe(x*0.9, y*0.5, x*0.1, y*0.5)125 def swipe_to_right(self):126 '''右滑127 '''128 window_size = self.get_size()129 width = window_size.get("width")130 height = window_size.get("height")131 try:132 self.driver.swipe(width*0.1, height*0.5, width*0.9, height*0.5)133 time.sleep(0.5)134 except Exception:135 self.get_screen('screen_shot/')136 def swipe_to_up(self):137 '''上滑138 '''139 window_size = self.get_size()140 width = window_size.get("width")141 height = window_size.get("height")142 try:143 self.driver.swipe(width*0.5, height*0.9, width*0.5, height*0.1)144 time.sleep(0.5)145 except Exception:146 self.get_screen('screen_shot/')147 def swipe_to_down(self):148 '''下滑、下拉刷新149 '''150 window_size = self.get_size()151 width = window_size.get("width")152 height = window_size.get("height")153 try:154 self.driver.swipe(width*0.5, height*0.4, width*0.5, height*0.9)155 time.sleep(1)156 except Exception:157 self.get_screen('screen_shot/')158 def get_screen(self, path):159 '''截图160 '''161 now = datetime.datetime.now().strftime('%Y%m%d%H%M%S')162 screen_shot = path + 'a_' + now + '.png'163 self.driver.get_screenshot_as_file(screen_shot)164 return screen_shot165if __name__ == '__main__':...

Full Screen

Full Screen

BobsTasks.py

Source:BobsTasks.py Github

copy

Full Screen

...11 def on_screen(self) -> bool:12 if self.get_locations():13 return True14 return False15 def is_fulfilled(self, screen_shot=Condition.create_screen_shot()) -> bool:16 """17 Assumes condition is fulfilled if one click location is found.18 :param screen_shot:19 :return:20 """21 if len(self.get_locations(screen_shot)) > 0:22 return True23 return False24 @abstractmethod25 def get_locations(self, screen_shot=None):26 pass27 def click(self, screen_shot=None):28 screen_shot = Condition.create_screen_shot(screen_shot)29 locations = self.get_locations(screen_shot)30 if len(locations[0]) <4:31 pyautogui.click(locations[0][0], locations[0][1])32 else:33 pyautogui.click(locations[0][0] + locations[0][2]/2, locations[0][1] + locations[0][3]/2)34 @property35 def key(self):36 return self._key37 @staticmethod38 def type_key():39 return 'abstract'40 @staticmethod41 def show_boxes(img=None, data=None):42 if img is None:43 img = np.array(pyautogui.screenshot())44 if data is None:45 data = pytesseract.image_to_data(img, lang='eng', output_type=pytesseract.Output.DATAFRAME)46 for i in range(len(data)):47 (x, y, w, h) = (data['left'][i], data['top'][i], data['width'][i], data['height'][i])48 cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)49 cv2.imshow('img', img)50class ImgBasedButton(Button):51 def __init__(self, key, img, confidence=None):52 super().__init__(key)53 self._img = cv2.imread(img, 0)54 self._confidence = confidence55 @staticmethod56 def type_key():57 return 'img_based'58 def get_locations(self, screen_shot=None):59 if screen_shot is None:60 screen_shot = np.array(pyautogui.screenshot())61 img_gray = cv2.cvtColor(screen_shot, cv2.COLOR_BGR2GRAY)62 cv2.imshow('img', img_gray)63 cv2.imshow('template', self._img)64 w, h = self._img.shape[:2]65 res = cv2.matchTemplate(img_gray, self._img, ImgBasedButton.get_matching_method('ccoeff_normed'))66 if self._confidence:67 loc = np.where(res >= 0.8)68 # cv2.imshow('res', res)69 locations = []70 for pt in zip(*loc[::-1]):71 locations.append([pt[0], pt[1], w, h])72 return locations73 min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)74 return [*max_loc, w, h]75 @staticmethod76 def get_matching_method(key=''):77 if key == '':78 return cv2.TM_CCOEFF79 if key == 'ccoeff_normed':80 return cv2.TM_CCOEFF_NORMED81 if key == '':82 return cv2.TM_CCORR83 if key == '':84 return cv2.TM_CCORR_NORMED85 if key == '':86 return cv2.TM_SQDIFF87 if key == '':88 return cv2.TM_SQDIFF_NORMED89 raise ValueError(f'The specified matching method ({key}) is not known.')90class TextBasedButton(Button):91 _last_image = None92 _last_result = None93 def __init__(self, key, text, screen_fac=1):94 super().__init__(key)95 self._text = text96 self._screen_fac = screen_fac97 @staticmethod98 def type_key():99 return 'text_base'100 @staticmethod101 def evaluate_img(img):102 if TextBasedButton._last_image is not None and np.all(img == TextBasedButton._last_image):103 return TextBasedButton._last_result104 TextBasedButton._last_image = img105 TextBasedButton._last_result = pytesseract.image_to_data(img,106 lang='eng', output_type=pytesseract.Output.DATAFRAME)107 return TextBasedButton._last_result108 def get_locations(self, screen_shot=None):109 if screen_shot is None:110 screen_shot = np.array(pyautogui.screenshot())111 if not self._screen_fac == 1:112 screen_shot = cv2.resize(screen_shot,113 (screen_shot.shape[1] * self._screen_fac, screen_shot.shape[0] * self._screen_fac))114 data = TextBasedButton.evaluate_img(screen_shot)115 conf = data[data['conf'] > 10]116 selected_data = conf[conf['text'].str.contains(self._text)]117 locations = selected_data[['left', 'top', 'width', 'height']].to_numpy() / self._screen_fac118 return locations119class ImgAndTextBasedButton(Button):120 def __init__(self, key, img, text=None):121 super().__init__(key)122 self._img = cv2.imread(img)123 if text:124 self._text = text125 else:126 self._text = pytesseract.image_to_string(self._img)127class NeighborhoodCondition(Condition):128 def __init__(self, key, center: Button, neighbors: Button, distance: float):129 super().__init__(key)130 self._center = center131 self._neighbors = neighbors if isinstance(neighbors, list) else [neighbors]132 self._distance2 = distance ** 2133 def is_fulfilled(self, screen_shot=Condition.create_screen_shot()) -> bool:134 self_loc = self._center.get_locations(screen_shot)135 for neighbor in self._neighbors:136 new_loc = neighbor.get_locations(screen_shot)137 distances2 = np.array([(loc[0] - self_loc[0]) ** 2 + (loc[1] - self_loc[1]) ** 2 for loc in new_loc])138 if not np.any(distances2 < self._distance2):139 return False140 return True141class DeviationNeighborhoodButton(Button):142 def __init__(self, key, button: Button, partner: Button, threshold_x=None, threshold_y=None):143 super().__init__(key)144 self._button = button145 self._partner = partner146 self._threshold_x = threshold_x147 self._threshold_y = threshold_y148 def get_locations(self, screen_shot=None):149 screen_shot = Condition.create_screen_shot(screen_shot)150 locations = self._button.get_locations(screen_shot)151 locations_partner = self._partner.get_locations(screen_shot)152 output = []153 for location in locations:154 dev_x = location[0]-locations_partner[:, 0]155 dev_y = location[1]-locations_partner[:, 1]156 f_x = self._threshold_x[0] < dev_x < self._threshold_x[1]157 f_y = self._threshold_y[0] < dev_y < self._threshold_y[1]158 if np.any(f_x & f_y):159 output.append(location)...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

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