tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

frames.py (1263B)


      1 import pytest
      2 from webdriver.error import NoSuchWindowException
      3 
      4 from tests.support.sync import AsyncPoll
      5 
      6 pytestmark = pytest.mark.asyncio
      7 
      8 
      9 async def test_classic_switch_to_parent_no_browsing_context(bidi_session, current_session, url):
     10    # With WebDriver classic it cannot be checked if the parent frame is already
     11    # gone before switching to it. To prevent race conditions such a check needs
     12    # to be done via WebDriver BiDi.
     13    current_session.url = url("/webdriver/tests/support/html/frames.html")
     14 
     15    subframe = current_session.find.css("#sub-frame", all=False)
     16    current_session.switch_to_frame(subframe)
     17 
     18    deleteframe = current_session.find.css("#delete-frame", all=False)
     19    current_session.switch_to_frame(deleteframe)
     20 
     21    button = current_session.find.css("#remove-top", all=False)
     22    button.click()
     23 
     24    # Wait until iframe is gone.
     25    async def is_frame_removed(_):
     26        contexts = await bidi_session.browsing_context.get_tree(root=current_session.window_handle)
     27        assert not contexts[0]["children"], "iframe that should be closed is still open"
     28 
     29    wait = AsyncPoll(current_session)
     30    await wait.until(is_frame_removed)
     31 
     32    with pytest.raises(NoSuchWindowException):
     33        current_session.switch_to_parent_frame()