Код в файле теста:
@pytest.mark.skipif(pytest.mark._config.getoption('os') == 'win',
reason='This test is for Mac only')
def test_correct_app_version_should_be_downloaded_on_mac(driver):
page.open(driver)
page.click_download_button(driver)
assert page.is_downloaded_app_version_correct(driver, TestData.app_for_mac_format), \
"Downloaded App has incorrect for Mac format"@pytest.mark.skipif(pytest.mark._config.getoption('os') == 'mac',reason='This test is for Windows only')
def test_correct_app_version_should_be_downloaded_on_windows(driver_win_chrome):
page.open(driver_win_chrome)
page.click_download_button(driver_win_chrome)
assert page.is_downloaded_app_version_correct(
driver_win_chrome, TestData.sa_app_for_win_format), \
"Downloaded App has incorrect for Windows format"
Код в Page:
@allure.step("Check if downloaded App version is correct.")
def is_downloaded_app_version_correct(driver, expected_format):
downloaded_file_name = _get_downloaded_filename(driver, 180)
print(downloaded_file_name)
return expected_format in downloaded_file_namedef _get_downloaded_filename(driver, waitTime):
driver.execute_script("window.open()")
driver.switch_to.window(driver.window_handles[-1])
driver.get('chrome://downloads')
endTime = time.time()+waitTime
while True:
try:
return driver.execute_script(
"return document.querySelector('downloads-manager').shadowRoot.querySelector"
"('#downloadsList downloads-item').shadowRoot.querySelector"
"('div#content #file-link').text")
except:
pass
time.sleep(1)
if time.time() > endTime:
break
Комментариев нет:
Отправить комментарий