Ejemplo n.º 1
0
    def run(self):
        super(PageTest, self).run()
        logger.write( u"url: {0}".format(html.link(self.url, self.url)) )

        ## check status code
        assert self.status == self.response.status, u"HTTP Response status expected {0}, recieved {1}".format(self.status, self.response.status)

        ## check title & header
        if not (self.title_xpath == None) and not (self.title == None) :
            assert_xpath_content( self.webpage, self.title_xpath, self.title )

        if not (self.h1_xpath == None) and not (self.h1 == None) :
            assert_xpath_content( self.webpage, self.h1_xpath, self.h1 )

        # text present merge
        if not self.texts_present is None :
            for ( xpath, text ) in self.texts_present :
                txt = self.webpage.find_element_by_xpath(xpath).text
                assert text in txt, u"Text '{0}' not found, present '{1}'".format(text, txt)

        # text count merge
        if not self.texts_count is None :
            for item in self.texts_count :
                count = self.webpage.page_source.count( item[0] )
                if item[1] == u'<' :
                    assert count < item[2],\
                    u"Text '{0}' occurs {1} times >= {2}".format( item[0], count, item[2] )
                if item[1] == u'=' :
                    assert count == item[2],\
                    u"Text '{0}' occurs {1} times != {2}".format( item[0], count, item[2] )
                if item[1] == u'>' :
                    assert count > item[2],\
                    u"Text '{0}' occurs {1} times <= {2}".format( item[0], count, item[2] )

                if item[1] == u'<=' :
                    assert count <= item[2],\
                    u"Text '{0}' occurs {1} times > {2}".format( item[0], count, item[2] )
                if item[1] == u'>=' :
                    assert count >= item[2],\
                    u"Text '{0}' occurs {1} times < {2}".format( item[0], count, item[2] )

        # execute sub tests
        for subtest in self.subtests :
            logger.write( u"Running test '{0}' of '{1}'".format( subtest.__doc__.decode("utf-8"), self.__doc__.decode("utf-8") ) )
            with logger.current_test( subtest ) :
                with browser.current_screenshot_dir( subtest.artifactsDir() ) :
                    try :
                        subtest.setUp( self.webpage )
                        subtest.run()
                        status = 'success'
                    except Exception as s :
                        status = 'fail'
                        logger.write( u"Error: {0}".format(s) )
                        snapshot()
                        raise SubTestFail( subtest.__doc__.decode("utf-8") )
                    finally:
                        subtest.tearDown()
                        logger.set_status( status )
                        logger.write( html.status_label( status ) )
                        logger.save_test_result()
Ejemplo n.º 2
0
    def run(self):
        super(RedirectTest, self).run()

        for (from_url, redirect_status, dest_url, dest_status) in self.redirects :

            parsed_url = urlparse( from_url )
            conn = httplib.HTTPConnection( parsed_url.netloc )
            conn.request( "HEAD", parsed_url.path.encode('utf-8') )
            from_response = conn.getresponse()

            assert from_response.status == redirect_status, \
            u"При посещении страницы {0}, ожидался {1} переход на страницу {2}, но получен статус {3}".\
            format( html.link(from_url,from_url), redirect_status, html.link( dest_url, dest_url ), from_response.status )

            loc = from_response.getheader('location').decode('utf-8')

            assert loc == dest_url, \
            u"При посещении страницы {0}, ожидался {1} переход на страницу {2}, но редирект перевел на страницу {3}".\
            format( html.link(from_url,from_url), redirect_status, html.link( dest_url, dest_url ), html.link( loc, loc ) )

            parsed_url2 = urlparse( loc )
            conn2 = httplib.HTTPConnection( parsed_url2.netloc )
            conn2.request( "HEAD", parsed_url2.path.encode('utf-8') )
            dest_response = conn2.getresponse()

            assert dest_response.status == dest_status,\
            u"При посещении страницы {0}, ожидался {1} переход на страницу {2} со статусом {3}, но получен статус {4}".\
            format( html.link(from_url,from_url), redirect_status, html.link( dest_url, dest_url ), dest_status, dest_response.status )