diff --git a/test/campaigntest.py b/test/campaigntest.py index f486d8b6..0bf3fa0e 100644 --- a/test/campaigntest.py +++ b/test/campaigntest.py @@ -3,6 +3,21 @@ from regluit.payment.models import Transaction, PaymentResponse, Receiver from regluit.payment.manager import PaymentManager from regluit.payment.paypal import IPN_PAY_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE, IPN_PAY_STATUS_COMPLETED +import logging + + +def set_test_logging(): + + # Setup debug logging to our console so we can watch + defaultLogger = logging.getLogger('') + defaultLogger.addHandler(logging.StreamHandler()) + defaultLogger.setLevel(logging.DEBUG) + + # Set the selenium logger to info + sel = logging.getLogger("selenium") + sel.setLevel(logging.INFO) + + def run_google_rc(): from selenium import selenium @@ -30,7 +45,49 @@ def run_google_rc(): testcases = [google_rc] suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases]) unittest.TextTestRunner().run(suites) - + +def run_google_wd(): + """ + A google example using WebDriver + """ + + from selenium import selenium, webdriver + from selenium.common.exceptions import NoSuchElementException + import unittest, time, re + + class GoogleWebDriverTest(unittest.TestCase): + + def setUp(self): + self.verificationErrors = [] + # This is an empty array where we will store any verification errors + # we find in our tests + + self.selenium = webdriver.Firefox() + set_test_logging() + + def test_google_rc(self): + sel = self.selenium + sel.get("https://www.google.com/") + search_box = sel.find_elements_by_xpath("//input[@type='text']") + search_box[0].send_keys("Bach") + search_box[0].submit() + time.sleep(3) + try: + sel.find_element_by_xpath("//a[contains(@href,'wikipedia')]") + except NoSuchElementException, e: + self.verificationErrors.append(str(e)) + #try: self.failUnless(sel.is_text_present("Wikipedia")) + #except AssertionError, e: self.verificationErrors.append(str(e)) + + def tearDown(self): + self.selenium.quit() + self.assertEqual([], self.verificationErrors) + + testcases = [GoogleWebDriverTest] + suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases]) + unittest.TextTestRunner().run(suites) + + # from selenium import webdriver # driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS) # driver.get("http://google.com")