How to use expect_ssl_error method in Playwright Python

Best Python code snippet using playwright-python

test_navigation.py

Source:test_navigation.py Github

copy

Full Screen

...144 page, https_server, browser_name145):146 with pytest.raises(Error) as exc_info:147 await page.goto(https_server.EMPTY_PAGE)148 expect_ssl_error(exc_info.value.message, browser_name)149async def test_goto_should_fail_when_navigating_to_bad_ssl_after_redirects(150 page, server, https_server, browser_name151):152 server.set_redirect("/redirect/1.html", "/redirect/2.html")153 server.set_redirect("/redirect/2.html", "/empty.html")154 with pytest.raises(Error) as exc_info:155 await page.goto(https_server.PREFIX + "/redirect/1.html")156 expect_ssl_error(exc_info.value.message, browser_name)157async def test_goto_should_not_crash_when_navigating_to_bad_ssl_after_a_cross_origin_navigation(158 page, server, https_server, browser_name159):160 await page.goto(server.CROSS_PROCESS_PREFIX + "/empty.html")161 with pytest.raises(Error):162 await page.goto(https_server.EMPTY_PAGE)163async def test_goto_should_throw_if_networkidle2_is_passed_as_an_option(page, server):164 with pytest.raises(Error) as exc_info:165 await page.goto(server.EMPTY_PAGE, wait_until="networkidle2")166 assert (167 "wait_until: expected one of (load|domcontentloaded|networkidle)"168 in exc_info.value.message169 )170async def test_goto_should_fail_when_main_resources_failed_to_load(171 page, server, is_chromium, is_webkit, is_win172):173 with pytest.raises(Error) as exc_info:174 await page.goto("http://localhost:44123/non-existing-url")175 if is_chromium:176 assert "net::ERR_CONNECTION_REFUSED" in exc_info.value.message177 elif is_webkit and is_win:178 assert "Couldn't connect to server" in exc_info.value.message179 elif is_webkit:180 assert "Could not connect" in exc_info.value.message181 else:182 assert "NS_ERROR_CONNECTION_REFUSED" in exc_info.value.message183async def test_goto_should_fail_when_exceeding_maximum_navigation_timeout(page, server):184 # Hang for request to the empty.html185 server.set_route("/empty.html", lambda request: None)186 with pytest.raises(Error) as exc_info:187 await page.goto(server.PREFIX + "/empty.html", timeout=1)188 assert "Timeout 1ms exceeded" in exc_info.value.message189 assert server.PREFIX + "/empty.html" in exc_info.value.message190 assert isinstance(exc_info.value, TimeoutError)191async def test_goto_should_fail_when_exceeding_default_maximum_navigation_timeout(192 page, server193):194 # Hang for request to the empty.html195 server.set_route("/empty.html", lambda request: None)196 page.context.set_default_navigation_timeout(2)197 page.set_default_navigation_timeout(1)198 with pytest.raises(Error) as exc_info:199 await page.goto(server.PREFIX + "/empty.html")200 assert "Timeout 1ms exceeded" in exc_info.value.message201 assert server.PREFIX + "/empty.html" in exc_info.value.message202 assert isinstance(exc_info.value, TimeoutError)203async def test_goto_should_fail_when_exceeding_browser_context_navigation_timeout(204 page, server205):206 # Hang for request to the empty.html207 server.set_route("/empty.html", lambda request: None)208 page.context.set_default_navigation_timeout(2)209 with pytest.raises(Error) as exc_info:210 await page.goto(server.PREFIX + "/empty.html")211 assert "Timeout 2ms exceeded" in exc_info.value.message212 assert server.PREFIX + "/empty.html" in exc_info.value.message213 assert isinstance(exc_info.value, TimeoutError)214async def test_goto_should_fail_when_exceeding_default_maximum_timeout(page, server):215 # Hang for request to the empty.html216 server.set_route("/empty.html", lambda request: None)217 page.context.set_default_timeout(2)218 page.set_default_timeout(1)219 with pytest.raises(Error) as exc_info:220 await page.goto(server.PREFIX + "/empty.html")221 assert "Timeout 1ms exceeded" in exc_info.value.message222 assert server.PREFIX + "/empty.html" in exc_info.value.message223 assert isinstance(exc_info.value, TimeoutError)224async def test_goto_should_fail_when_exceeding_browser_context_timeout(page, server):225 # Hang for request to the empty.html226 server.set_route("/empty.html", lambda request: None)227 page.context.set_default_timeout(2)228 with pytest.raises(Error) as exc_info:229 await page.goto(server.PREFIX + "/empty.html")230 assert "Timeout 2ms exceeded" in exc_info.value.message231 assert server.PREFIX + "/empty.html" in exc_info.value.message232 assert isinstance(exc_info.value, TimeoutError)233async def test_goto_should_prioritize_default_navigation_timeout_over_default_timeout(234 page, server235):236 # Hang for request to the empty.html237 server.set_route("/empty.html", lambda request: None)238 page.set_default_timeout(0)239 page.set_default_navigation_timeout(1)240 with pytest.raises(Error) as exc_info:241 await page.goto(server.PREFIX + "/empty.html")242 assert "Timeout 1ms exceeded" in exc_info.value.message243 assert server.PREFIX + "/empty.html" in exc_info.value.message244 assert isinstance(exc_info.value, TimeoutError)245async def test_goto_should_disable_timeout_when_its_set_to_0(page, server):246 loaded = []247 page.once("load", lambda: loaded.append(True))248 await page.goto(server.PREFIX + "/grid.html", timeout=0, wait_until="load")249 assert loaded == [True]250async def test_goto_should_work_when_navigating_to_valid_url(page, server):251 response = await page.goto(server.EMPTY_PAGE)252 assert response.ok253async def test_goto_should_work_when_navigating_to_data_url(page, server):254 response = await page.goto("data:text/html,hello")255 assert response is None256async def test_goto_should_work_when_navigating_to_404(page, server):257 response = await page.goto(server.PREFIX + "/not-found")258 assert response.ok is False259 assert response.status == 404260async def test_goto_should_return_last_response_in_redirect_chain(page, server):261 server.set_redirect("/redirect/1.html", "/redirect/2.html")262 server.set_redirect("/redirect/2.html", "/redirect/3.html")263 server.set_redirect("/redirect/3.html", server.EMPTY_PAGE)264 response = await page.goto(server.PREFIX + "/redirect/1.html")265 assert response.ok266 assert response.url == server.EMPTY_PAGE267async def test_goto_should_navigate_to_data_url_and_not_fire_dataURL_requests(268 page, server269):270 requests = []271 page.on("request", lambda request: requests.append(request))272 dataURL = "data:text/html,<div>yo</div>"273 response = await page.goto(dataURL)274 assert response is None275 assert requests == []276async def test_goto_should_navigate_to_url_with_hash_and_fire_requests_without_hash(277 page, server278):279 requests = []280 page.on("request", lambda request: requests.append(request))281 response = await page.goto(server.EMPTY_PAGE + "#hash")282 assert response.status == 200283 assert response.url == server.EMPTY_PAGE284 assert len(requests) == 1285 assert requests[0].url == server.EMPTY_PAGE286async def test_goto_should_work_with_self_requesting_page(page, server):287 response = await page.goto(server.PREFIX + "/self-request.html")288 assert response.status == 200289 assert "self-request.html" in response.url290async def test_goto_should_fail_when_navigating_and_show_the_url_at_the_error_message(291 page, server, https_server292):293 url = https_server.PREFIX + "/redirect/1.html"294 with pytest.raises(Error) as exc_info:295 await page.goto(url)296 assert url in exc_info.value.message297async def test_goto_should_be_able_to_navigate_to_a_page_controlled_by_service_worker(298 page, server299):300 await page.goto(server.PREFIX + "/serviceworkers/fetch/sw.html")301 await page.evaluate("window.activationPromise")302 await page.goto(server.PREFIX + "/serviceworkers/fetch/sw.html")303async def test_goto_should_send_referer(page, server):304 [request1, request2, _] = await asyncio.gather(305 server.wait_for_request("/grid.html"),306 server.wait_for_request("/digits/1.png"),307 page.goto(server.PREFIX + "/grid.html", referer="http://google.com/"),308 )309 assert request1.getHeader("referer") == "http://google.com/"310 # Make sure subresources do not inherit referer.311 assert request2.getHeader("referer") == server.PREFIX + "/grid.html"312 assert page.url == server.PREFIX + "/grid.html"313async def test_goto_should_reject_referer_option_when_set_extra_http_headers_provides_referer(314 page, server315):316 await page.set_extra_http_headers({"referer": "http://microsoft.com/"})317 with pytest.raises(Error) as exc_info:318 await page.goto(server.PREFIX + "/grid.html", referer="http://google.com/")319 assert (320 '"referer" is already specified as extra HTTP header' in exc_info.value.message321 )322 assert server.PREFIX + "/grid.html" in exc_info.value.message323async def test_network_idle_should_navigate_to_empty_page_with_networkidle(324 page, server325):326 response = await page.goto(server.EMPTY_PAGE, wait_until="networkidle")327 assert response.status == 200328async def test_wait_for_nav_should_work(page, server):329 await page.goto(server.EMPTY_PAGE)330 async with page.expect_navigation() as response_info:331 await page.evaluate(332 "url => window.location.href = url", server.PREFIX + "/grid.html"333 )334 response = await response_info.value335 assert response.ok336 assert "grid.html" in response.url337async def test_wait_for_nav_should_respect_timeout(page, server):338 with pytest.raises(Error) as exc_info:339 async with page.expect_navigation(url="**/frame.html", timeout=5000):340 await page.goto(server.EMPTY_PAGE)341 assert "Timeout 5000ms exceeded" in exc_info.value.message342async def test_wait_for_nav_should_work_with_both_domcontentloaded_and_load(343 page, server344):345 async with page.expect_navigation(346 wait_until="domcontentloaded"347 ), page.expect_navigation(wait_until="load"):348 await page.goto(server.PREFIX + "/one-style.html")349async def test_wait_for_nav_should_work_with_clicking_on_anchor_links(page, server):350 await page.goto(server.EMPTY_PAGE)351 await page.set_content('<a href="#foobar">foobar</a>')352 async with page.expect_navigation() as response_info:353 await page.click("a"),354 response = await response_info.value355 assert response is None356 assert page.url == server.EMPTY_PAGE + "#foobar"357async def test_wait_for_nav_should_work_with_clicking_on_links_which_do_not_commit_navigation(358 page, server, https_server, browser_name359):360 await page.goto(server.EMPTY_PAGE)361 await page.set_content(f"<a href='{https_server.EMPTY_PAGE}'>foobar</a>")362 with pytest.raises(Error) as exc_info:363 async with page.expect_navigation():364 await page.click("a"),365 expect_ssl_error(exc_info.value.message, browser_name)366async def test_wait_for_nav_should_work_with_history_push_state(page, server):367 await page.goto(server.EMPTY_PAGE)368 await page.set_content(369 """370 <a onclick='javascript:pushState()'>SPA</a>371 <script>372 function pushState() { history.pushState({}, '', 'wow.html') }373 </script>374 """375 )376 async with page.expect_navigation() as response_info:377 await page.click("a"),378 response = await response_info.value379 assert response is None380 assert page.url == server.PREFIX + "/wow.html"381async def test_wait_for_nav_should_work_with_history_replace_state(page, server):382 await page.goto(server.EMPTY_PAGE)383 await page.set_content(384 """385 <a onclick='javascript:replaceState()'>SPA</a>386 <script>387 function replaceState() { history.replaceState({}, '', '/replaced.html') }388 </script>389 """390 )391 async with page.expect_navigation() as response_info:392 await page.click("a"),393 response = await response_info.value394 assert response is None395 assert page.url == server.PREFIX + "/replaced.html"396async def test_wait_for_nav_should_work_with_dom_history_back_forward(page, server):397 await page.goto(server.EMPTY_PAGE)398 await page.set_content(399 """400 <a id=back onclick='javascript:go_back()'>back</a>401 <a id=forward onclick='javascript:go_forward()'>forward</a>402 <script>403 function go_back() { history.back(); }404 function go_forward() { history.forward(); }405 history.pushState({}, '', '/first.html')406 history.pushState({}, '', '/second.html')407 </script>408 """409 )410 assert page.url == server.PREFIX + "/second.html"411 async with page.expect_navigation() as back_response_info:412 await page.click("a#back"),413 back_response = await back_response_info.value414 assert back_response is None415 assert page.url == server.PREFIX + "/first.html"416 async with page.expect_navigation() as forward_response_info:417 await page.click("a#forward"),418 forward_response = await forward_response_info.value419 assert forward_response is None420 assert page.url == server.PREFIX + "/second.html"421@pytest.mark.skip_browser("firefox")422async def test_wait_for_nav_should_work_when_subframe_issues_window_stop(page, server):423 server.set_route("/frames/style.css", lambda _: None)424 navigation_promise = asyncio.create_task(425 page.goto(server.PREFIX + "/frames/one-frame.html")426 )427 await asyncio.sleep(0)428 async with page.expect_event("frameattached") as frame_info:429 pass430 frame = await frame_info.value431 async with page.expect_event("framenavigated", lambda f: f == frame):432 pass433 await asyncio.gather(frame.evaluate("() => window.stop()"), navigation_promise)434async def test_wait_for_nav_should_work_with_url_match(page, server):435 responses = [None, None, None]436 async def wait_for_nav(url: Any, index: int) -> None:437 async with page.expect_navigation(url=url) as response_info:438 pass439 responses[index] = await response_info.value440 response0_promise = asyncio.create_task(441 wait_for_nav(re.compile(r"one-style\.html"), 0)442 )443 response1_promise = asyncio.create_task(444 wait_for_nav(re.compile(r"\/frame.html"), 1)445 )446 response2_promise = asyncio.create_task(447 wait_for_nav(lambda url: "foo=bar" in url, 2)448 )449 assert responses == [None, None, None]450 await page.goto(server.EMPTY_PAGE)451 assert responses == [None, None, None]452 await page.goto(server.PREFIX + "/frame.html")453 assert responses[0] is None454 await response1_promise455 assert responses[1] is not None456 assert responses[2] is None457 await page.goto(server.PREFIX + "/one-style.html")458 await response0_promise459 assert responses[0] is not None460 assert responses[1] is not None461 assert responses[2] is None462 await page.goto(server.PREFIX + "/frame.html?foo=bar")463 await response2_promise464 assert responses[0] is not None465 assert responses[1] is not None466 assert responses[2] is not None467 await page.goto(server.PREFIX + "/empty.html")468 assert responses[0].url == server.PREFIX + "/one-style.html"469 assert responses[1].url == server.PREFIX + "/frame.html"470 assert responses[2].url == server.PREFIX + "/frame.html?foo=bar"471async def test_wait_for_nav_should_work_with_url_match_for_same_document_navigations(472 page, server473):474 await page.goto(server.EMPTY_PAGE)475 async with page.expect_navigation(url=re.compile(r"third\.html")) as response_info:476 assert not response_info.is_done()477 await page.evaluate("history.pushState({}, '', '/first.html')")478 assert not response_info.is_done()479 await page.evaluate("history.pushState({}, '', '/second.html')")480 assert not response_info.is_done()481 await page.evaluate("history.pushState({}, '', '/third.html')")482 assert response_info.is_done()483async def test_wait_for_nav_should_work_for_cross_process_navigations(page, server):484 await page.goto(server.EMPTY_PAGE)485 url = server.CROSS_PROCESS_PREFIX + "/empty.html"486 async with page.expect_navigation(wait_until="domcontentloaded") as response_info:487 await page.goto(url)488 response = await response_info.value489 assert response.url == url490 assert page.url == url491 assert await page.evaluate("document.location.href") == url492async def test_expect_navigation_should_work_for_cross_process_navigations(493 page, server494):495 await page.goto(server.EMPTY_PAGE)496 url = server.CROSS_PROCESS_PREFIX + "/empty.html"497 async with page.expect_navigation(wait_until="domcontentloaded") as response_info:498 goto_task = asyncio.create_task(page.goto(url))499 response = await response_info.value500 assert response.url == url501 assert page.url == url502 assert await page.evaluate("document.location.href") == url503 await goto_task504async def test_wait_for_load_state_should_respect_timeout(page, server):505 requests = []506 def handler(request: Any):507 requests.append(request)508 server.set_route("/one-style.css", handler)509 await page.goto(server.PREFIX + "/one-style.html", wait_until="domcontentloaded")510 with pytest.raises(Error) as exc_info:511 await page.wait_for_load_state("load", timeout=1)512 assert "Timeout 1ms exceeded." in exc_info.value.message513async def test_wait_for_load_state_should_resolve_immediately_if_loaded(page, server):514 await page.goto(server.PREFIX + "/one-style.html")515 await page.wait_for_load_state()516async def test_wait_for_load_state_should_throw_for_bad_state(page, server):517 await page.goto(server.PREFIX + "/one-style.html")518 with pytest.raises(Error) as exc_info:519 await page.wait_for_load_state("bad")520 assert (521 "state: expected one of (load|domcontentloaded|networkidle)"522 in exc_info.value.message523 )524async def test_wait_for_load_state_should_resolve_immediately_if_load_state_matches(525 page, server526):527 await page.goto(server.EMPTY_PAGE)528 requests = []529 def handler(request: Any):530 requests.append(request)531 server.set_route("/one-style.css", handler)532 await page.goto(server.PREFIX + "/one-style.html", wait_until="domcontentloaded")533 await page.wait_for_load_state("domcontentloaded")534async def test_wait_for_load_state_should_work_with_pages_that_have_loaded_before_being_connected_to(535 page, context, server536):537 await page.goto(server.EMPTY_PAGE)538 async with page.expect_popup() as popup_info:539 await page.evaluate("window._popup = window.open(document.location.href)")540 # The url is about:blank in FF.541 popup = await popup_info.value542 assert popup.url == server.EMPTY_PAGE543 await popup.wait_for_load_state()544 assert popup.url == server.EMPTY_PAGE545async def test_wait_for_load_state_should_wait_for_load_state_of_empty_url_popup(546 browser, page, is_firefox547):548 ready_state = []549 async with page.expect_popup() as popup_info:550 ready_state.append(551 await page.evaluate(552 """() => {553 popup = window.open('')554 return popup.document.readyState555 }"""556 )557 )558 popup = await popup_info.value559 await popup.wait_for_load_state()560 assert ready_state == ["uninitialized"] if is_firefox else ["complete"]561 assert await popup.evaluate("() => document.readyState") == ready_state[0]562async def test_wait_for_load_state_should_wait_for_load_state_of_about_blank_popup_(563 browser, page564):565 async with page.expect_popup() as popup_info:566 await page.evaluate("window.open('about:blank') && 1")567 popup = await popup_info.value568 await popup.wait_for_load_state()569 assert await popup.evaluate("document.readyState") == "complete"570async def test_wait_for_load_state_should_wait_for_load_state_of_about_blank_popup_with_noopener(571 browser, page572):573 async with page.expect_popup() as popup_info:574 await page.evaluate("window.open('about:blank', null, 'noopener') && 1")575 popup = await popup_info.value576 await popup.wait_for_load_state()577 assert await popup.evaluate("document.readyState") == "complete"578async def test_wait_for_load_state_should_wait_for_load_state_of_popup_with_network_url_(579 browser, page, server580):581 await page.goto(server.EMPTY_PAGE)582 async with page.expect_popup() as popup_info:583 await page.evaluate("url => window.open(url) && 1", server.EMPTY_PAGE)584 popup = await popup_info.value585 await popup.wait_for_load_state()586 assert await popup.evaluate("document.readyState") == "complete"587async def test_wait_for_load_state_should_wait_for_load_state_of_popup_with_network_url_and_noopener_(588 browser, page, server589):590 await page.goto(server.EMPTY_PAGE)591 async with page.expect_popup() as popup_info:592 await page.evaluate(593 "url => window.open(url, null, 'noopener') && 1", server.EMPTY_PAGE594 )595 popup = await popup_info.value596 await popup.wait_for_load_state()597 assert await popup.evaluate("document.readyState") == "complete"598async def test_wait_for_load_state_should_work_with_clicking_target__blank(599 browser, page, server600):601 await page.goto(server.EMPTY_PAGE)602 await page.set_content(603 '<a target=_blank rel="opener" href="/one-style.html">yo</a>'604 )605 async with page.expect_popup() as popup_info:606 await page.click("a")607 popup = await popup_info.value608 await popup.wait_for_load_state()609 assert await popup.evaluate("document.readyState") == "complete"610async def test_wait_for_load_state_should_wait_for_load_state_of_new_page(611 context, page, server612):613 async with context.expect_page() as page_info:614 await context.new_page()615 new_page = await page_info.value616 await new_page.wait_for_load_state()617 assert await new_page.evaluate("document.readyState") == "complete"618async def test_wait_for_load_state_in_popup(context, server):619 page = await context.new_page()620 await page.goto(server.EMPTY_PAGE)621 css_requests = []622 def handle_request(request):623 css_requests.append(request)624 request.write(b"body {}")625 request.finish()626 server.set_route("/one-style.css", handle_request)627 async with page.expect_popup() as popup_info:628 await page.evaluate(629 "url => window.popup = window.open(url)", server.PREFIX + "/one-style.html"630 )631 popup = await popup_info.value632 await popup.wait_for_load_state()633 assert len(css_requests)634async def test_go_back_should_work(page, server):635 assert await page.go_back() is None636 await page.goto(server.EMPTY_PAGE)637 await page.goto(server.PREFIX + "/grid.html")638 response = await page.go_back()639 assert response.ok640 assert server.EMPTY_PAGE in response.url641 response = await page.go_forward()642 assert response.ok643 assert "/grid.html" in response.url644 response = await page.go_forward()645 assert response is None646async def test_go_back_should_work_with_history_api(page, server):647 await page.goto(server.EMPTY_PAGE)648 await page.evaluate(649 """() => {650 history.pushState({}, '', '/first.html')651 history.pushState({}, '', '/second.html')652 }"""653 )654 assert page.url == server.PREFIX + "/second.html"655 await page.go_back()656 assert page.url == server.PREFIX + "/first.html"657 await page.go_back()658 assert page.url == server.EMPTY_PAGE659 await page.go_forward()660 assert page.url == server.PREFIX + "/first.html"661async def test_frame_goto_should_navigate_subframes(page, server):662 await page.goto(server.PREFIX + "/frames/one-frame.html")663 assert "/frames/one-frame.html" in page.frames[0].url664 assert "/frames/frame.html" in page.frames[1].url665 response = await page.frames[1].goto(server.EMPTY_PAGE)666 assert response.ok667 assert response.frame == page.frames[1]668async def test_frame_goto_should_reject_when_frame_detaches(page, server):669 await page.goto(server.PREFIX + "/frames/one-frame.html")670 await page.route("**/empty.html", lambda route, request: None)671 navigation_task = asyncio.create_task(page.frames[1].goto(server.EMPTY_PAGE))672 asyncio.create_task(page.eval_on_selector("iframe", "frame => frame.remove()"))673 with pytest.raises(Error) as exc_info:674 await navigation_task675 assert "frame was detached" in exc_info.value.message676async def test_frame_goto_should_continue_after_client_redirect(page, server):677 server.set_route("/frames/script.js", lambda _: None)678 url = server.PREFIX + "/frames/child-redirect.html"679 with pytest.raises(Error) as exc_info:680 await page.goto(url, timeout=5000, wait_until="networkidle")681 assert "Timeout 5000ms exceeded." in exc_info.value.message682 assert (683 f'navigating to "{url}", waiting until "networkidle"' in exc_info.value.message684 )685async def test_frame_wait_for_nav_should_work(page, server):686 await page.goto(server.PREFIX + "/frames/one-frame.html")687 frame = page.frames[1]688 async with frame.expect_navigation() as response_info:689 await frame.evaluate(690 "url => window.location.href = url", server.PREFIX + "/grid.html"691 )692 response = await response_info.value693 assert response.ok694 assert "grid.html" in response.url695 assert response.frame == frame696 assert "/frames/one-frame.html" in page.url697async def test_frame_wait_for_nav_should_fail_when_frame_detaches(page, server):698 await page.goto(server.PREFIX + "/frames/one-frame.html")699 frame = page.frames[1]700 server.set_route("/empty.html", lambda _: None)701 with pytest.raises(Error) as exc_info:702 async with frame.expect_navigation():703 await asyncio.gather(704 frame.evaluate('window.location = "/empty.html"'),705 page.evaluate(706 'setTimeout(() => document.querySelector("iframe").remove())'707 ),708 )709 assert "frame was detached" in exc_info.value.message710async def test_frame_wait_for_load_state_should_work(page, server):711 await page.goto(server.PREFIX + "/frames/one-frame.html")712 frame = page.frames[1]713 request_future = asyncio.Future()714 await page.route(715 server.PREFIX + "/one-style.css",716 lambda route, request: request_future.set_result(route),717 )718 await frame.goto(server.PREFIX + "/one-style.html", wait_until="domcontentloaded")719 request = await request_future720 load_task = asyncio.create_task(frame.wait_for_load_state())721 # give the promise a chance to resolve, even though it shouldn't722 await page.evaluate("1")723 assert not load_task.done()724 asyncio.create_task(request.continue_())725 await load_task726async def test_reload_should_work(page, server):727 await page.goto(server.EMPTY_PAGE)728 await page.evaluate("window._foo = 10")729 await page.reload()730 assert await page.evaluate("window._foo") is None731async def test_reload_should_work_with_data_url(page, server):732 await page.goto("data:text/html,hello")733 assert "hello" in await page.content()734 assert await page.reload() is None735 assert "hello" in await page.content()736async def test_should_work_with__blank_target(page, server):737 def handler(request):738 request.write(739 f'<a href="{server.EMPTY_PAGE}" target="_blank">Click me</a>'.encode()740 )741 request.finish()742 server.set_route("/empty.html", handler)743 await page.goto(server.EMPTY_PAGE)744 await page.click('"Click me"')745async def test_should_work_with_cross_process__blank_target(page, server):746 def handler(request):747 request.write(748 f'<a href="{server.CROSS_PROCESS_PREFIX}/empty.html" target="_blank">Click me</a>'.encode()749 )750 request.finish()751 server.set_route("/empty.html", handler)752 await page.goto(server.EMPTY_PAGE)753 await page.click('"Click me"')754def expect_ssl_error(error_message: str, browser_name: str) -> None:755 if browser_name == "chromium":756 assert "net::ERR_CERT_AUTHORITY_INVALID" in error_message757 elif browser_name == "webkit":758 if sys.platform == "darwin":759 assert "The certificate for this server is invalid" in error_message760 elif sys.platform == "win32":761 assert "SSL connect error" in error_message762 else:763 assert "Unacceptable TLS certificate" in error_message764 else:...

Full Screen

Full Screen

VerifiedConnectionTestClient.py

Source:VerifiedConnectionTestClient.py Github

copy

Full Screen

1from ssl import SSLError2from sys import exit3from ..https import VerifiedHTTPSConnection4def fail_and_exit(host, method, path, status):5 print 'Connection request failed: %s %s%s' % (method, host, path)6 print 'Response status: %d' % status7 exit(1)8def test_conn(host, method, path, expect_status=200, expect_ssl_error=False, verify_no_text_match=None):9 try:10 conn = VerifiedHTTPSConnection(host=host)11 conn.request(method, path)12 response = conn.getresponse()13 if expect_ssl_error:14 raise RuntimeError('Got response status %d but expected SSLError', response.status)15 if expect_status != response.status:16 fail_and_exit(host, method, path, response.status)17 if verify_no_text_match:18 if -1 != response.read().find(verify_no_text_match):19 print 'Bad text "%s" found in response' % verify_no_text_match20 exit(1)21 except SSLError, ex:22 if not expect_ssl_error:23 print ex24 exit(1)25if __name__ == '__main__':26 test_conn('www.digicert.com', 'GET', '/css/bv.css')27 test_conn('64.78.193.234', 'GET', '/css/bv.css', expect_ssl_error=True)28 test_conn('chain-demos.digicert.com', 'GET', '/')...

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