rinfo / lagrummet_test

Testapplikation för lagrummet.se
0 stars 0 forks source link

Förslag på CasperJS regressiontest - Felsida #8

Closed kamidev closed 8 years ago

kamidev commented 8 years ago

From @lalindqv on February 23, 2015 10:7

Om en felaktig URL anges ska en fin felsida visas: skarmklipp

Testet i Selenium anger en felaktig URl och letar efter texterna "Sidan gick inte att hitta" och "The page could not be found".

Selenium IDE -test ( python):

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re

class Felsida(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "http://change-this-to-the-site-you-are-testing/" self.verificationErrors = [] self.accept_next_alert = True

def test_felsida(self):
    driver = self.driver
    # Försök öppna en sida som inte finns
    driver.get(self.base_url + "/some_non_existing_link_to_test_errorpage")
    try: self.assertEqual("Sidan gick inte att hitta", driver.find_element_by_css_selector("h1").text)
    except AssertionError as e: self.verificationErrors.append(str(e))
    try: self.assertEqual("The page could not be found", driver.find_element_by_xpath("//div[@id='content']/article[2]/header/h1").text)
    except AssertionError as e: self.verificationErrors.append(str(e))

def is_element_present(self, how, what):
    try: self.driver.find_element(by=how, value=what)
    except NoSuchElementException, e: return False
    return True

def is_alert_present(self):
    try: self.driver.switch_to_alert()
    except NoAlertPresentException, e: return False
    return True

def close_alert_and_get_its_text(self):
    try:
        alert = self.driver.switch_to_alert()
        alert_text = alert.text
        if self.accept_next_alert:
            alert.accept()
        else:
            alert.dismiss()
        return alert_text
    finally: self.accept_next_alert = True

def tearDown(self):
    self.driver.quit()
    self.assertEqual([], self.verificationErrors)

if name == "main": unittest.main()

Copied from original issue: rinfo/lagrummet.se#386

kamidev commented 8 years ago

Stänger detta ärende. Se istället ärende #10.