Source code for django_landing_simple.test.test_error_simple_502

"""
test program for the django template "error_502"
based on the "unittest" and "selenium" functionality
"""

import unittest
from selenium.webdriver.common.by    import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support      import expected_conditions as EC

# Import base test case for automatic cleanup
from django_landing_simple.test.base_test_case import ReadOnlyDjangoTestCase

[docs] class test_error_simple_502(ReadOnlyDjangoTestCase): """ Class for the test cases of the django template "error_502" """
[docs] def test_cases(self): """ test cases for the template "error_502" """ # Get test parameters from configuration custom_url = self.config_global.get('settings_django_server', 'url') custom_title_homepage = self.config_test.get('get_settings_title', 'title_homepage') # url to trigger a 502 error (Bad Gateway) # Using the test route that returns 502 status self.driver.get(custom_url + '/test/trigger_502/') # assertion to confirm that the title has the keyword in it assert 'Error 502' in self.driver.title # search and enter link wait = WebDriverWait(self.driver, 10) link = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Back to homepage"))) # Scroll into view self.driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", link) # Small pause (optional, sometimes helps with timing) self.driver.implicitly_wait(1) # Click using JavaScript to avoid interception self.driver.execute_script("arguments[0].click();", link) # assertion to test that template "home" is called after submit assert custom_title_homepage in self.driver.title
if __name__ == "__main__": unittest.main()