def t_sql_inject_with_no_harm(self, injection): utils.search_new_catalog_by_keyword(self.browser, injection) noResultsFound = self.browser.find_elements_by_class_name("noResultsMessage") titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") success = (len(noResultsFound) == 1) or (len(titleDivs) > 0) self.assertTrue(success, "Site did not respond appropriately during SQL injection" + injection)
def t_isbn_search_for(self, isbn, title): utils.search_new_catalog_by_keyword(self.browser, isbn) # we get one results titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Found no results searching by ISBN " + isbn) self.assertTrue(len(titleDivs) < 5, "Found more than 4 results when searching by ISBN " + isbn) # result matches our expected title returnedTitleLink = titleDivs[0].find_element_by_xpath("./span/a") returnedTitleStr = returnedTitleLink.text self.assertTrue(returnedTitleStr.lower() in title.lower(), "Returned title of '" + returnedTitleStr.lower() + "' did not match expected title '" + title.lower() + "' ") # that result has the ISBN we searched for returnedTitleLink.click() self.browser.implicitly_wait(3) additionalInfoDivs = self.browser.find_elements_by_class_name("bibInfoData") addInfo = [] for item in additionalInfoDivs: addInfo.append(item.text) foundISBN = False for item in additionalInfoDivs: if isbn in item.text: foundISBN = True self.assertTrue(foundISBN, "Could not retrieve ISBN " + isbn + " for " + title)
def test_can_search_with_nonascii_characters(self): # look for the art of war utils.search_new_catalog_by_keyword(self.browser, "孫子兵法") titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Did not return any results when searching for the art of war in chinese") # look for crime and punishment utils.search_new_catalog_by_keyword(self.browser, "Преступление и наказание") titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Did not return any results when searching for crime and punishment in russian")
def t_copy_location(self, isbn): utils.search_new_catalog_by_keyword(self.browser, isbn) titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Could not retrieve any results based on isbn " + isbn) # get book copies from new catalog titleDivs[0].find_element_by_xpath("./span/a").click() self.browser.implicitly_wait(3) expand = self.browser.find_elements_by_class_name("allRowItem") if len(expand) > 0: expand[0].click() self.browser.implicitly_wait(3) nLocations = self.browser.find_elements_by_xpath("//table[@class='itemTable']//tr/td/*[1]") nLocationsText = [] for place in nLocations: nLocationsText.append(place.text) # search book by isbn in old catalog self.browser.get(utils.nypl_old_catalog) self.browser.implicitly_wait(3) self.browser.find_element_by_xpath("//select[@id='searchtype']/option[@value='i']").click() search_bar = self.browser.find_element_by_name("searcharg") search_bar.send_keys(isbn) search_bar.send_keys(Keys.ENTER) self.browser.implicitly_wait(3) # book copies from old catalog expand = self.browser.find_elements_by_xpath( "//input[@type='submit'][@value='View additional copies or search for a specific volume/copy']" ) if len(expand) > 0: expand[0].click() self.browser.implicitly_wait(3) oLocations = self.browser.find_elements_by_xpath("//div[@class='additionalCopies']/table//tr/td/*[1]") # at least all the old catalog's locations are in the new catalog # FAILING for place in oLocations: self.assertTrue( place.text in nLocationsText, "According to old catalog, " + isbn + " exists at " + place.text + ", but doesn't appear in new catalog", )
def t_copies_match(self, isbn): self.browser.get(utils.nypl_new_catalog) self.browser.implicitly_wait(3) utils.search_new_catalog_by_keyword(self.browser, isbn) titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Could not retrieve any results based on isbn " + isbn) # get book copies from new catalog titleDivs[0].find_element_by_xpath("./span/a").click() self.browser.implicitly_wait(3) expand = self.browser.find_elements_by_class_name("allRowItem") if len(expand) > 0: expand[0].click() self.browser.implicitly_wait(3) nCopies = self.browser.find_elements_by_xpath("//table[@class='itemTable']//tr") # search book by isbn in old catalog self.browser.get(utils.nypl_old_catalog) self.browser.implicitly_wait(3) self.browser.find_element_by_xpath("//select[@id='searchtype']/option[@value='i']").click() search_bar = self.browser.find_element_by_name("searcharg") search_bar.send_keys(isbn) search_bar.send_keys(Keys.ENTER) self.browser.implicitly_wait(3) # book copies from old catalog expand = self.browser.find_elements_by_xpath( "//input[@type='submit'][@value='View additional copies or search for a specific volume/copy']" ) if len(expand) > 0: expand[0].click() self.browser.implicitly_wait(3) oCopies = self.browser.find_elements_by_xpath("//div[@class='additionalCopies']/table//tr") # new catalog may have more resources (online) to pull copies from self.assertTrue(len(nCopies) >= len(oCopies))
def test01_keyword_search_matches_old_catalog(self): # search for and get title of each book in new catalog utils.search_new_catalog_by_keyword(self.browser, "hitchhiker's guide to the galaxy") titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") newTitles = [] for div in titleDivs: newTitles.append(div.find_element_by_xpath("./span/a").text) # search for book in old catalog self.browser.get(utils.nypl_old_catalog) self.browser.implicitly_wait(3) search_bar = self.browser.find_element_by_name("searcharg") search_bar.send_keys("hitchhiker's guide to the galaxy") search_bar.send_keys(Keys.ENTER) self.browser.implicitly_wait(3) # get the old catalog self.browser.get(utils.nypl_old_catalog) self.browser.implicitly_wait(3) # search for HHGTTG search_bar = self.browser.find_element_by_name("searcharg") search_bar.send_keys("hitchhiker's guide to the galaxy") search_bar.send_keys(Keys.ENTER) self.browser.implicitly_wait(3) titleContainers = self.browser.find_elements_by_class_name("briefcitTitle") oldTitles = [] for span in titleContainers: oldTitles.append(span.find_element_by_xpath("./a").text) # the new catalog has more results, but it should at least have # all the results from the old catalog # FAILING self.assertTrue(len(newTitles) >= len(oldTitles), "New catalog has less results than the old catalg. New: " + str(len(newTitles)) + ", Old: " + str(len(oldTitles))) for title in oldTitles: self.assertTrue(title in newTitles, "Could not find " + title + " in the new catalog")
def t_can_get_isbn(self, isbn): utils.search_new_catalog_by_keyword(self.browser, isbn) # we get one results titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Could not retrieve any results based on isbn " + isbn) # result matches our expected title titleDivs[0].find_element_by_xpath("./span/a").click() self.browser.implicitly_wait(3) # that result has the ISBN we searched for additionalInfoDivs = self.browser.find_elements_by_class_name("bibInfoData") addInfo = [] for item in additionalInfoDivs: addInfo.append(item.text) # we can view the isbn foundISBN = False for item in additionalInfoDivs: if isbn in item.text: foundISBN = True self.assertTrue(foundISBN, "Could not retrieve ISBN " + isbn + ".")
def t_keyword_search_for(self, keyword): utils.search_new_catalog_by_keyword(self.browser, keyword) titleDivs = self.browser.find_elements_by_class_name("dpBibTitle") self.assertTrue(len(titleDivs) > 0, "Did not return any results when searching for keyword '" + keyword + "'")