def testSwissSearchParameter(driver, url, inputEl, searchTest, timeout=10): searchText = searchTest['searchText'] oneResOnly = searchTest['oneResOnly'] resultTitle = searchTest['resultTitle'] resultLocation = searchTest['resultLocation'] targetUrl = url + '?lang=de&swisssearch=%s' % searchText driver.get(targetUrl) # One result only -> zoom to the desired location if oneResOnly: if waitForUrlChange(driver, resultLocation): onLocationFail(driver.current_url, searchText, resultLocation) try: assert "swisssearch" in driver.current_url except AssertionError as e: raise Exception(e) # parameter (swisssearch) is removed by map action (simulating zoom) driver.find_element_by_css_selector("button.ol-zoom-out").click() else: selectLocationItem(driver, inputEl, searchText, resultTitle, resultLocation) if waitForUrlChange(driver, 'swisssearch', find=False): print 'swissearch param can still be found in the URL after a map move' sys.exit(1) print 'SwissSearch parameter test for %s OK!' % searchText
def runSearchTest(driver, url): print 'Search_test starts!' driver.get(url) driver.maximize_window() driver.get(url + '/?lang=de') # Send "Bern" to the searchbar driver.find_element_by_xpath("//*[@type='search']").send_keys("Bern") # Click on the field "Bern (BE)" driver.find_element_by_xpath("//*[contains(text(), 'Bern')]").click() if bCheckIfUrlHasChanged(driver): # Was the URL in the address bar adapted? current_url = driver.current_url try: bCheckIfLinkIsUpdatedEverywhere(driver, QUERYSTRING_OF_BERN) except: try: # Wait refresh URL waitForUrlChange(driver, current_url) except Exception as e: print str(e) raise Exception('URL has not changed') try: bCheckIfLinkIsUpdatedEverywhere(driver, QUERYSTRING_OF_BERN) except AssertionError as e: print str(e) raise Exception("Coordinate of raron is not set in the url") print 'Search_test completed'
def runMobileTest(driver, target, is_top_browser): print "Start Mobile tests" target_url = target + '?lang=de' driver.get(target_url) # wait until the page is loaded. We know this when the title contain # (S)chweiz try: WebDriverWait(driver, 10).until(EC.title_contains('chweiz')) except Exception as e: print '-----------' print str(e) raise Exception("Unable to load map.geo.admin page!") current_url = driver.current_url # Switch to Mobile Version driver.find_element_by_link_text("Mobile Version").click() try: waitForUrlChange(driver, current_url) # Rem : mobile.html is replace by index.tml except Exception as e: print '-----------' print str(e) print "Current url: " + current_url raise Exception("Mobile version not loaded !") # Zoom-in driver.find_element_by_css_selector("button.ol-zoom-in").click() if waitForUrlChange(driver, QUERYSTRING_WHEN_ZOOM_IN): print 'Mobile: expected pattern %s was not found after a zoom in' % QUERYSTRING_WHEN_ZOOM_IN sys.exit(1) # Make a search driver.find_element_by_xpath("//input[@type='search']").clear() driver.find_element_by_xpath( "//input[@type='search']").send_keys("Avenches") driver.find_element_by_css_selector("span.ga-search-highlight").click() if waitForUrlChange(driver, QUERYSTRING_OF_AVENCHES): print 'Mobile: expected pattern %s was not found after a search' % QUERYSTRING_OF_AVENCHES sys.exit(1) # Check result search of 'wasser'. Must return locations (Gehe nach) and # layers (Karte hinzufügen) driver.find_element_by_xpath("//input[@type='search']").clear() driver.find_element_by_xpath("//*[@type='search']").send_keys("wasser") # Check if result contain data and layer driver.find_element_by_xpath("//*[contains(text(), 'Gehe nach')]") driver.find_element_by_xpath("//*[contains(text(), 'Karte hinzufügen')]") print "Mobile tests Ok !"
def selectLocationItem(driver, inputEl, searchText, resultTitle, resultLocation): searchResultEls = driver.find_elements_by_class_name(itemClass) for resultEl in searchResultEls: if resultTitle == resultEl.get_attribute('title'): resultEl.click() break # Make sure map is zoomed to the desired location if waitForUrlChange(driver, resultLocation): onLocationFail(driver.current_url, searchText, resultLocation)
def selectLayerInputItem(driver, inputEl, searchText, resultTitle, layerId): searchResultEls = driver.find_elements_by_class_name(itemClass) for resultEl in searchResultEls: if resultTitle == resultEl.get_attribute('title'): resultEl.click() break # Make sure map is zoomed to the desired location if waitForUrlChange(driver, layerId): print '%s layer cannot be found in the permalink' % layerId sys.exit(1)
def runMobileTest(driver, target): print "Start Mobile tests" target_url = target + '?lang=de' driver.get(target_url) # wait until the page is loaded. We know this when the title contain # (S)chweiz try: WebDriverWait(driver, 10).until(EC.title_contains('chweiz')) except Exception as e: print '-----------' print str(e) raise Exception("Unable to load map.geo.admin page!") current_url = driver.current_url # Switch to Mobile Version driver.find_element_by_link_text("Mobile Version").click() try: waitForUrlChange(driver, current_url) # Rem : mobile.html is replace by index.tml except Exception as e: print '-----------' print str(e) print "Current url: " + current_url raise Exception("Mobile version not loaded !") # Zoom-in driver.find_element_by_css_selector("button.ol-zoom-in").click() current_url = driver.current_url try: assert QUERYSTRING_WHEN_ZOOM_IN in current_url except Exception as e: # Wait refresh URL try: waitForUrlChange(driver, current_url) except Exception as e: print '-----------' print str(e) raise Exception('URL has not changed') try: assert QUERYSTRING_WHEN_ZOOM_IN in driver.current_url except AssertionError as e: print '-----------' print str(e) raise Exception("Zoom click not set in the url") # Check if the zoom in click update the url assert QUERYSTRING_WHEN_ZOOM_IN in driver.current_url # Make a search driver.find_element_by_xpath("//input[@type='search']").clear() driver.find_element_by_xpath( "//input[@type='search']").send_keys("Avenches") driver.find_element_by_css_selector("span.ga-search-highlight").click() current_url = driver.current_url try: assert QUERYSTRING_OF_AVENCHES in current_url except Exception as e: # Wait refresh URL try: waitForUrlChange(driver, current_url) except Exception as e: print '-----------' print str(e) raise Exception("Coordinate of Avenches is not set in the url") # Check if url contain coordinate of avenches assert QUERYSTRING_OF_AVENCHES in driver.current_url # Check result search of 'wasser'. Must return locations (Gehe nach) and # layers (Karte hinzufügen) driver.find_element_by_xpath("//input[@type='search']").clear() driver.find_element_by_xpath("//*[@type='search']").send_keys("wasser") # Check if result contain data and layer driver.find_element_by_xpath("//*[contains(text(), 'Gehe nach')]") driver.find_element_by_xpath("//*[contains(text(), 'Karte hinzufügen')]") print "Mobile test Ok !"