How to use current_url method in pytractor

Best Python code snippet using pytractor_python

test_cfp_wizard.py

Source:test_cfp_wizard.py Github

copy

Full Screen

1import datetime as dt2from urllib.parse import urlparse3import bs44import pytest5from django import forms as forms6from django.core import mail as djmail7from django.core.files.uploadedfile import SimpleUploadedFile8from django.http.request import QueryDict9from django.utils.timezone import now10from django_scopes import scope, scopes_disabled11from pretalx.submission.forms import InfoForm12from pretalx.submission.models import Submission, SubmissionType13class TestWizard:14 @staticmethod15 def get_response_and_url(client, url, follow=True, method="POST", data=None):16 if method == "GET":17 response = client.get(url, follow=follow, data=data)18 else:19 response = client.post(url, follow=follow, data=data)20 try:21 current_url = response.redirect_chain[-1][0]22 except IndexError: # We are not being redirected at all!23 current_url = url24 return response, current_url25 def perform_init_wizard(self, client, success=True, event=None, access_code=None):26 # Start wizard27 djmail.outbox = []28 url = "/test/submit/"29 if access_code:30 url += f"?access_code={access_code.code}"31 response, current_url = self.get_response_and_url(client, url, method="GET")32 assert ("/info/" in current_url) is success33 return response, current_url34 def perform_info_wizard(35 self,36 client,37 response,38 url,39 next_step="questions",40 title="Submission title",41 content_locale="en",42 description="Description",43 abstract="Abstract",44 notes="Notes",45 slot_count=1,46 submission_type=None,47 event=None,48 track=None,49 additional_speaker=None,50 ):51 submission_data = {52 "title": title,53 "content_locale": content_locale,54 "description": description,55 "abstract": abstract,56 "notes": notes,57 "slot_count": slot_count,58 "submission_type": submission_type,59 "additional_speaker": additional_speaker or "",60 }61 if track:62 submission_data["track"] = getattr(track, "pk", track)63 response, current_url = self.get_response_and_url(64 client, url, data=submission_data65 )66 assert (67 f"/{next_step}/" in current_url68 ), f"{current_url} does not end with /{next_step}/!"69 return response, current_url70 def perform_question_wizard(71 self, client, response, url, data, next_step="profile", event=None72 ):73 response, current_url = self.get_response_and_url(client, url, data=data)74 assert (75 f"/{next_step}/" in current_url76 ), f"{current_url} does not end with /{next_step}/!"77 return response, current_url78 def perform_user_wizard(79 self,80 client,81 response,82 url,83 password,84 next_step="profile",85 email=None,86 register=False,87 event=None,88 ):89 if register:90 data = {91 "register_name": email,92 "register_email": email,93 "register_password": password,94 "register_password_repeat": password,95 }96 else:97 data = {"login_email": email, "login_password": password}98 response, current_url = self.get_response_and_url(client, url, data=data)99 assert (100 f"/{next_step}/" in current_url101 ), f"{current_url} does not end with /{next_step}/!"102 return response, current_url103 def perform_profile_form(104 self,105 client,106 response,107 url,108 name="Jane Doe",109 bio="l337 hax0r",110 next_step="me/submissions",111 event=None,112 success=True,113 ):114 data = {"name": name, "biography": bio}115 response, current_url = self.get_response_and_url(client, url, data=data)116 assert (117 f"/{next_step}/" in current_url118 ), f"{current_url} does not end with /{next_step}/!"119 doc = bs4.BeautifulSoup(response.rendered_content, "lxml")120 assert bool(doc.select(".alert-success")) is success121 assert bool(doc.select("#user-dropdown-label")) is success122 return response, current_url123 def assert_submission(124 self,125 event,126 title="Submission title",127 content_locale="en",128 description="Description",129 abstract="Abstract",130 notes="Notes",131 question=None,132 answer="42",133 track=None,134 ):135 with scope(event=event):136 sub = Submission.objects.last()137 assert sub.title == title138 assert sub.submission_type is not None139 assert sub.content_locale == content_locale140 assert sub.description == description141 assert sub.abstract == abstract142 assert sub.notes == notes143 assert sub.slot_count == 1144 if question:145 answ = sub.answers.first()146 assert answ147 assert answ.question == question148 assert answ.answer == answer149 else:150 assert sub.answers.count() == 0151 if track:152 assert sub.track == track153 else:154 assert sub.track is None155 return sub156 def assert_user(157 self,158 submission,159 email="testuser@example.com",160 name="Jane Doe",161 biography="l337 hax0r",162 question=None,163 answer=None,164 ):165 with scope(event=submission.event):166 user = submission.speakers.get(email=email)167 assert user.name == name168 assert user.profiles.get(event=submission.event).biography == biography169 if question:170 answ = user.answers.filter(question__target="speaker").first()171 assert answ172 assert answ.question == question173 assert answ.person == user174 assert not answ.submission175 assert answ.answer == "green"176 return user177 def assert_mail(self, submission, user, count=1, extra=None):178 assert len(djmail.outbox) == count179 mail = djmail.outbox[0 if not extra else 1]180 assert submission.title in mail.subject181 assert submission.title in mail.body182 assert user.email in mail.to183 if extra:184 assert djmail.outbox[0].to == [extra]185 @pytest.mark.django_db186 def test_info_wizard_query_string_handling(self, event, client, track):187 # build query string188 params_dict = QueryDict(f"track={track.pk}&submission_type=academic_talk")189 current_url = "/test/submit/?{params_dict}"190 # Start wizard191 _, current_url = self.get_response_and_url(client, current_url, method="GET")192 # get query string from current URL193 url_parts = urlparse(current_url)194 q = QueryDict(url_parts.query)195 assert url_parts.path.endswith("/info/") is True196 assert q.get("track") == params_dict.get("academic")197 assert q.get("submission_type") == params_dict.get("academic_talk")198 @pytest.mark.django_db199 def test_wizard_new_user(self, event, question, client):200 event.mail_settings["mail_on_new_submission"] = True201 event.save()202 with scope(event=event):203 submission_type = SubmissionType.objects.filter(event=event).first()204 submission_type.deadline = event.cfp.deadline205 submission_type.save()206 event.deadline = now() - dt.timedelta(days=1)207 event.locale_array = "de,en"208 event.save()209 submission_type = submission_type.pk210 answer_data = {f"question_{question.pk}": "42"}211 response, current_url = self.perform_init_wizard(client, event=event)212 response, current_url = self.perform_info_wizard(213 client,214 response,215 current_url + f"?submission_type={submission_type}-helpful-slug",216 submission_type=submission_type,217 event=event,218 )219 response, current_url = self.perform_question_wizard(220 client, response, current_url, answer_data, next_step="user", event=event221 )222 # Try to login first, then remember you don't have an account yet223 response, current_url = self.perform_user_wizard(224 client,225 response,226 current_url,227 email="wrong@example.org",228 password="testpassw0rd!",229 event=event,230 next_step="user",231 )232 response, current_url = self.perform_user_wizard(233 client,234 response,235 current_url,236 password="testpassw0rd!",237 email="testuser@example.com",238 register=True,239 event=event,240 )241 response, current_url = self.perform_profile_form(242 client, response, current_url, event=event243 )244 submission = self.assert_submission(event, question=question)245 self.assert_user(submission, email="testuser@example.com")246 assert len(djmail.outbox) == 2 # user email plus orga email247 @pytest.mark.django_db248 def test_wizard_existing_user(249 self,250 event,251 client,252 question,253 user,254 speaker_question,255 choice_question,256 multiple_choice_question,257 file_question,258 ):259 with scope(event=event):260 event.cfp.deadline = now() + dt.timedelta(days=1)261 event.save()262 submission_type = SubmissionType.objects.filter(event=event).first().pk263 answer_data = {264 f"question_{question.pk}": "42",265 f"question_{speaker_question.pk}": "green",266 f"question_{choice_question.pk}": choice_question.options.first().pk,267 f"question_{multiple_choice_question.pk}": multiple_choice_question.options.first().pk,268 f"question_{file_question.pk}": SimpleUploadedFile(269 "testfile.txt", b"file_content"270 ),271 }272 response, current_url = self.perform_init_wizard(client, event=event)273 response, current_url = self.perform_info_wizard(274 client,275 response,276 current_url + "?submission_type=123-helpful-slug",277 submission_type=submission_type,278 event=event,279 )280 response, current_url = self.perform_question_wizard(281 client,282 response,283 current_url,284 answer_data,285 next_step="user",286 event=event,287 )288 response, current_url = self.perform_user_wizard(289 client,290 response,291 current_url,292 email=user.email,293 password="testpassw0rd!",294 event=event,295 )296 response, current_url = self.perform_profile_form(297 client, response, current_url, event=event298 )299 submission = self.assert_submission(event, question=question)300 user = self.assert_user(submission, question=speaker_question, answer="green")301 self.assert_mail(submission, user)302 with scope(event=event):303 assert file_question.answers.first().answer_file.read() == b"file_content"304 @pytest.mark.django_db305 def test_wizard_logged_in_user(306 self, event, client, question, user, review_question307 ):308 with scope(event=event):309 submission_type = SubmissionType.objects.filter(event=event).first().pk310 answer_data = {f"question_{question.pk}": "42"}311 client.force_login(user)312 response, current_url = self.perform_init_wizard(client, event=event)313 response, current_url = self.perform_info_wizard(314 client,315 response,316 current_url,317 submission_type=submission_type,318 event=event,319 )320 response, current_url = self.perform_question_wizard(321 client,322 response,323 current_url,324 answer_data,325 event=event,326 )327 response, current_url = self.perform_profile_form(328 client, response, current_url, event=event329 )330 submission = self.assert_submission(event, question=question)331 user = self.assert_user(submission)332 self.assert_mail(submission, user)333 @pytest.mark.django_db334 def test_wizard_logged_in_user_no_questions(self, event, client, user):335 with scope(event=event):336 submission_type = SubmissionType.objects.filter(event=event).first().pk337 client.force_login(user)338 response, current_url = self.perform_init_wizard(client, event=event)339 response, current_url = self.perform_info_wizard(340 client,341 response,342 current_url,343 submission_type=submission_type,344 next_step="profile",345 event=event,346 additional_speaker="additional@example.com",347 )348 response, current_url = self.perform_profile_form(349 client, response, current_url, event=event350 )351 submission = self.assert_submission(event)352 user = self.assert_user(submission)353 self.assert_mail(submission, user, extra="additional@example.com", count=2)354 @pytest.mark.django_db355 def test_wizard_logged_in_user_additional_speaker_mail_fail(356 self, event, client, user357 ):358 with scope(event=event):359 submission_type = SubmissionType.objects.filter(event=event).first().pk360 event.mail_settings["smtp_use_custom"] = True361 event.save()362 client.force_login(user)363 response, current_url = self.perform_init_wizard(client, event=event)364 response, current_url = self.perform_info_wizard(365 client,366 response,367 current_url,368 submission_type=submission_type,369 next_step="profile",370 event=event,371 additional_speaker="additional@example.com",372 )373 response, current_url = self.perform_profile_form(374 client, response, current_url, event=event375 )376 submission = self.assert_submission(event)377 user = self.assert_user(submission)378 assert len(djmail.outbox) == 0379 @pytest.mark.django_db380 def test_wizard_logged_in_user_only_review_questions(381 self, event, client, user, review_question382 ):383 with scope(event=event):384 submission_type = SubmissionType.objects.filter(event=event).first().pk385 client.force_login(user)386 response, current_url = self.perform_init_wizard(client, event=event)387 response, current_url = self.perform_info_wizard(388 client,389 response,390 current_url,391 submission_type=submission_type,392 next_step="profile",393 event=event,394 )395 response, current_url = self.perform_profile_form(396 client, response, current_url, event=event397 )398 submission = self.assert_submission(event)399 user = self.assert_user(submission)400 self.assert_mail(submission, user)401 @pytest.mark.django_db402 def test_wizard_logged_in_user_no_questions_broken_template(403 self, event, client, user404 ):405 with scope(event=event):406 submission_type = SubmissionType.objects.filter(event=event).first().pk407 event.ack_template.text = (408 str(event.ack_template.text) + "{name} and {nonexistent}"409 )410 event.ack_template.save()411 client.force_login(user)412 response, current_url = self.perform_init_wizard(client, event=event)413 response, current_url = self.perform_info_wizard(414 client,415 response,416 current_url,417 submission_type=submission_type,418 next_step="profile",419 event=event,420 )421 response, current_url = self.perform_profile_form(422 client, response, current_url, event=event423 )424 submission = self.assert_submission(event)425 user = self.assert_user(submission)426 assert len(djmail.outbox) == 0427 @pytest.mark.django_db428 def test_wizard_with_tracks(self, event, client, track, other_track):429 with scope(event=event):430 submission_type = SubmissionType.objects.filter(event=event).first().pk431 event.cfp.fields["track"]["visibility"] = "required"432 event.cfp.save()433 response, current_url = self.perform_init_wizard(client, event=event)434 response, current_url = self.perform_info_wizard(435 client,436 response,437 current_url,438 submission_type=submission_type,439 next_step="user",440 event=event,441 track=track,442 )443 response, current_url = self.perform_user_wizard(444 client,445 response,446 current_url,447 password="testpassw0rd!",448 email="testuser@example.com",449 register=True,450 event=event,451 )452 response, current_url = self.perform_profile_form(453 client, response, current_url, event=event454 )455 submission = self.assert_submission(event, track=track)456 user = self.assert_user(submission, email="testuser@example.com")457 self.assert_mail(submission, user)458 @pytest.mark.django_db459 def test_wizard_cfp_closed(self, event, client, user):460 event.cfp.deadline = now() - dt.timedelta(days=1)461 event.cfp.save()462 client.force_login(user)463 self.perform_init_wizard(client, success=False, event=event)464 @pytest.mark.django_db465 def test_wizard_cfp_closed_access_code(self, event, client, access_code):466 with scope(event=event):467 submission_type = SubmissionType.objects.filter(event=event).first().pk468 event.cfp.deadline = now() - dt.timedelta(days=1)469 event.cfp.save()470 response, current_url = self.perform_init_wizard(471 client, event=event, access_code=access_code472 )473 response, current_url = self.perform_info_wizard(474 client,475 response,476 current_url,477 submission_type=submission_type,478 event=event,479 next_step="user",480 )481 response, current_url = self.perform_user_wizard(482 client,483 response,484 current_url,485 password="testpassw0rd!",486 email="testuser@example.com",487 register=True,488 event=event,489 )490 response, current_url = self.perform_profile_form(491 client, response, current_url, event=event492 )493 submission = self.assert_submission(event)494 assert submission.access_code == access_code495 @pytest.mark.django_db496 def test_wizard_cfp_closed_expired_access_code(self, event, client, access_code):497 event.cfp.deadline = now() - dt.timedelta(days=1)498 event.cfp.save()499 access_code.valid_until = now() - dt.timedelta(hours=1)500 access_code.save()501 response, current_url = self.perform_init_wizard(502 client, event=event, access_code=access_code, success=False503 )504 @pytest.mark.django_db505 def test_wizard_track_access_code_and_question(506 self,507 event,508 client,509 access_code,510 track,511 other_track,512 question,513 ):514 with scope(event=event):515 submission_type = SubmissionType.objects.filter(event=event).first().pk516 event.cfp.fields["track"]["visibility"] = "required"517 event.cfp.fields["abstract"]["visibility"] = "do_not_ask"518 event.cfp.save()519 track.requires_access_code = True520 track.save()521 question.tracks.add(track)522 other_track.requires_access_code = True523 other_track.save()524 access_code.track = track525 access_code.submission_type = event.cfp.default_type526 access_code.save()527 response, current_url = self.perform_init_wizard(client, event=event)528 self.perform_info_wizard( # Does not work without token529 client,530 response,531 current_url,532 submission_type=submission_type,533 next_step="info",534 event=event,535 track=track,536 )537 (538 response,539 current_url,540 ) = self.perform_info_wizard( # Works with token and right track541 client,542 response,543 current_url + "?access_code=" + access_code.code,544 submission_type=submission_type,545 next_step="questions",546 event=event,547 track=track,548 )549 answer_data = {f"question_{question.pk}": 42}550 response, current_url = self.perform_question_wizard(551 client, response, current_url, answer_data, next_step="user", event=event552 )553 response, current_url = self.perform_user_wizard(554 client,555 response,556 current_url,557 password="testpassw0rd!",558 email="testuser@example.com",559 register=True,560 event=event,561 )562 response, current_url = self.perform_profile_form(563 client, response, current_url, event=event564 )565 self.assert_submission(event, track=track, question=question, abstract=None)566 @pytest.mark.django_db567 def test_wizard_submission_type_access_code(self, event, client, access_code):568 with scope(event=event):569 submission_type = SubmissionType.objects.filter(event=event).first()570 submission_type.requires_access_code = True571 submission_type.save()572 submission_type = submission_type.pk573 response, current_url = self.perform_init_wizard(client, event=event)574 (575 response,576 current_url,577 ) = self.perform_info_wizard( # Does not work without access token578 client,579 response,580 current_url,581 submission_type=submission_type,582 next_step="info",583 event=event,584 )585 response, current_url = self.perform_info_wizard(586 client,587 response,588 current_url + "?access_code=" + access_code.code,589 submission_type=submission_type,590 next_step="user",591 event=event,592 )593 response, current_url = self.perform_user_wizard(594 client,595 response,596 current_url,597 password="testpassw0rd!",598 email="testuser@example.com",599 register=True,600 event=event,601 )602 response, current_url = self.perform_profile_form(603 client, response, current_url, event=event604 )605 self.assert_submission(event)606 @pytest.mark.django_db607 def test_wizard_request_missing_step(self, event, client):608 _, current_url = self.perform_init_wizard(client, event=event)609 response = client.get(current_url.replace("info", "wrooooong"))610 assert response.status_code == 404611 @pytest.mark.django_db612 def test_wizard_existing_user_twice(613 self,614 event,615 client,616 user,617 speaker_question,618 ):619 with scope(event=event):620 assert event.submissions.count() == 0621 assert speaker_question.answers.count() == 0622 submission_type = SubmissionType.objects.filter(event=event).first().pk623 answer_data = {f"question_{speaker_question.pk}": "green"}624 client.force_login(user)625 for _ in range(2):626 response, current_url = self.perform_init_wizard(client, event=event)627 response, current_url = self.perform_info_wizard(628 client,629 response,630 current_url,631 submission_type=submission_type,632 event=event,633 )634 response, current_url = self.perform_question_wizard(635 client,636 response,637 current_url,638 answer_data,639 event=event,640 )641 response, current_url = self.perform_profile_form(642 client, response, current_url, event=event643 )644 submission = self.assert_submission(event)645 self.assert_user(submission, question=speaker_question, answer="green")646 with scope(event=event):647 assert event.submissions.count() == 2648 assert speaker_question.answers.count() == 1649@pytest.mark.django_db650def test_infoform_set_submission_type(event, other_event):651 # https://github.com/pretalx/pretalx/issues/642652 with scopes_disabled():653 assert len(SubmissionType.objects.all()) > 1654 with scope(event=event):655 f = InfoForm(event)656 assert len(event.submission_types.all()) == 1657 assert "submission_type" not in f.fields658 assert f.initial["submission_type"] == event.submission_types.first()659 assert "submission_type" not in f.fields660@pytest.mark.django_db661def test_infoform_set_submission_type_2nd_event(event, other_event, submission_type):662 # https://github.com/pretalx/pretalx/issues/642663 with scopes_disabled():664 assert len(SubmissionType.objects.all()) > 1665 with scope(event=event):666 f = InfoForm(event)667 assert len(event.submission_types.all()) == 2668 assert len(f.fields["submission_type"].queryset) == 2...

Full Screen

Full Screen

test_admin_forms_infant.py

Source:test_admin_forms_infant.py Github

copy

Full Screen

1# import time2#3# from selenium.webdriver.common.keys import Keys4#5# # from .base_selenium_test import BaseSeleniumTest6#7#8# class TestAdminFormsInfant(BaseSeleniumTest):9#10# def login_navigate_to_admin(self):11# self.login()12# time.sleep(1)13# self.browser.get(self.live_server_url + '/admin/microbiome/')14#15# def test_infant_birth_admin(self):16# self.login_navigate_to_admin()17# time.sleep(1)18# self.browser.find_element_by_link_text('Infant Birth Feeding & Vaccinations').click()19# time.sleep(1)20# self.assertIn('infantbirthfeedvaccine/', self.browser.current_url)21# self.browser.get(self.browser.current_url + 'add/')22# self.browser.save_screenshot('microbiome/screenshots/infant_birth_admin.png')23#24# def test_infant_birth_arv_admin(self):25# self.login_navigate_to_admin()26# time.sleep(1)27# self.browser.find_element_by_link_text('Infant Birth Record: ARVs').click()28# time.sleep(1)29# self.assertIn('infantbirtharv/', self.browser.current_url)30# self.browser.get(self.browser.current_url + 'add/')31# self.browser.save_screenshot('microbiome/screenshots/infant_birth_arv_admin.png')32#33# def test_infant_birth_exam_admin(self):34# self.login_navigate_to_admin()35# time.sleep(1)36# self.browser.find_element_by_partial_link_text('Infant Birth Record: Exams').click()37# time.sleep(1)38# self.assertIn('infantbirthexam/', self.browser.current_url)39# self.browser.get(self.browser.current_url + 'add/')40# self.browser.save_screenshot('microbiome/screenshots/infact_birth_exam_admin.png')41#42# def test_infant_birth_records(self):43# self.login_navigate_to_admin()44# self.browser.find_element_by_partial_link_text('Infant Birth Records').click()45# time.sleep(1)46# self.assertIn('infantbirth/', self.browser.current_url)47# self.browser.get(self.browser.current_url + 'add/')48# self.browser.save_screenshot('microbiome/screenshots/infact_birth_records.png')49#50# def test_infant_congenital_anomalies_cardio(self):51# self.login_navigate_to_admin()52# self.browser.find_element_by_partial_link_text('Infant Congenital Anomalies:Cardios').click()53# time.sleep(1)54# self.assertIn('infantcardiovasculardisorderitems/', self.browser.current_url)55# self.browser.get(self.browser.current_url + 'add/')56# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_cardio.png')57#58# def test_infant_congenital_anomalies_cleft(self):59# self.login_navigate_to_admin()60# self.browser.find_element_by_partial_link_text('Infant Congenital Anomalies:Cleft').click()61# time.sleep(1)62# self.assertIn('infantcleftdisorderitems/', self.browser.current_url)63# self.browser.get(self.browser.current_url + 'add/')64# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_cleft.png')65#66# def test_infant_congenital_anomalies_cns(self):67# self.login_navigate_to_admin()68# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Cnss').click()69# time.sleep(1)70# self.assertIn('infantcnsabnormalityitems/', self.browser.current_url)71# self.browser.get(self.browser.current_url + 'add/')72# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_cns.png')73#74# def test_infant_congenital_anomalies_facial(self):75# self.login_navigate_to_admin()76# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Facials').click()77# time.sleep(1)78# self.assertIn('infantfacialdefectitems/', self.browser.current_url)79# self.browser.get(self.browser.current_url + 'add/')80# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_facials.png')81#82# def test_infant_congenital_anomalies_femalegen(self):83# self.login_navigate_to_admin()84# self.browser.find_element_by_link_text('Infant Congenital Anomalies:FemaleGens').click()85# time.sleep(1)86# self.assertIn('infantfemalegenitalanomalyitems/', self.browser.current_url)87# self.browser.get(self.browser.current_url + 'add/')88# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_femalegen.png')89#90# def test_infant_congenital_anomalies_malegen(self):91# self.login_navigate_to_admin()92# self.browser.find_element_by_link_text('Infant Congenital Anomalies:MaleGens').click()93# time.sleep(1)94# self.assertIn('infantmalegenitalanomalyitems/', self.browser.current_url)95# self.browser.get(self.browser.current_url + 'add/')96# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_malegen.png')97#98# def test_infant_congenital_anomalies_lower_gast(self):99# self.login_navigate_to_admin()100# self.browser.find_element_by_link_text('Infant Congenital Anomalies:LowerGasts').click()101# time.sleep(1)102# self.assertIn('infantlowergastrointestinalitems/', self.browser.current_url)103# self.browser.get(self.browser.current_url + 'add/')104# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_lower_gast.png')105#106# def test_infant_congenital_anomalies_mouth(self):107# self.login_navigate_to_admin()108# self.browser.find_element_by_link_text('Infant Congenital Anomalies:MouthUpps').click()109# time.sleep(1)110# self.assertIn('infantmouthupgastrointestinalitems/', self.browser.current_url)111# self.browser.get(self.browser.current_url + 'add/')112# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_mouth.png')113#114# def test_infant_congenital_anomalies_muscle(self):115# self.login_navigate_to_admin()116# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Musculosks').click()117# time.sleep(1)118# self.assertIn('infantmusculoskeletalabnormalitems/', self.browser.current_url)119# self.browser.get(self.browser.current_url + 'add/')120# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_muscle.png')121#122# def test_infant_congenital_anomalies_renal(self):123# self.login_navigate_to_admin()124# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Renals').click()125# time.sleep(1)126# self.assertIn('infantrenalanomalyitems/', self.browser.current_url)127# self.browser.get(self.browser.current_url + 'add/')128# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_renal.png')129#130# def test_infant_congenital_anomalies_respiratory(self):131# self.login_navigate_to_admin()132# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Respitarorys').click()133# time.sleep(1)134# self.assertIn('infantrespiratorydefectitems/', self.browser.current_url)135# self.browser.get(self.browser.current_url + 'add/')136# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_respiratory.png')137#138# def test_infant_congenital_anomalies_skin(self):139# self.login_navigate_to_admin()140# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Skins').click()141# time.sleep(1)142# self.assertIn('infantskinabnormalitems/', self.browser.current_url)143# self.browser.get(self.browser.current_url + 'add/')144# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_skin.png')145#146# def test_infant_congenital_anomalies_triome(self):147# self.login_navigate_to_admin()148# self.browser.find_element_by_link_text('Infant Congenital Anomalies:Trisomess').click()149# time.sleep(1)150# self.assertIn('infanttrisomieschromosomeitems/', self.browser.current_url)151# self.browser.get(self.browser.current_url + 'add/')152# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anom_triome.png')153#154# def test_infant_congenital_anomalies(self):155# self.login_navigate_to_admin()156# self.browser.find_element_by_link_text('Infant Congenital Anomaliess').click()157# time.sleep(1)158# self.assertIn('infantcongenitalanomalies/', self.browser.current_url)159# self.browser.get(self.browser.current_url + 'add/')160# self.browser.save_screenshot('microbiome/screenshots/infant_congenital_anomalies.png')161#162# def test_infant_death(self):163# self.login_navigate_to_admin()164# self.browser.find_element_by_link_text('Infant Deaths').click()165# time.sleep(1)166# self.assertIn('infantdeath/', self.browser.current_url)167# self.browser.get(self.browser.current_url + 'add/')168# self.browser.save_screenshot('microbiome/screenshots/infant_death.png')169#170# def test_infant_eligibility(self):171# self.login_navigate_to_admin()172# self.browser.find_element_by_link_text('Infant Eligibility').click()173# time.sleep(1)174# self.assertIn('infanteligibility/', self.browser.current_url)175# self.browser.get(self.browser.current_url + 'add/')176# self.browser.save_screenshot('microbiome/screenshots/infant_eligibility.png')177#178# def test_infant_visit(self):179# self.login_navigate_to_admin()180# self.browser.find_element_by_link_text('Infant Visits').click()181# time.sleep(1)182# self.assertIn('infantvisit/', self.browser.current_url)183# self.browser.get(self.browser.current_url + 'add/')...

Full Screen

Full Screen

script(main).py

Source:script(main).py Github

copy

Full Screen

1import selenium2from selenium import webdriver3import time4import os5from selenium import webdriver6from selenium.webdriver import ActionChains7from selenium.webdriver.chrome.options import Options8from selenium.webdriver.common.keys import Keys9from selenium.webdriver.common.by import By10from selenium.webdriver.support.ui import WebDriverWait11from selenium.webdriver.support import expected_conditions as EC12from time import gmtime, strftime13from os import system14from selenium.webdriver.chrome.service import Service15from webdriver_manager.chrome import ChromeDriverManager16from selenium.webdriver.support.ui import WebDriverWait17from selenium.webdriver.support import expected_conditions as EC18from selenium.webdriver.common.by import By19from selenium import webdriver20from selenium.webdriver.common.by import By21from selenium.webdriver.support.ui import WebDriverWait22from selenium.webdriver.support import expected_conditions as cond23from selenium.common.exceptions import NoAlertPresentException24from selenium.common.exceptions import TimeoutException25from selenium.webdriver.support.ui import WebDriverWait26from selenium.webdriver.common.by import By27from selenium.webdriver.support import expected_conditions as EC28from selenium.webdriver.chrome.options import Options29from selenium.webdriver.chrome.options import Options as chrome_options30driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))31from selenium.common.exceptions import NoSuchElementException32from selenium.common.exceptions import StaleElementReferenceException33from selenium.webdriver.common.by import By34from selenium.webdriver.support.ui import WebDriverWait35from selenium.webdriver.support import expected_conditions3637count = 038driver.get("https://myanimelist.net/login.php?from=%2F")3940username = ''41password = ''4243driver.find_element("id", 'loginUserName').send_keys(username)44driver.find_element("id", 'login-password').send_keys(password)45time.sleep(2.5)46driver.find_element(By.XPATH, '//*[@id="gdpr-modal-bottom"]/div/div/div[2]/button').click()4748driver.find_element("xpath", '//*[@id="dialog"]/tbody/tr/td/form/div/p[6]/input').click()49activearea = ''50time.sleep(3)51driver.get("https://myanimelist.net/anime.php")5253for iterater1 in range(27):54 print(iterater1)55 if iterater1 == 0:56 activearea = '#'57 print(activearea)58 driver.get("https://myanimelist.net/anime.php?letter=.")59 driver.get(driver.current_url)60 elif iterater1 == 1:61 activearea = 'U'62 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)63 driver.get(driver.current_url)64 elif iterater1 == 2:65 activearea = 'Y'66 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)67 driver.get(driver.current_url)68 elif iterater1 == 3:69 activearea = 'T'70 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)71 driver.get(driver.current_url)72 elif iterater1 == 4:73 activearea = 'R'74 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)75 driver.get(driver.current_url)76 elif iterater1 == 5:77 activearea = 'E'78 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)79 driver.get(driver.current_url)80 elif iterater1 == 6:81 activearea = 'W'82 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)83 driver.get(driver.current_url)84 elif iterater1 == 7:85 activearea = 'Q'86 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)87 driver.get(driver.current_url)88 elif iterater1 == 8:89 activearea = 'A'90 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)91 driver.get(driver.current_url)92 elif iterater1 == 9:93 activearea = 'S'94 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)95 driver.get(driver.current_url)96 elif iterater1 == 10:97 activearea = 'D'98 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)99 driver.get(driver.current_url)100 elif iterater1 == 11:101 activearea = 'F'102 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)103 driver.get(driver.current_url)104 elif iterater1 == 12:105 activearea = 'G'106 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)107 driver.get(driver.current_url)108 elif iterater1 == 13:109 activearea = 'H'110 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)111 driver.get(driver.current_url)112 elif iterater1 == 14:113 activearea = 'J'114 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)115 driver.get(driver.current_url)116 elif iterater1 == 15:117 activearea = 'K'118 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)119 driver.get(driver.current_url)120 elif iterater1 == 16:121 activearea = 'L'122 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)123 driver.get(driver.current_url)124 elif iterater1 == 17:125 activearea = 'M'126 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)127 driver.get(driver.current_url)128 elif iterater1 == 18:129 activearea = 'N'130 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)131 driver.get(driver.current_url)132 elif iterater1 == 19:133 activearea = 'B'134 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)135 driver.get(driver.current_url)136 elif iterater1 == 20:137 activearea = 'V'138 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)139 driver.get(driver.current_url)140 elif iterater1 == 21:141 activearea = 'C'142 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)143 driver.get(driver.current_url)144 elif iterater1 == 22:145 activearea = 'X'146 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)147 driver.get(driver.current_url)148 elif iterater1 == 23:149 activearea = 'Z'150 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)151 driver.get(driver.current_url)152 elif iterater1 == 24:153 activearea = 'I'154 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)155 driver.get(driver.current_url)156 elif iterater1 == 25:157 activearea = 'O'158 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)159 driver.get(driver.current_url)160 elif iterater1 == 26:161 activearea = 'P'162 driver.get("https://myanimelist.net/anime.php?letter=" + activearea)163 driver.get(driver.current_url)164165 for i in range(1, 41, 1):166 driver.get("https://myanimelist.net/anime.php?letter=.&show=" + str(((i-1)*50)))167 returnurl = ("https://myanimelist.net/anime.php?letter=.&show=" + str(((i-1)*50)))168 driver.get(driver.current_url)169 buttons = driver.find_elements(By.CLASS_NAME, 'title')170 print(buttons)171 count = 0172 for btn in buttons:173 buttons = driver.find_elements(By.CLASS_NAME, 'title')174 if count == 17:175 count = 18176 if buttons[count].is_displayed():177 buttons[count].click()178179 print("clicked item number" + (str(count + 1)))180 count = count + 1181182 driver.get(driver.current_url)183 time.sleep(2)184 addbutton = driver.find_element("id", 'showAddtolistAnime')185 addbutton.click()186 time.sleep(2)187 addbutton1 = driver.find_element("name", 'myinfo_submit')188 addbutton1.click()189 time.sleep(1)190 print("added 1 anime")191 driver.get(returnurl)192 time.sleep(2)193 ...

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