import time import pytest import webview from .util import run_test html = """
""" @pytest.fixture def window(): return webview.create_window('Download test', html=html) # skip this test by default since it's a manual test that requires user interaction @pytest.mark.skip def test_download_attribute(window): webview.settings['ALLOW_DOWNLOADS'] = True run_test(webview, window, download_test) def get_result(): res = input( 'Did the system prompt you for a download with name test_download.txt or download a file by that name? Y/N' ).upper() return res == 'Y' def download_test(window): # this should not cause the browser to navigate away but instead should trigger a download # since the type is text the browser should support it and if it navigates to it it will display it instead window.evaluate_js("document.getElementById('start_download').click();") time.sleep(0.5) # make sure it has executed # if it loaded on the page and navigated away then it will fail this elements = window.dom.get_elements('#start_download') assert len(elements) == 1 # wait for download prompt to be dismissed and focus to come back to window while not window.evaluate_js('checkFocus()'): time.sleep(0.5) # ask user if the test passed assert window.evaluate_js('verify_result();')