def test_qed_leftlinks(): test_name = "Test of Ubertool Mainpage Left Column Links " try: # verify that all links on a model page produce status code of 200 for main_server in servers: response = requests.get(main_server + "/ubertool") soup_content = BeautifulSoup(response.content, "html.parser") div_tags_left = soup_content.find_all('div', {'class': 'left'}) # assuming a single div/class by this name left_links = div_tags_left[0].find_all('a') if left_links: assert_error = False link_url = [""] * len(left_links) status = [""] * len(left_links) link_url = linkcheck_helper.build_http_links(main_server, left_links) status = linkcheck_helper.status_chk(link_url) try: npt.assert_array_equal(status, 200, '200 error', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, link_url, status) return
def test_qed_input_form(): test_name = "Model Input Page Generation " try: #need to repeat login and then verify title of input page assert_error = False current_title = [""] * len(redirect_model_pages) expected_title = [""] * len(redirect_model_pages) for idx, m in enumerate(redirect_model_pages): br = mechanize.Browser() br.open(m) #step 1: login and authenticate br.select_form(name="auth") br["username"] = "******" br["password"] = "******" response2 = br.submit() response2.get_data() #locate model input page title and verify it is as expected soup = BeautifulSoup(response2, "html.parser") tag = [a.find(text=True) for a in soup.findAll('h2', {'class': 'model_header'})] current_title[idx] = m.replace("input", "") + ": " + str(tag[0]) expected_title[idx] = m.replace("input", "") + ": " + redirect_models[idx] + " Inputs" #create array comparison ((assume h2/model header -tag- of interest is first in list) try: npt.assert_array_equal(current_title, expected_title,'Wrong Input Page Title', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_title, current_title) return
def test_qed_404(): test_name = "Model page 404 " try: assert_error = False response = [requests.get(m) for m in model_pages] check_of404 = ["Ok"] * len(response) assume_no404 = [False] * len(response) #assume no 404 in page html page_content = [BeautifulSoup(r.content, "html.parser") for r in response] find_N404s = [len(s.findAll('img',src='/static/images/404error.png')) for s in page_content] did_we_find404 = [s>0 for s in find_N404s] for item in did_we_find404: if item == True: check_of404[item] = "Found 404" try: npt.assert_array_equal(did_we_find404, assume_no404, '404 error', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, model_pages, check_of404) return
def test_qed_redirect(): #redirects occur on 'input' pages due to login requirement test_name = "Model Input Page Redirect " try: response = [requests.get(m) for m in redirect_model_pages] assert_error = False check_of302 = ["302 Failed"] * len(response) did_we_find302 = [False] * len(response) assume302 = [True] * len(response) # we're expecting 302 as response history for idx, r in enumerate(response): for resp in r.history: if resp.status_code == 302: did_we_find302[idx] = True check_of302[idx] = "Ok" try: npt.assert_array_equal(did_we_find302, assume302, '302 error', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, redirect_model_pages, check_of302) return
def test_qed_authenticate_input(): test_name = "Model Input Page Login Authentication " try: #need to login and then verify we land on input page current_page = [""] * len(redirect_model_pages) expected_page = [""] * len(redirect_model_pages) assert_error = False for idx, m in enumerate(redirect_model_pages) : br = mechanize.Browser() br.open(m) #step 1: login and authenticate br.select_form(name="auth") br["username"] = "******" br["password"] = "******" br.submit() # Verify we have successfully logged in and are now on input page current_page[idx] = br.geturl() expected_page[idx] = m try: npt.assert_array_equal(expected_page, current_page, 'Login Failed', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_page, current_page) return
def test_qed_mainpagelinks(): try: # verify that all links on a model page (main article section) produce status code of 200 test_name = "Model Mainpage Article Links " for page in model_tab_pages: response = requests.get(page) soup_content = BeautifulSoup(response.content, "html.parser") div_tag_article = soup_content.find_all('div', {'class': 'articles'}) # assuming a single div/class by this name if div_tag_article: article_links = div_tag_article[0].find_all('a') if article_links: link_url = [""] * len(article_links) status = [""] * len(article_links) link_url = linkcheck_helper.build_http_links(page, article_links) status = linkcheck_helper.status_chk(link_url) try: npt.assert_array_equal(status, 200, '200 error', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, link_url, status) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) return
def test_qed_output_form(): try: # verify proper output page content, i.e., page title # need to repeat login, submit default inputs test_name = "Input Form Submittal and Output Generation " current_title = [""] * len(redirect_model_pages) expected_title = [""] * len(redirect_model_pages) assert_error = False for idx, m in enumerate(redirect_model_pages): expected_title[idx] = m.replace("input", "") + " : " + redirect_models[idx] + " Output" browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull) browser.get(m) # login and authenticate username = browser.find_element_by_name("username") username.send_keys("betatester") password = browser.find_element_by_name("password") password.send_keys("ubertool") with WaitForPageLoad(browser): login = browser.find_element_by_xpath("//form[@name='auth']") login.submit() # use .click() for individual buttons and .submit() for form submittal # Locate and submit input form (using the default data for now) with WaitForPageLoad(browser): locate_submit = browser.find_element_by_xpath("//div[@class='input_right']") try: form_submit = browser.find_element_by_xpath("//button[@class='input_button']") except: form_submit = browser.find_element_by_xpath("//button[@class='submit input_button']") form_submit.submit() # use .click() for individual buttons and .submit() for form submittal if browser.page_source.__contains__("User Inputs"): current_title[idx] = browser.current_url.replace("output", "") + " : " + redirect_models[ idx] + " Output" elif browser.page_source.__contains__('File Not Found'): current_title[idx] = browser.current_url.replace("output", "") + " : File Not Found Page Error" else: current_title[idx] = browser.current_url.replace("output", "") + " : Unknown Output Page Error" try: npt.assert_array_equal(expected_title, current_title, 'Submittal of Input Failed', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_title, current_title) browser.quit() return
def test_qed_200(): test_name = "Model page access " try: assert_error = False response = [requests.get(m).status_code for m in model_pages] try: npt.assert_array_equal(response, 200, '200 error', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, model_pages, response) return
def test_qed_qaqc_form(): try: test_name = "QAQC Execution and Results Generation " current_page_id = [""] * len(qaqc_model_pages) # pageID = url + <h2 class='model header' string> expected_page_id = [""] * len(qaqc_model_pages) assert_error = False browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull) # added the argument service_log_path=os.path.devnull to the function webdriver.PhantomJS() # to prevent PhantomJS from creating a ghostdriver.log in the directory of the python file # being executed. for idx, m in enumerate(qaqc_model_pages): expected_page_id[idx] = m + "/run : " + qaqc_models[idx] + " QAQC" browser.get(m) try: with WaitForPageLoad(browser): qaqc_run_button = browser.find_element_by_id('runQAQC') qaqc_run_button.click() if browser.current_url.__str__() != m + "/run": current_page_id[idx] = str( browser.current_url) + " : Run QAQC failed" # we did not arrive at expected url elif browser.page_source.__contains__('File Not Found'): current_page_id[idx] = str(browser.current_url) + " : File Not Found Page Error" elif browser.page_source.__contains__("User Inputs"): # check to see of string User Inputs appears on page current_page_id[idx] = m + "/run : " + qaqc_models[idx] + " QAQC" else: current_page_id[idx] = str(browser.current_url) + " Unknown QAQC run error" except: current_page_id[idx] = m + " Unknown exception thrown" # build array for reporting table try: npt.assert_array_equal(expected_page_id, current_page_id, 'QAQC Failed', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_page_id, current_page_id) browser.quit() return
def test_qed_output_form(): test_name = "Model output generation " try: #need to repeat login, submit default inputs, and verify we land on output page assert_error = False current_title = [""] * len(redirect_model_pages) expected_title = [""] * len(redirect_model_pages) for idx, m in enumerate(redirect_model_pages) : br = mechanize.Browser() response = br.open(m) #step 1: login and authenticate br.select_form(name="auth") br["username"] = "******" br["password"] = "******" response2 = br.submit() response2.get_data() # Step 2: Select and submit input form (it will have default data in it - we just want to run with that for now) try: br.form = list(br.forms())[0] # syntax for selecting form when form is unnamed response3 = br.submit() # use mechanize to post input data response3.get_data() #Verify we have successfully posted input data and that we have arrived at the output page soup = BeautifulSoup(response3, "html.parser") tag = [a.find(text=True) for a in soup.findAll('h2', {'class': 'model_header'})] current_title[idx] = m.replace("input", "") + ": " + str(tag[0]) expected_title[idx] = m.replace("input", "") + ": " + redirect_models[idx] + " Output" except Exception: current_title[idx] = m.replace("input", "") + ": " + "No " + redirect_models[idx] + " Output" expected_title[idx] = m.replace("input", "") + ": " + redirect_models[idx] + " Output" try: #create array comparison (assume h2/model header -tag- of interest is first in list) npt.assert_array_equal(current_title, expected_title,'Submittal of Input Failed for one or more models', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_title, current_title) return
def test_qed_input_form(): # verify input page contains expected content (we chk page title, e.g., 'SIP Inputs') # need to repeat login try: test_name = "Input Form URL " current_title = [""] * len(redirect_model_pages) expected_title = [""] * len(redirect_model_pages) assert_error = False for idx, m in enumerate(redirect_model_pages): expected_title[idx] = m + " : " + redirect_models[idx] + " Inputs" browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull) browser.get(m) # login and authenticate username = browser.find_element_by_name("username") username.send_keys("betatester") password = browser.find_element_by_name("password") password.send_keys("ubertool") with WaitForPageLoad(browser): login = browser.find_element_by_xpath("//form[@name='auth']") login.submit() # use .click() for individual buttons and .submit() for form submittal # verify that login was successful by checking that inputs page title is rendered if browser.page_source.__contains__(redirect_models[idx] + " Inputs"): current_title[idx] = m + " : " + redirect_models[idx] + " Inputs" else: current_title[idx] = m + " : " + redirect_models[idx] + " Input Submit Error" # build array for reporting table try: npt.assert_array_equal(expected_title, current_title, 'Input Form Submittal Failed', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_title, current_title) browser.quit() return
def test_qed_authenticate_input(): try: # verify successful login and that we land on input page url test_name = "Login Authentication " current_page = [""] * len(redirect_model_pages) expected_page = [""] * len(redirect_model_pages) assert_error = False for idx, m in enumerate(redirect_model_pages): browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull) browser.get(m) # login and authenticate username = browser.find_element_by_name("username") username.send_keys("betatester") password = browser.find_element_by_name("password") password.send_keys("ubertool") with WaitForPageLoad(browser): login = browser.find_element_by_xpath("//form[@name='auth']") login.submit() # use .click() for individual buttons and .submit() for form submittal #next two lines is alternative technique #LoginButton = browser.find_element_by_class_name("input_button") #LoginButton.click() # Verify we have successfully logged in and are now at input page url current_page[idx] = str(browser.current_url) expected_page[idx] = m try: npt.assert_array_equal(expected_page, current_page, 'Login Test Failed', True) except AssertionError: assert_error = True except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) except Exception as e: # handle any other exception print "Error '{0}' occured. Arguments {1}.".format(e.message, e.args) finally: linkcheck_helper.write_report(test_name, assert_error, expected_page, current_page) browser.quit() return