How to use handle_redirect method in Playwright Python

Best Python code snippet using playwright-python

views.py

Source:views.py Github

copy

Full Screen

...9from .forms import *10from django.core.paginator import Paginator11import datetime12from datetime import timedelta13def handle_redirect(view_type, user_type):14 if view_type != user_type:15 if user_type == "student":16 return 'student_home'17 elif user_type == "teacher":18 return 'teacher_home'19def student_register(request):20 template_name = 'account/auth/student_register.html'21 form1 = RegistrationFormUser()22 form2 = RegistrationFormStudent()23 if request.method == 'POST':24 form1 = RegistrationFormUser(request.POST)25 form2 = RegistrationFormStudent(request.POST, request.FILES)26 if form1.is_valid() and form2.is_valid():27 user = form1.save()28 userprofile = Userprofile(user=user, user_type='student', profile_picture=form2.cleaned_data['profile_picture'])29 userprofile.save()30 return redirect('account:welcome_page')31 else:32 return render(request, 'account/auth/student_register.html', {'form1': form1, 'form2': form2})33 return render(request, template_name, context={'form1': form1, 'form2': form2})34@login_required35def edit_student_profile(request):36 rd = handle_redirect('student', request.user.userprofile.user_type)37 if rd:38 return redirect('account:' + rd)39 template_name = 'account/auth/edit_student_profile.html'40 if request.method == 'POST':41 form1 = UserEditForm(request.POST, instance=request.user)42 form2 = RegistrationFormStudent(request.POST, request.FILES)43 if form1.is_valid() and form2.is_valid():44 request.user.username = form1.cleaned_data['username']45 request.user.email = form1.cleaned_data['email']46 request.user.first_name = form1.cleaned_data['first_name']47 request.user.last_name = form1.cleaned_data['last_name']48 request.user.save()49 if form2.cleaned_data["profile_picture"]:50 request.user.userprofile.profile_picture = form2.cleaned_data['profile_picture']51 request.user.userprofile.save()52 return redirect('account:student_home')53 return render(request, template_name, {'form1': form1, 'form2': form2})54 form1 = UserEditForm(55 initial={56 'username': request.user.username,57 'first_name': request.user.first_name,58 'last_name': request.user.last_name,59 'email': request.user.email60 }61 )62 form2 = RegistrationFormStudent(initial={'profile_picture': request.user.userprofile.profile_picture})63 return render(request, template_name, {'form1': form1, 'form2': form2})64@login_required65def edit_teacher_profile(request):66 rd = handle_redirect('teacher', request.user.userprofile.user_type)67 if rd:68 return redirect('account:' + rd)69 template_name = 'account/auth/edit_student_profile.html'70 if request.method == 'POST':71 form1 = UserEditForm(request.POST, instance=request.user)72 form2 = RegistrationFormTeacher(request.POST, request.FILES)73 if form1.is_valid() and form2.is_valid():74 request.user.username = form1.cleaned_data['username']75 request.user.email = form1.cleaned_data['email']76 request.user.first_name = form1.cleaned_data['first_name']77 request.user.last_name = form1.cleaned_data['last_name']78 request.user.save()79 if form2.cleaned_data["profile_picture"]:80 request.user.userprofile.profile_picture = form2.cleaned_data['profile_picture']81 request.user.userprofile.save()82 return redirect('account:student_home')83 return render(request, template_name, {'form1': form1, 'form2': form2})84 form1 = UserEditForm(85 initial={86 'username': request.user.username,87 'first_name': request.user.first_name,88 'last_name': request.user.last_name,89 'email': request.user.email90 }91 )92 form2 = RegistrationFormTeacher(initial={'profile_picture': request.user.userprofile.profile_picture})93 return render(request, template_name, {'form1': form1, 'form2': form2})94def teacher_register(request):95 template_name = 'account/auth/teacher_register.html'96 form1 = RegistrationFormUser()97 form2 = RegistrationFormTeacher()98 if request.method == 'POST':99 form1 = RegistrationFormUser(request.POST)100 form2 = RegistrationFormTeacher(request.POST, request.FILES)101 if form1.is_valid() and form2.is_valid():102 user = form1.save()103 userprofile = Userprofile(user=user, user_type='teacher', profile_picture=form2.cleaned_data['profile_picture'])104 userprofile.save()105 return redirect('account:welcome_page')106 else:107 return render(request, 'account/auth/teacher_register.html', {'form1': form1, 'form2': form2})108 return render(request, template_name, context={'form1': form1, 'form2': form2})109@login_required110def student_home(request):111 rd = handle_redirect('student', request.user.userprofile.user_type)112 if rd:113 return redirect('account:' + rd)114 template_name = 'account/basic/student_home.html'115 return render(request, template_name, context={'user': request.user})116@login_required117def teacher_home(request):118 rd = handle_redirect('teacher', request.user.userprofile.user_type)119 if rd:120 return redirect('account:' + rd)121 template_name = 'account/basic_teacher/teacher_home.html'122 123 return render(request, template_name, context={'user': request.user })124@login_required125def student_subclass_home(request, subclass_id):126 rd = handle_redirect('student', request.user.userprofile.user_type)127 if rd:128 return redirect('account:' + rd)129 template_name = "account/basic/subclass_home.html"130 subclass = SubClass.objects.get(id=subclass_id, main_class=request.user.userprofile.main_class)131 last_lessons = subclass.lesson_set.all().order_by("-date_added")[0:6]132 last_grades = request.user.userprofile.grade_set.filter(sub_class=subclass).order_by("-date_added")[0:6]133 next_events = subclass.event_set.filter(date__gte=datetime.date.today()).order_by("date")[0:6]134 return render(request, template_name, context={'last_lessons': last_lessons, "last_grades": last_grades, "next_events":next_events, "sub_class": subclass})135 136@login_required137def student_lessons(request, subclass_id):138 rd = handle_redirect('student', request.user.userprofile.user_type)139 if rd:140 return redirect('account:' + rd)141 template_name = "account/basic/student_lessons.html"142 search_input = request.GET.get('search')143 main_class = request.user.userprofile.main_class144 try:145 sub_class = SubClass.objects.get(id=subclass_id)146 except:147 sub_class = None148 if subclass_id == '0':149 lesson_list = Lesson.objects.filter(sub_class__main_class=main_class).order_by('-date_added')150 else:151 if SubClass.objects.filter(id=subclass_id):152 lesson_list = Lesson.objects.filter(sub_class=SubClass.objects.get(id=subclass_id), sub_class__main_class=main_class).order_by('-date_added')153 else:154 return redirect('account:student_home')155 if search_input:156 lesson_list = lesson_list.filter(Q(title__icontains=search_input) | Q(date_added__icontains=search_input) | Q(sub_class__name__icontains=search_input))157 return render(request, template_name, context={'lessons': lesson_list, 'sub_class': sub_class})158 paginator = Paginator(lesson_list, 25)159 page = request.GET.get('page')160 lessons = paginator.get_page(page)161 return render(request, template_name, context={'lessons': lessons, 'sub_class': sub_class})162@login_required163def teacher_lessons(request, subclass_id):164 rd = handle_redirect('teacher', request.user.userprofile.user_type)165 if rd:166 return redirect('account:' + rd)167 try:168 sub_class = SubClass.objects.get(id=subclass_id)169 except:170 sub_class = None171 template_name = "account/basic_teacher/teacher_lessons.html"172 search_input = request.GET.get('search')173 teacher = request.user.userprofile174 if subclass_id == '0':175 lesson_list = Lesson.objects.filter(sub_class__teacher=teacher).order_by('-date_added')176 else:177 if SubClass.objects.filter(id=subclass_id):178 lesson_list = Lesson.objects.filter(sub_class=SubClass.objects.get(id=subclass_id), sub_class__teacher=teacher).order_by('-date_added')179 else:180 return redirect('account:teacher_home')181 if search_input:182 lesson_list = lesson_list.filter(Q(title__icontains=search_input) | Q(date_added__icontains=search_input) | Q(sub_class__main_class__name__icontains=search_input))183 return render(request, template_name, context={'lessons': lesson_list, 'subclass_id': subclass_id, 'sub_class': sub_class})184 paginator = Paginator(lesson_list, 25)185 page = request.GET.get('page')186 lessons = paginator.get_page(page)187 return render(request, template_name, context={'lessons': lessons, 'subclass_id': subclass_id, 'sub_class': sub_class})188@login_required189def add_lesson(request, subclass_id):190 rd = handle_redirect('teacher', request.user.userprofile.user_type)191 if rd:192 return redirect('account:' + rd)193 template_name = 'account/basic_teacher/add_lesson.html'194 195 if not(SubClass.objects.filter(id=subclass_id, teacher=request.user.userprofile)) and subclass_id != '0':196 return redirect('account:teacher_lessons', '0')197 sub_classes = SubClass.objects.filter(teacher=request.user.userprofile)198 form = AddLessonForm(sub_classes=sub_classes)199 sub_class = 0200 if subclass_id != '0':201 sub_class = SubClass.objects.get(id=subclass_id)202 if request.method == 'POST':203 if subclass_id != '0':204 request.POST = request.POST.copy()205 request.POST['sub_class'] = str(sub_class.id)206 form = AddLessonForm(request.POST, request.FILES, sub_classes=sub_classes)207 if form.is_valid():208 lesson = Lesson(title=form.cleaned_data['title'], text=form.cleaned_data['text'], pdf=form.cleaned_data['pdf'], sub_class=form.cleaned_data['sub_class'])209 lesson.save()210 return redirect('account:teacher_lessons', subclass_id)211 else:212 return render(request, template_name, context={'form':form, 'sub_class': sub_class})213 214 return render(request, template_name, context={'form':form, 'sub_class': sub_class})215@login_required216def remove_confirm_lesson(request, subclass_id, lesson_id):217 template_name = 'account/basic_teacher/remove_confirm_lesson.html'218 try:219 lesson = Lesson.objects.get(id=lesson_id)220 except:221 return redirect('account:teacher_lessons', 0)222 223 return render(request, template_name, {'lesson': lesson})224@login_required225def remove_lesson(request, subclass_id, lesson_id):226 try:227 lesson = Lesson.objects.get(id=lesson_id)228 except:229 return redirect('acccount:teacher_home')230 if lesson.sub_class.teacher == request.user.userprofile:231 lesson.delete()232 233 return redirect('account:teacher_lessons', 0)234 235@login_required236def student_lesson(request, subclass_id, lesson_id):237 rd = handle_redirect('student', request.user.userprofile.user_type)238 if rd:239 return redirect('account:' + rd)240 template_name = "account/basic/student_lesson.html"241 if Lesson.objects.filter(id=lesson_id):242 if request.user.userprofile.main_class != Lesson.objects.get(id=lesson_id).sub_class.main_class:243 return redirect('account:student_lessons', "0")244 else:245 return redirect('account:student_lessons', "0")246 lesson = Lesson.objects.get(id=lesson_id)247 return render(request, template_name, {'lesson': lesson})248@login_required249def teacher_lesson(request, subclass_id, lesson_id):250 rd = handle_redirect('teacher', request.user.userprofile.user_type)251 if rd:252 return redirect('account:' + rd)253 try:254 lesson = Lesson.objects.get(id=lesson_id, sub_class__teacher=request.user.userprofile)255 except:256 return redirect('account:teacher_lessons', "0")257 template_name = "account/basic_teacher/teacher_lesson.html"258 259 return render(request, template_name, {'lesson': lesson})260@login_required261def student_grades(request, subclass_id):262 rd = handle_redirect('student', request.user.userprofile.user_type)263 if rd:264 return redirect('account:' + rd)265 template_name = "account/basic/student_grades.html"266 search_input = request.GET.get('search_grades')267 main_class = request.user.userprofile.main_class268 if subclass_id == '0':269 grades_list = Grade.objects.filter(sub_class__main_class=main_class, student=request.user.userprofile).order_by('-date_added')270 subclass = None271 else:272 if SubClass.objects.filter(id=subclass_id, main_class=request.user.userprofile.main_class):273 grades_list = Grade.objects.filter(sub_class=SubClass.objects.get(id=subclass_id), student=request.user.userprofile).order_by('-date_added')274 subclass = SubClass.objects.get(id=subclass_id)275 else:276 return redirect('account:student_home')277 if search_input:278 grades_list = grades_list.filter(Q(value__icontains=search_input) | Q(date_added__icontains=search_input) | Q(sub_class__name__icontains=search_input))279 return render(request, template_name, context={'grades': grades_list, 'subclass_id': subclass_id})280 paginator = Paginator(grades_list, 48)281 page = request.GET.get('page')282 grades = paginator.get_page(page)283 return render(request, template_name, context={'grades': grades, 'subclass': subclass, 'subclass_id': subclass_id})284@login_required285def student_calendar(request, subclass_id, week):286 rd = handle_redirect('student', request.user.userprofile.user_type)287 if rd:288 return redirect('account:' + rd)289 290 week = int(week)291 template_name = "account/basic/student_calendar.html"292 today = datetime.date.today()293 main_class = request.user.userprofile.main_class294 sub_class = SubClass.objects.filter(id=subclass_id)295 if week and (today.weekday() in [5,6]):296 delta = timedelta(days=7-today.weekday() + 7*(week))297 date_start = today + delta298 elif week:299 delta = timedelta(days=7-today.weekday() + 7*(week-1))300 date_start = today + delta301 elif today.weekday() >= 5:302 date_start = today + timedelta(7-today.weekday())303 else:304 date_start = today305 306 dates = {}307 dates2 = []308 if sub_class:309 for i in range(date_start.weekday(), 5):310 date = date_start + timedelta(days=(i-today.weekday()))311 events = Event.objects.filter(date=date, sub_class=sub_class[0])312 dates.update({ date:events })313 return render(request, template_name, context={'dates': dates, 'sub_class': sub_class[0]})314 315 else:316 for i in range(date_start.weekday(), 5):317 date = date_start + timedelta(days=(i-date_start.weekday()))318 events = Event.objects.filter(date=date, sub_class__main_class=main_class)319 dates.update({ date:events })320 return render(request, template_name, context={'dates': dates, 'dates2': dates2})321 322@login_required323def mainclass_home(request):324 rd = handle_redirect('teacher', request.user.userprofile.user_type)325 if rd:326 return redirect('account:' + rd)327 if not request.user.userprofile.main_class:328 return redirect('account:teacher_home')329 template_name = 'account/basic_teacher/mainclass_home.html'330 return render(request, template_name)331@login_required332def add_mainclass(request):333 rd = handle_redirect('teacher', request.user.userprofile.user_type)334 if rd:335 return redirect('account:' + rd)336 if request.user.userprofile.main_class:337 return redirect('account:teacher_home')338 template_name = 'account/basic_teacher/add_mainclass.html'339 if request.method == 'POST':340 form = AddMainClassForm(request.POST)341 if form.is_valid():342 main_class = MainClass(name=form.cleaned_data['name'], semester=form.cleaned_data['semester'])343 main_class.save()344 request.user.userprofile.main_class = main_class345 request.user.userprofile.save()346 return redirect('account:mainclass_home')347 form = AddMainClassForm(initial={'semester': 1})348 return render(request, template_name, {'form': form})349@login_required350def edit_mainclass(request):351 rd = handle_redirect('teacher', request.user.userprofile.user_type)352 if rd:353 return redirect('account:' + rd)354 template_name = 'account/basic_teacher/add_mainclass.html'355 if request.method == 'POST':356 form = AddMainClassForm(request.POST)357 if form.is_valid():358 main_class = request.user.userprofile.main_class359 main_class.name = form.cleaned_data['name']360 main_class.semester = form.cleaned_data['semester']361 main_class.save()362 return redirect('account:mainclass_home')363 form = AddMainClassForm(364 initial={365 'semester': request.user.userprofile.main_class.semester,366 'name': request.user.userprofile.main_class.name367 })368 return render(request, template_name, {'form': form})369@login_required370def add_subclass_request(request):371 rd = handle_redirect('teacher', request.user.userprofile.user_type)372 if rd:373 return redirect('account:' + rd) 374 if not request.user.userprofile.main_class:375 return redirect('account:teacher_home')376 template_name = 'account/basic_teacher/add_subclass.html'377 378 if request.method == 'POST':379 form = AddSubClassForm(request.POST)380 381 if form.is_valid():382 try:383 Userprofile.objects.get(id=form.cleaned_data['teacher'], user_type='teacher')384 except:385 return render(request, template_name, {'form': AddSubClassForm(), 'invalid_id': True})386 request = Request(sent_by=request.user.userprofile, recieved_by=Userprofile.objects.get(id=form.cleaned_data['teacher']), subclass_name=form.cleaned_data['name'], subclass_color_code=form.cleaned_data['color_code'])387 request.save()388 return redirect('account:mainclass_home')389 390 return render(request, template_name, {'form': AddSubClassForm()})391@login_required392def edit_subclass(request, subclass_id):393 rd = handle_redirect('teacher', request.user.userprofile.user_type)394 if rd:395 return redirect('account:' + rd) 396 if not request.user.userprofile.main_class.subclass_set.filter(id=subclass_id, main_class=request.user.userprofile.main_class):397 return redirect('account:teacher_home')398 template_name = 'account/basic_teacher/add_subclass.html'399 400 sub_class = SubClass.objects.get(id=subclass_id)401 if request.method == 'POST':402 form = AddSubClassForm(request.POST)403 404 if form.is_valid():405 try:406 teacher = Userprofile.objects.get(id=form.cleaned_data['teacher'], user_type='teacher')407 except:408 return render(request, template_name, {'form': AddSubClassForm( initial={'name': sub_class.name, 'color_code': sub_class.color_code }), 'invalid_id': True})409 if teacher != sub_class.teacher:410 try:411 current_request = Request.objects.get(subclass=sub_class)412 current_request.delete()413 except:414 pass415 sub_class.teacher = None416 request = Request(sent_by=request.user.userprofile, recieved_by=teacher, subclass=sub_class)417 request.save()418 419 sub_class.name = form.cleaned_data['name']420 sub_class.color_code = form.cleaned_data['color_code']421 sub_class.save()422 return redirect('account:mainclass_home')423 if sub_class.teacher:424 return render(request, template_name, {'form': AddSubClassForm( initial={'name': sub_class.name, 'color_code': sub_class.color_code, 'teacher': sub_class.teacher.id })})425 try:426 teacher_id = Request.objects.get(subclass=sub_class).recieved_by.id427 except:428 teacher_id = None429 return render(request, template_name, {'form': AddSubClassForm( initial={'name': sub_class.name, 'color_code': sub_class.color_code, 'teacher': teacher_id })})430@login_required431def mainclass_students(request):432 rd = handle_redirect('teacher', request.user.userprofile.user_type)433 if rd:434 return redirect('account:' + rd) 435 if not request.user.userprofile.main_class:436 return redirect('account:teacher_home')437 template_name = 'account/basic_teacher/mainclass_students.html'438 students = request.user.userprofile.main_class.userprofile_set.filter(user_type="student")439 return render(request, template_name, {'students': students})440@login_required441def kick_student(request, student_id):442 rd = handle_redirect('teacher', request.user.userprofile.user_type)443 if rd:444 return redirect('account:' + rd) 445 if not request.user.userprofile.main_class:446 return redirect('account:teacher_home')447 448 try:449 student = Userprofile.objects.get(id=student_id)450 student.main_class = None451 student.save()452 return redirect('account:mainclass_students')453 except:454 return redirect('account:mainclass_students')455@login_required456def teacher_notifications(request):457 rd = handle_redirect('teacher', request.user.userprofile.user_type)458 if rd:459 return redirect('account:' + rd) 460 template_name = 'account/basic_teacher/notifications.html'461 return render(request, template_name)462@login_required463def teacher_handle_request(request, request_id, handle):464 rd = handle_redirect('teacher', request.user.userprofile.user_type)465 if rd:466 return redirect('account:' + rd) 467 request_object = Request.objects.get(id=request_id)468 if request.user.userprofile == request_object.recieved_by and handle == '1':469 sub_class = SubClass(470 name=request_object.subclass_name,471 main_class=request_object.sent_by.main_class,472 color_code=request_object.subclass_color_code,473 teacher=request.user.userprofile,474 ) 475 sub_class.save()476 request_object.delete()477 return redirect('account:teacher_lessons', sub_class.id)478 elif request.user.userprofile == request_object.recieved_by and handle == '0':479 request_object.delete()480 481 elif request.user.userprofile == request_object.recieved_by and handle == '2':482 request_object.sent_by.main_class = request.user.userprofile.main_class483 request_object.sent_by.save()484 request_object.delete()485 return redirect('account:teacher_notifications')486 487 elif request.user.userprofile == request_object.recieved_by and handle == '3':488 request_object.subclass.teacher = request.user.userprofile489 request_object.subclass.save()490 request_object.delete()491 return redirect('account:teacher_notifications')492 return redirect('account:teacher_notifications')493@login_required494def student_join_request(request):495 rd = handle_redirect('student', request.user.userprofile.user_type)496 if rd:497 return redirect('account:' + rd) 498 if request.user.userprofile.main_class:499 return redirect('account:student_home')500 template_name = 'account/basic/join_class.html'501 if request.method == 'POST':502 try:503 main_class = MainClass.objects.get(id=request.POST['mainclass_id'])504 except:505 return render(request, template_name,{'id_valid': False})506 for past_request in Request.objects.filter(sent_by=request.user.userprofile):507 past_request.delete()508 request_object = Request(sent_by=request.user.userprofile, recieved_by=main_class.userprofile_set.get(user_type='teacher'))509 request_object.save()510 return redirect('account:student_home')511 512 return render(request, template_name,{'id_valid': True})513@login_required514def student_archives(request, subclass_id, my_filter):515 rd = handle_redirect('student', request.user.userprofile.user_type)516 if rd:517 return redirect('account:' + rd) 518 template_name = "account/basic/student_archives.html"519 search_input = request.GET.get('search')520 main_class = request.user.userprofile.main_class521 try:522 sub_class = SubClass.objects.get(id=subclass_id)523 if request.user.userprofile.main_class != sub_class.main_class:524 return redirect('account:student_home')525 except:526 sub_class = None527 if subclass_id != '0':528 return redirect('account:student_home')529 if my_filter == '0':...

Full Screen

Full Screen

lexer.py

Source:lexer.py Github

copy

Full Screen

...212def handle_double_amps(state, token):213 yield _new_token("AND", "and", token.start)214def handle_double_pipe(state, token):215 yield _new_token("OR", "or", token.start)216def handle_redirect(state, token):217 # The parser expects whitespace after a redirection in subproc mode.218 # If whitespace does not exist, we'll issue an empty whitespace219 # token before proceeding.220 state["last"] = token221 typ = token.type222 st = token.string223 key = (typ, st) if (typ, st) in token_map else typ224 yield _new_token(token_map[key], st, token.start)225 if state["pymode"][-1][0]:226 return227 # add a whitespace token after a redirection, if we need to228 next_tok = next(state["stream"])229 if next_tok.start == token.end:230 yield _new_token("WS", "", token.end)...

Full Screen

Full Screen

browser_collectivites.py

Source:browser_collectivites.py Github

copy

Full Screen

...43 # here we are already logged, we have been logged in EdfproBrowser, but we have detected a new BASEURL44 # and new pages45 # manually handle response because we were unable to handle it the first time due to another BASEURL46 page = self.client_space.handle(self.response)47 url = page.handle_redirect()48 self.location(url)49 if self.authentication_error.is_here():50 raise BrowserIncorrectPassword(self.page.get_error_message())51 if self.client_space.is_here() and self.page.handle_redirect():52 url = self.page.handle_redirect()53 self.location(url)54 if self.maintenance.is_here():55 raise BrowserUnavailable(self.page.get_message())56 frontdoor_url = self.page.get_frontdoor_url()57 self.location(frontdoor_url)58 self.client_space.go()59 redirect_page = self.page.handle_redirect()60 # sometimes the account is already signed in so we have to disconnect them with redirect url61 if redirect_page:62 limit = 063 while self.page.handle_redirect() and limit < 5:64 limit += 165 redirect_page = self.page.handle_redirect()66 self.location(redirect_page)67 if self.premium_client_space.is_here():68 self.is_premium = True69 else:70 self.client_space.go()71 self.token = self.page.get_token()72 aura_config = self.page.get_aura_config()73 self.context = aura_config['context']74 def go_aura(self, message, page_uri=''):75 uri = '/espaceclient/s/%s' % page_uri76 page = self.aura77 if self.is_premium:78 uri = '/espaceclientpremium/s/%s' % page_uri79 page = self.premium_aura...

Full Screen

Full Screen

redirect.py

Source:redirect.py Github

copy

Full Screen

...76 parsed_page_src = plugin.__parser(*parser_args)77 if not plugin._is_valid_page(parsed_page_src):78 return fallback()79 80 result = plugin.handle_redirect(browser, url, parsed_page_src,81 *args, **kwargs)82 if result is None:83 return fallback()84 85 return result86 87 @abc.abstractmethod88 def handle_redirect(plugin, browser, url, source, *args,89 **kwargs):90 """Should return the value given by ``browser.load_page`` with the91 additional arguments, ``*args`` and ``**kwargs`` (modified if desired).92 If it returns ``None`` or raises a :class:`PageRedirectionError`, the93 redirect is canceled. Here's an example handle_redirect method::94 95 def handle_redirect(plugin, browser, url, parsed, *args, **kwargs):96 "For this example, we'll say the plugin's parser is lxml"97 return browser.load_page(parsed.xpath("//a")[0].attrib["href"],98 *args, **kwargs)99 100 ..101 """102 pass103class PageRedirectionError(Exception):104 def __init__(self):105 Exception.__init__(self)106class BrowserMetaRefreshHander(BaseRedirectionPlugin):107 """Handles pages using the deprecated html `meta refresh`_ feature.108 109 .. _meta refresh: http://www.w3.org/TR/WCAG10-HTML-TECHS/#meta-element"""110 def __init__(self, max_seconds=None):111 BaseRedirectionPlugin.__init__(self, parser=parsers.passthrough_str)112 self._max_seconds = max_seconds113 114 # compile all the regex patterns we use in handle_redirect115 self._meta_re = re.compile(116 r"""\<meta( [^>]*)? http-equiv=["']refresh["']( [^>]*)?\>""",117 re.IGNORECASE | re.DOTALL118 )119 self._content_re = re.compile(r"""(?<=content=["']).+?(?=["'])""",120 re.IGNORECASE | re.DOTALL)121 self._timeout_re = re.compile(r"""\A\d+""")122 self._url_re = re.compile(r"""(?<=url=).+""")123 124 125 def handle_redirect(plugin, browser, base_url, source, *args, **kwargs):126 # look for a <meta> tag with the refresh property127 meta_tag = plugin._meta_re.search(source)128 if not meta_tag: return None # not a match129 meta_tag = meta_tag.group()130 131 # pull the content property from the tag if it's there132 content = plugin._content_re.search(meta_tag)133 content = content.group() if content else ""134 135 # parse the data in the content property136 137 # solve for the load delay (specified in seconds)138 timeout = plugin._timeout_re.search(content)139 if timeout:...

Full Screen

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