Source code for django_landing_simple.test.test_error_simple_500
"""test program for the django template "error_500"based on the "unittest" and "selenium" functionality"""importunittestfromselenium.webdriver.common.byimportByfromselenium.webdriver.support.waitimportWebDriverWaitfromselenium.webdriver.supportimportexpected_conditionsasEC# Import base test case for automatic cleanupfromdjango_landing_simple.test.base_test_caseimportReadOnlyDjangoTestCase
[docs]classtest_error_simple_500(ReadOnlyDjangoTestCase):""" Class for the test cases of the django template "error_500" """
[docs]deftest_cases(self):""" test cases for the template "error_500" """# Get test parameters from configurationcustom_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 500 error (Internal Server Error)# Using the test route that raises a generic Exceptionself.driver.get(custom_url+'/test/trigger_500/')# assertion to confirm that the title has the keyword in itassert'Error 500'inself.driver.title# search and enter linkwait=WebDriverWait(self.driver,10)link=wait.until(EC.presence_of_element_located((By.LINK_TEXT,"Back to homepage")))# Scroll into viewself.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 interceptionself.driver.execute_script("arguments[0].click();",link)# assertion to test that template "home" is called after submitassertcustom_title_homepageinself.driver.title