tor-browser

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

test_1287715_littlealchemy2_com.py (1122B)


      1 import asyncio
      2 
      3 import pytest
      4 
      5 URL = "https://littlealchemy2.com/"
      6 PLAY_BUTTON_CSS = "#loading-screen .btn.js-ready"
      7 
      8 
      9 async def did_music_play(client):
     10    await client.navigate(URL, wait="none")
     11    play = client.await_css(PLAY_BUTTON_CSS, is_displayed=True)
     12    client.execute_script(
     13        """
     14      window.__musicPlayed = false;
     15      AudioBufferSourceNode.prototype.start = function() {
     16        window.__musicPlayed = true;
     17      }
     18    """
     19    )
     20    play.click()
     21 
     22    # click somewhere so audio can start playing on Android
     23    client.apz_click(element=client.await_css("#library", is_displayed=True))
     24 
     25    await asyncio.sleep(2)
     26    return client.execute_script("return window.__musicPlayed")
     27 
     28 
     29 @pytest.mark.asyncio
     30 @pytest.mark.with_interventions
     31 async def test_enabled(client):
     32    assert await did_music_play(client)
     33 
     34 
     35 @pytest.mark.asyncio
     36 @pytest.mark.without_interventions
     37 async def test_disabled(client):
     38    # the problem is intermittent, so we try multiple times just in case.
     39    for _ in range(5):
     40        if not await did_music_play(client):
     41            assert True
     42            return
     43    assert False