diff --git a/modules/browser_object_navigation.py b/modules/browser_object_navigation.py index 4aeae078e..5f7331d19 100644 --- a/modules/browser_object_navigation.py +++ b/modules/browser_object_navigation.py @@ -307,6 +307,18 @@ def refresh_page(self) -> BasePage: self.wait_for_page_to_load() return self + @BasePage.context_chrome + def hard_reload_with_key_combo(self) -> BasePage: + """ + Use Cmd/Ctrl + Shift + R to hard reload the page and overide cache. + """ + if self.sys_platform() == "Darwin": + mod_key = Keys.COMMAND + else: + mod_key = Keys.CONTROL + self.perform_key_combo(mod_key, Keys.SHIFT, "r") + return self + def handle_geolocation_prompt( self, button_type="primary", remember_this_decision=False ): diff --git a/tests/tabs/test_reload_overiding_cache_keys.py b/tests/tabs/test_reload_overiding_cache_keys.py new file mode 100644 index 000000000..a66e7fe2c --- /dev/null +++ b/tests/tabs/test_reload_overiding_cache_keys.py @@ -0,0 +1,58 @@ +import pytest +from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver import Firefox +from selenium.webdriver.common.by import By + +from modules.browser_object import TabBar +from modules.browser_object_navigation import Navigation + + +@pytest.fixture() +def test_case(): + return "134642" + + +TEST_URL = "https://postman-echo.com/headers" + + +def test_reload_overiding_cache_keys(driver: Firefox, sys_platform: str): + """ + C134642 - Verify that tabs can be hard reloaded (overriding cache) using keyboard shortcut CTRL/CMD + SHIFT + R. + """ + + browser = TabBar(driver) + nav = Navigation(driver) + + # New tab + navigate + browser.new_tab_by_button() + driver.switch_to.window(driver.window_handles[-1]) + driver.get(TEST_URL) + + # Hard reload using helper function for action CTRL/CMD + SHIFT + "r" + nav.hard_reload_with_key_combo() + + # Verify cache is not being used by checking for http request headers + # Header "if-none-match" should not be sent + try: + etag = driver.find_element(By.ID, "/headers/if-none-match").get_attribute( + "innerText" + ) + assert False, f"Unexpected If-None-Match present: {etag!r}" + except NoSuchElementException: + pass + + # Header "pragma" should be sent with with value "no-cache" + pragma_text = driver.find_element(By.ID, "/headers/pragma").get_attribute( + "innerText" + ) + assert "no-cache" in pragma_text, ( + f"Expected 'no-cache' in pragma; got: {pragma_text!r}" + ) + + # Header "cache-control" should be sent with with value "no-cache" + cache_control_text = driver.find_element( + By.ID, "/headers/cache-control" + ).get_attribute("innerText") + assert "no-cache" in cache_control_text, ( + f"Expected 'no-cache' in cache-control; got: {cache_control_text!r}" + )