Example #1
0
class WebTester(object):

    """Visits pages in browsers, takes screenshots."""

    def __init__(self, tests, report_name):
        """constructor.

        @param tests (list) : WebTest namedtuples
        @param report_name (str) : name for the report. Used in filename.

        """
        self._tests = tests
        self._results = WebTestResults()
        self._report_name = report_name

    def start(self):
        """run the tests."""
        for test in self._tests:
            self.run_test(test)
        self._results.write_to_file(self._report_name)

    def run_test(self, test):
        """run test.

        @param test (WebTest) : webtest namedtuple

        """
        driver = webdriver.Remote(test.browser_node_uri,
                                  test.browser_selenium_spec)
        for resource in test.resources_to_test:
            driver.get('http://www.google.com')
            t = datetime.datetime.now()
            driver.get(resource)
            t = str(datetime.datetime.now() - t)
            time.sleep(5)
            fn = tempfile.mkstemp(suffix='.png')[1]
            driver.get_screenshot_as_file(fn)
            time.sleep(5)
            heading = '{} Test'.format(resource)
            ver = driver.capabilities['version']
            plat = driver.capabilities['platform']
            text = 'Browser: {}\nVersion: {}\nPlatform: {}\nWait: {}\n'
            text = text.format(test.browser_name, ver, plat, t)
            self._results.add_section(heading, text, fn)
        driver.quit()
Example #2
0
    def __init__(self, tests, report_name):
        """constructor.

        @param tests (list) : WebTest namedtuples
        @param report_name (str) : name for the report. Used in filename.

        """
        self._tests = tests
        self._results = WebTestResults()
        self._report_name = report_name
class TestWebTestResults(unittest.TestCase):

    """Test class."""

    def setUp(self):
        """Set up the test."""
        self.driver = webdriver.Firefox()
        self.test_results = WebTestResults()

    def test_web_test_results_build_report(self):
        """run a simple report."""
        t = datetime.datetime.now()
        self.driver.get(TEST_DOMAIN)
        t = str(datetime.datetime.now() - t)
        fn = tempfile.mkstemp(suffix='.png')[1]
        self.driver.get_screenshot_as_file(fn)
        heading = "Firefox Google Test"
        ver = self.driver.capabilities['version']
        plat = self.driver.capabilities['platform']
        text = 'version: {}\nplatform: {}\nwait: {}\n'.format(ver, plat, t)
        self.test_results.add_section(heading, text, fn)
        fn = tempfile.mkstemp(suffix='.pdf')[1]
        self.test_results.write_to_file(fn)
        self.driver.quit()
Example #4
0
 def test_getting_ie_image_pdf(self):
     driver = webdriver.Remote(TEST_REMOTE, IE)
     driver.get('http://google.com')
     inputElement = driver.find_element_by_name('q')
     inputElement.send_keys('cheese!')
     inputElement.submit()
     time.sleep(10)
     x = StringIO.StringIO(driver.get_screenshot_as_png())
     x.seek(0)
     img = PIL.Image.open(x)
     img.save(self.imgfilename, dpi=(300, 300))
     browser_name = driver.name
     caps = str(driver.capabilities)
     descaps = str(driver.desired_capabilities)
     cds = caps + '\n\n\n' + descaps
     driver.quit()
     results = WebTestResults()
     results.add_test_section_header(browser_name, cds)
     results.add_img_from_file(self.imgfilename)
     results.write_to_file('test.pdf')
 def setUp(self):
     """Set up the test."""
     self.driver = webdriver.Firefox()
     self.test_results = WebTestResults()