def clearfields(driver, screenshot = False): #Wait for the defualt search to finish waitforload(driver) #Click on reset button try: #Try to click on reset via css WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//a[@class='button' or @class='button buttonOver' and @name='reset']"))).click() except: #Try to click rest css if xpath fails WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "[name='reset']"))).click() if screenshot: path_name = get_datetime_path("obidev-intern-josh", "rest_fields_css_click") driver.save_screenshot(path_name) #Click on Clear all option try: #Try to click on clear all via xpath WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//span[contains(text(),'Clear All')]"))).click() except: #Try to click clear all css if xpath fails WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "div.floatingWindowDiv.contextMenu > div:nth-of-type(5) > table.ContextMenuOptionTable > tbody > tr > td.contextMenuOptionTextCell > span.contextMenuOptionText"))).click() if screenshot: path_name = get_datetime_path("obidev-intern-josh", "clear_fields_css_click") driver.save_screenshot(path_name) #Wait 3 seconds for the clear to finish time.sleep(3)
def moreSearchHandler(driver, dropdownElement, list_to_search, screenshot = False): #Open our drop element dropdownElement.click() #Open the search/more... option try: #Try to open search/more.. option via css WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "div.floatingWindowDiv > div > div.DropDownSearch > span"))).click() except: #Try to open search/more.. option via xpath taking a screenshot to show we had to use xpath path_name = get_datetime_path("obidev", "search_more_except_xpath") driver.save_screenshot(path_name) WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//input[@class='DropDownSearch' and @style='display: block;']"))).click() #Click the remove all button WebDriverWait(driver, 30).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[@title='Remove All']"))).click() for search_item in list_to_search: #Enter our string to search for into the search box WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchStringSearchEditBoxFieldWidth' and @name='choiceListSearchString']"))).send_keys(str(search_item)) #Press the Search button try: #Via css WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "#searchButton"))).click() except: #if css fails try xpath WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//input[@type='button' and @name='searchButton' and @id='searchButton']"))).click() #wait for our search to finish by waiting for the searched element to be highlighted WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//span[@class='searchHighlightedText']"))).click() #Click move all button now that our search is done WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[@title='Move All']"))).click() #Screenshot for debuging if the function was handed a true as the last input if screenshot: path_name = get_datetime_path("obidev-intern-josh", search_item) driver.save_screenshot(path_name) #Clear the search field in preperation for the next test WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchStringSearchEditBoxFieldWidth' and @name='choiceListSearchString']"))).clear() #click OK on the button of the More/search window element to finish our more/search selection driver.find_element_by_css_selector('[name="OK"]').click()
def gobtn_helper(driver, xpath_to_search, counter, screenshot): #Wait for 3 seconds to provent a "There is a pending request to the server" Error time.sleep(3) try: #Try to click on gobtn via css WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, "//input[@class='button' or @class='button buttonOver' and @name='gobtn' or @value='Apply']"))).click() except: #Try to click gobtn css if xpath fails WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "#gobtn"))).click() if screenshot: path_name = get_datetime_path("obidev-intern-josh", "gobtn_helper_css_click") driver.save_screenshot(path_name) try: #Can we find the xpath element that tells the user that the search is currently being preformed? If so move on and wait for our querry to finish like normal WebDriverWait(driver, 2).until(expected_conditions.presence_of_element_located((By.XPATH, "//div[contains(text(),'Searching... To cancel, click')]"))) if screenshot: path_name = get_datetime_path("obidev-intern-josh", "gobtn_helper_loading") driver.save_screenshot(path_name) except: try: #Was the search fast enough that we can already see our results? If so move on now to the next part of the script as we are sure the gobtn worked WebDriverWait(driver, 2).until(expected_conditions.presence_of_element_located((By.XPATH, xpath_to_search))) if screenshot: path_name = get_datetime_path("obidev-intern-josh", "gobtn_helper_check_element") driver.save_screenshot(path_name) except: #If we reach this point we can asume something went wrong with the gobtn press, so lets try this whole process again but with a max of 2 atempts if counter < 3: counter = counter + 1 if screenshot: path_name = get_datetime_path("obidev-intern-josh", "gobtn_helper_couter_triggerd") driver.save_screenshot(path_name) gobtn_helper(driver, xpath_to_search, counter, screenshot) else: #Our test has failed lets take a screenshot and fail the test path_name = get_datetime_path("obidev-intern-josh", "gobtn_FAILURE") driver.save_screenshot(path_name) assert 2 == 1
def test_z_better_display_content(self): driver = self.driver #self.driver.implicitly_wait(10) # seconds #sign in using sign in abstraction user_signin.signin(driver, "Username") # go directly to general fund dashboard. self.driver.get("https://obitest.humboldt.edu:9804/analytics/saw.dll?dashboard&PortalPath=%2Fshared%2F2.0%20-%20Finance%2F_portal%2F2.0.1%20-%20General%20Fund") #Sleep for 5 seconds to insure page loads before getting the dropdown, becuase its css it may grab the wrong dropdown becuase of how the page is loading on the emulated display time.sleep(5) #Clear fields via clear fields abstraction user_signin.clearfields(driver) #Store dropdown for selecting fiscal year. dropdown = WebDriverWait(driver, 120).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "tr > td:first-child > table > tbody > tr:first-child > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > img.promptDropDownButton"))) #create a list of elements we want to select in our dropdown list_to_select = ["2015-2016"] #use moreSearchHandler abstraction to do de selects and selects user_signin.moreSearchHandler(driver, dropdown, list_to_select) #Store dropdown for selecting Department year. dropdown = WebDriverWait(driver, 120).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "tr > td:first-child > table > tbody > tr:nth-of-type(4) > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > img.promptDropDownButton"))) #create a list of elements we want to select in our dropdown list_to_select = ["D10001"] #use moreSearchHandler abstraction to do de selects and selects user_signin.moreSearchHandler(driver, dropdown, list_to_select) #Click apply to get our records we are asking for(gobtn) user_signin.clickgobtn(driver,"//td[contains(text(),'644,238.00')]", True) # Store known value '644,238.00' in spreadsheet into variable. try: time.sleep(1) operating_fund_orig_budge = WebDriverWait(driver, 240).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[contains(text(),'644,238.00')]"))).text time.sleep(1) except: path_name = get_datetime_path("obidev-intern-max", "operating_fund_orig_budge") self.driver.save_screenshot(path_name) operating_fund_orig_budge = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[contains(text(),'644,238.00')]"))).text self.driver.save_screenshot(path_name) # Casting this variable to a string because it is brought in as UNICODE type. str(operating_fund_orig_budge) #verify that amount is the known correct value 644,238.00.A assert operating_fund_orig_budge == "644,238.00"
def signout(driver): time.sleep(3) #This sleep is to make sure we dont get this test done so fast that obi think we are loging out while still retreaving data. try: #Trys to click on singout via xpath, if sucess we are done WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//span[contains(text(),'Sign Out')]"))).click() except: try: #If xpath fails try to click on sinout via css, if sucsess we are done WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "#logout > span.HeaderMenuBarText > span"))).click() except: #If we failed to click via css after trying xpath we take a screenshot and try again to throw an exption failing the test path_name = get_datetime_path("obidev-intern-josh", "SignOutFAILURE") driver.save_screenshot(path_name) WebDriverWait(driver, 1).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, "#logout > span.HeaderMenuBarText > span"))).click()
def test_finacial_trial_balance(self): driver = self.driver self.driver.implicitly_wait(7) #seconds #sign in using sign in abstraction user_signin.signin(driver, "Username") #go directly to 2.0.3 Financial Reports, Trial Balance self.driver.get( "https://obitest.humboldt.edu:9804/analytics/saw.dll?dashboard&PortalPath=%2Fshared%2F2.0%20-%20Finance%2F_portal%2F2.0.3%20-%20Financial%20Reports" ) #Sleep for 5 seconds to insure page loads before getting the dropdown, becuase its css it may grab the wrong dropdown becuase of how the page is loading on the emulated display time.sleep(5) #Store dropdown for selecting fiscal year. dropdown = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:nth-of-type(3) > table > tbody > tr > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > input.promptTextField.promptTextFieldReadOnly" ))) #create a list of elements we want to select in our dropdown list_to_select = ["2016-2017"] #use moreSearchHandler abstraction to do de selects and selects user_signin.moreSearchHandler(driver, dropdown, list_to_select) #Store dropdown for selecting fund year. dropdown = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:nth-of-type(2) > table > tbody > tr > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > input.promptTextField.promptTextFieldReadOnly.textFieldHelper" ))) #create a list of elements we want to select in our dropdown list_to_select = ["N4500"] #use moreSearchHandler abstraction to do de selects and selects user_signin.moreSearchHandler(driver, dropdown, list_to_select) #Click apply to get our records we are asking for(gobtn) user_signin.clickgobtn(driver, "//td[contains(text(),'(50,631.00)')]") #Copy Reveniue Total Using dynamic wait with maximum time of 120 #rev_total = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[@class='TTHT PTHT OORT' and @id='e_saw_2609_c_1_2_5']"))).text #rev_total = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[contains(text(),'(50,631.00)') and @id='e_saw_2609_c_1_2_5']"))).text rev_total = WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located( (By.CSS_SELECTOR, "tbody > tr:nth-of-type(8) > td.TTHT.PTHT.PTLC.OORT"))).text #Copy Expendetures total Using dynamic wait #exp_total = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[@class='TTHT PTHT OORT' and @id='e_saw_2609_c_1_2_20']"))).text #exp_total = WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, "//td[contains(text(),'50,631.00') and @id='e_saw_2609_c_1_2_20']"))).text exp_total = WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located( (By.CSS_SELECTOR, "tbody > tr:nth-of-type(23) > td.TTHT.PTHT.PTLC.OORT"))).text time.sleep(2) str(rev_total) str(exp_total) rev_total_stripped = rev_total.strip("()") exp_total_stripped = exp_total.strip("()") try: assert rev_total_stripped == exp_total_stripped except: path_name = get_datetime_path("obidev-intern-josh", "finacial_trial_bal_FAILURE") driver.save_screenshot(path_name) assert rev_total_stripped == exp_total_stripped
def test_PI_role_row_level(self): # Normal abstraction does not work here we need anothr function to handle the "date" and dept style moreSearchHandler driver = self.driver self.driver.implicitly_wait(7) #seconds #sign in using sign in abstraction user_signin.signin(driver, "Username") #go directly to 2.0.0 Chartfields and Vendors dashboard self.driver.get( "https://obitest.humboldt.edu:9804/analytics/saw.dll?dashboard&PortalPath=%2Fshared%2F2.0%20-%20Finance%2F_portal%2F2.0.0%20Chartfields%20and%20Vendors" ) #Click on the Departments tab try: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:nth-of-type(2) > table.tabContainer > tbody > tr > td.secondaryTabEnabled > span" ))).click() except: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located( (By.XPATH, "//span[contains(text(), 'Departments')]"))).click() #Sleep a bit to insure the departments tab has loaded time.sleep(5) #Open dropdown for selecting Fiscal Year. try: dropdownyear = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tbody > tr:first-child > td:nth-of-type(2) > table > tbody > tr > td.data.promptControl > div > div.promptChoiceListBox > input.promptTextField.promptTextFieldReadOnly" ))) except: dropdownyear = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tbody > tr:first-child > td:nth-of-type(2) > table > tbody > tr > td.data.promptControl > div > div.promptChoiceListBox > img.promptDropDownButton" ))) #create a list of elements we want to select in our dropdown list_to_search_year = ["2016"] self.moreSearchHandler(driver, dropdownyear, list_to_search_year) #select the dropdown for Dept_ID (Point in Time) WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:nth-of-type(2) > table > tbody > tr:first-child > td:nth-of-type(2) > table > tbody > tr > td.data.promptControl > div > div:first-child > img.promptComboBoxButtonMoz" ))).click() #select the proper dept_ID "D10001" try: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='checkboxRadioButton' and @value='D10001']" ))).click() except: try: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "div.floatingWindowDiv > div > div.DropDownValueList > div:nth-of-type(4) > div.promptDropdownNoBorderDiv > input.checkboxRadioButton" ))).click() except: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, ".floatingWindowDiv > div:nth-child(1) > div:nth-child(2) > div:nth-child(4)" ))).click() #de-select the dropdown for Dept_ID (Point in Time) WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:nth-of-type(2) > table > tbody > tr:first-child > td:nth-of-type(2) > table > tbody > tr > td.data.promptControl > div > div:first-child > img.promptComboBoxButtonMoz" ))).click() #Screenshot before gobtn self.driver.save_screenshot( '/var/lib/jenkins/workspace/obidev/CI-RPD/screenshots/PI_test_before_click_apply.png' ) #Click apply to get our records we are asking for(gobtn) user_signin.clickgobtn( driver, "//td[contains(text(),\"PRESIDENT'S OFFICE\")]") #Check to make sure that the presidents office is the department we got try: WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located( (By.XPATH, "//td[contains(text(),\"PRESIDENT'S OFFICE\")]"))) except: path_name = get_datetime_path("obidev-intern-josh", "role_row_FAILURE") driver.save_screenshot(path_name) WebDriverWait(driver, 5).until( expected_conditions.presence_of_element_located( (By.XPATH, "//td[contains(text(),\"PRESIDENT'S OFFICE\")]"))) #We found presidents office so pass via a assertion assert 2 == 2
def moreSearchHandler(self, driver, dropdownElement, list_to_search): #Open our drop element dropdownElement.click() #Open the search/more... option try: # path_name = get_datetime_path("obidev-intern-max", "search_more_try_css_role_row") # driver.save_screenshot(path_name) WebDriverWait(driver, 10).until( expected_conditions.presence_of_element_located( (By.CSS_SELECTOR, "div.floatingWindowDiv > div > div.DropDownSearch > span" ))).click() except: path_name = get_datetime_path("obidev-intern-max", "search_more_try_xpath_role_row") driver.save_screenshot(path_name) WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='DropDownSearch' and @style='display: block;']" ))).click() #Click the remove all button driver.find_element_by_xpath("//td[@title='Remove All']").click() for search_item in list_to_search: #Enter our string to search for into the search box #driver.find_element_by_xpath("//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchStringSearchEditBoxFieldWidth' and @name='choiceListSearchString']").send_keys(str(search_item)) WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchNumericalSearchEditBoxFieldWidth' and @name='numericSearchValue_1']" ))).send_keys(str(search_item)) WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchNumericalSearchEditBoxFieldWidth' and @name='numericSearchValue_2']" ))).send_keys(str(search_item)) #Press the Search button #driver.find_element_by_xpath("//input[@type='button' and @name='searchButton' and @id='searchButton']").click() WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@type='button' and @name='searchButton' and @id='searchButton']" ))).click() #Click move all button #driver.find_element_by_xpath("//td[@title='Move All']").click() WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located( (By.XPATH, "//td[@title='Move All']"))).click() #Clear search field #driver.find_element_by_xpath("//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchStringSearchEditBoxFieldWidth' and @name='choiceListSearchString']").clear() WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchNumericalSearchEditBoxFieldWidth' and @name='numericSearchValue_1']" ))).clear() WebDriverWait(driver, 30).until( expected_conditions.presence_of_element_located(( By.XPATH, "//input[@class='promptEditBoxField promptEditBoxFieldWidth promptSearchNumericalSearchEditBoxFieldWidth' and @name='numericSearchValue_2']" ))).clear() #click OK on the button of the More/search window element driver.find_element_by_css_selector('[name="OK"]').click()
def test_finance_totals(self): driver = self.driver self.driver.implicitly_wait(7) # seconds #sign in using sign in abstraction user_signin.signin(driver, "Username") #Navigate the driver to the 2.0.1 General Fun self.driver.get( "https://obitest.humboldt.edu:9804/analytics/saw.dll?Dashboard&PortalPath=%2Fshared%2F2.0%20-%20Finance%2F_portal%2F2.0.1%20-%20General%20Fund&page=General%20Fund%20Expenditures" ) #Sleep for 5 seconds to insure page loads before getting the dropdown, becuase its css it may grab the wrong dropdown becuase of how the page is loading on the emulated display time.sleep(5) #Clear fields via clear fields abstraction user_signin.clearfields(driver) #Open dropdown for selecting Fiscal Year. dropdownyear = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:first-child > table > tbody > tr:first-child > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > img.promptDropDownButton" ))) #create a list of elements we want to select in our dropdown list_to_search_year = ["2015-2016"] user_signin.moreSearchHandler(driver, dropdownyear, list_to_search_year) #get dropdown for mbu dropdownMBU = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:first-child > table > tbody > tr:nth-of-type(3) > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > img.promptDropDownButton" ))) #create a list of elements we want to select in our dropdown list_to_search_MBU = ["ACADEMIC AFFAIRS - VP"] user_signin.moreSearchHandler(driver, dropdownMBU, list_to_search_MBU) #get dropdown for department dropdownMBU = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located(( By.CSS_SELECTOR, "tr > td:first-child > table > tbody > tr:nth-of-type(4) > td > table > tbody > tr:nth-of-type(2) > td > span > span.data.promptControlNarrowView > div > div.promptChoiceListBox > img.promptDropDownButton" ))) #create a list of elements we want to select in our dropdown(This time we dont want to select anything, only remove so we have an empty list) emptylist = [] user_signin.moreSearchHandler(driver, dropdownMBU, emptylist) # #Click apply to get our records we are asking for(gobtn) user_signin.clickgobtn(driver, "//a[contains(text(),'1,435,290.56')]", True) #Dynamic wait for our element with a max time of 120 seconds, then we store that element[HM500 - OPERATING FUND | 601 - Regular Salaries and Wages] try: actuals = WebDriverWait(driver, 120).until( expected_conditions.presence_of_element_located( (By.XPATH, "//a[contains(text(),'1,435,290.56')]"))).text except: path_name = get_datetime_path("obidev-intern-josh", "test_finance_totals_FAILURE") driver.save_screenshot(path_name) actuals = WebDriverWait(driver, 5).until( expected_conditions.presence_of_element_located( (By.XPATH, "//a[contains(text(),'1,435,290.56')]"))).text # Casting this variable to a string because it is brought in as UNICODE type. str(actuals) #verify that amount is the known correct value 1,435,290.56. assert actuals == "1,435,290.56"