def _RunPage(test, page, tab, expectation, results, options): logging.info('Running %s' % page.url) page_state = PageState() try: page_state.PreparePage(page, tab, test) test.Run(options, page, tab, results) util.CloseConnections(tab) except page_test.Failure: logging.warning('%s:\n%s', page.url, traceback.format_exc()) if expectation == 'fail': logging.info('Failure was expected\n') results.AddSuccess(page) else: results.AddFailure(page, sys.exc_info()) except (util.TimeoutException, exceptions.LoginException, exceptions.ProfilingException): logging.error('%s:\n%s', page.url, traceback.format_exc()) results.AddError(page, sys.exc_info()) except (exceptions.TabCrashException, exceptions.BrowserGoneException): logging.error('%s:\n%s', page.url, traceback.format_exc()) results.AddError(page, sys.exc_info()) # Run() catches these exceptions to relaunch the tab/browser, so re-raise. raise except Exception: raise else: if expectation == 'fail': logging.warning('%s was expected to fail, but passed.\n', page.url) results.AddSuccess(page) finally: page_state.CleanUpPage(page, tab)
def _RunPage(test, page, tab, results, options): if not test.CanRunForPage(page): logging.warning('Skipping test: it cannot run for %s', page.url) results.AddSkip(page, 'Test cannot run') return logging.info('Running %s' % page.url) page_state = PageState() try: page_state.PreparePage(page, tab, test) test.Run(options, page, tab, results) util.CloseConnections(tab) except page_test.Failure: logging.warning('%s:\n%s', page.url, traceback.format_exc()) results.AddFailure(page, sys.exc_info()) except (util.TimeoutException, exceptions.LoginException): logging.error('%s:\n%s', page.url, traceback.format_exc()) results.AddError(page, sys.exc_info()) except (exceptions.TabCrashException, exceptions.BrowserGoneException): logging.error('%s:\n%s', page.url, traceback.format_exc()) results.AddError(page, sys.exc_info()) # Run() catches these exceptions to relaunch the tab/browser, so re-raise. raise except Exception: raise else: results.AddSuccess(page) finally: page_state.CleanUpPage(page, tab)
def _RunPage(test, page, state, expectation, results, finder_options): if expectation == 'skip': logging.debug('Skipping test: Skip expectation for %s', page.url) results.AddSkip(page, 'Skipped by test expectations') return logging.info('Running %s' % page.url) page_state = PageState(page, test.TabForPage(page, state.browser)) def ProcessError(): logging.error('%s:', page.url) exception_formatter.PrintFormattedException() if expectation == 'fail': logging.info('Error was expected\n') results.AddSuccess(page) else: results.AddError(page, sys.exc_info()) try: page_state.PreparePage(test) if state.repeat_state.ShouldNavigate( finder_options.skip_navigate_on_repeat): page_state.ImplicitPageNavigation(test) test.RunPage(page, page_state.tab, results) util.CloseConnections(page_state.tab) except page_test.TestNotSupportedOnPlatformFailure: raise except page_test.Failure: if expectation == 'fail': logging.info('%s:', page.url) exception_formatter.PrintFormattedException() logging.info('Failure was expected\n') results.AddSuccess(page) else: logging.warning('%s:', page.url) exception_formatter.PrintFormattedException() results.AddFailure(page, sys.exc_info()) except (util.TimeoutException, exceptions.LoginException, exceptions.ProfilingException): ProcessError() except (exceptions.TabCrashException, exceptions.BrowserGoneException): ProcessError() # Run() catches these exceptions to relaunch the tab/browser, so re-raise. raise except page_action.PageActionNotSupported as e: results.AddSkip(page, 'Unsupported page action: %s' % e) except Exception: logging.warning('While running %s', page.url) exception_formatter.PrintFormattedException() results.AddFailure(page, sys.exc_info()) else: if expectation == 'fail': logging.warning('%s was expected to fail, but passed.\n', page.url) results.AddSuccess(page) finally: page_state.CleanUpPage(test)
def DidRunUserStory(self, results): if self._finder_options.profiler: self._StopProfiling(results) util.CloseConnections(self._current_tab) self._test.CleanUpAfterPage(self._current_page, self._current_tab) if self._current_page.credentials and self._did_login_for_current_page: self.browser.credentials.LoginNoLongerNeeded( self._current_tab, self._current_page.credentials) if self._test.StopBrowserAfterPage(self.browser, self._current_page): self._StopBrowser() self._current_page = None self._current_tab = None
def _RunPage(test, page, state, expectation, results): if expectation == 'skip': logging.debug('Skipping test: Skip expectation for %s', page.url) results.AddValue(skip.SkipValue(page, 'Skipped by test expectations')) return logging.info('Running %s', page.url) page_state = PageState(page, test.TabForPage(page, state.browser)) def ProcessError(): if expectation == 'fail': msg = 'Expected exception while running %s' % page.url else: msg = 'Exception while running %s' % page.url results.AddValue(failure.FailureValue(page, sys.exc_info())) exception_formatter.PrintFormattedException(msg=msg) try: page_state.PreparePage(test) page_state.ImplicitPageNavigation(test) test.RunPage(page, page_state.tab, results) util.CloseConnections(page_state.tab) except page_test.TestNotSupportedOnPlatformFailure: raise except page_test.Failure: if expectation == 'fail': exception_formatter.PrintFormattedException( msg='Expected failure while running %s' % page.url) else: exception_formatter.PrintFormattedException( msg='Failure while running %s' % page.url) results.AddValue(failure.FailureValue(page, sys.exc_info())) except (util.TimeoutException, exceptions.LoginException, exceptions.ProfilingException): ProcessError() except (exceptions.TabCrashException, exceptions.BrowserGoneException): ProcessError() # Run() catches these exceptions to relaunch the tab/browser, so re-raise. raise except page_action.PageActionNotSupported as e: results.AddValue( skip.SkipValue(page, 'Unsupported page action: %s' % e)) except Exception: exception_formatter.PrintFormattedException( msg='Unhandled exception while running %s' % page.url) results.AddValue(failure.FailureValue(page, sys.exc_info())) else: if expectation == 'fail': logging.warning('%s was expected to fail, but passed.\n', page.url) finally: page_state.CleanUpPage(test)
def _RunPage(test, page, state, expectation, results, finder_options): if expectation == 'skip': logging.info('Skipped %s' % page.url) return logging.info('Running %s' % page.url) page_state = PageState(page, test.TabForPage(page, state.browser)) page_action.PageAction.ResetNextTimelineMarkerId() def ProcessError(): logging.error('%s:\n%s', page.url, traceback.format_exc()) if expectation == 'fail': logging.info('Error was expected\n') results.AddSuccess(page) else: results.AddError(page, sys.exc_info()) try: page_state.PreparePage(test) if state.repeat_state.ShouldNavigate( finder_options.skip_navigate_on_repeat): page_state.ImplicitPageNavigation(test) test.Run(finder_options, page, page_state.tab, results) util.CloseConnections(page_state.tab) except page_test.Failure: if expectation == 'fail': logging.info('%s:\n%s', page.url, traceback.format_exc()) logging.info('Failure was expected\n') results.AddSuccess(page) else: logging.warning('%s:\n%s', page.url, traceback.format_exc()) results.AddFailure(page, sys.exc_info()) except (util.TimeoutException, exceptions.LoginException, exceptions.ProfilingException): ProcessError() except (exceptions.TabCrashException, exceptions.BrowserGoneException): ProcessError() # Run() catches these exceptions to relaunch the tab/browser, so re-raise. raise except Exception: logging.warning('While running %s', page.url) exception_formatter.PrintFormattedException(*sys.exc_info()) results.AddFailure(page, sys.exc_info()) else: if expectation == 'fail': logging.warning('%s was expected to fail, but passed.\n', page.url) results.AddSuccess(page) finally: page_state.CleanUpPage()
def _RunCompoundAction(self, page, tab, actions): for i, action in enumerate(actions): prev_action = actions[i - 1] if i > 0 else None next_action = actions[i + 1] if i < len(actions) - 1 else None if (action.RunsPreviousAction() and next_action and next_action.RunsPreviousAction()): raise page_action.PageActionFailed( 'Consecutive actions cannot both ' 'have RunsPreviousAction() == True.') if not (next_action and next_action.RunsPreviousAction()): action.WillRunAction(page, tab) self.WillRunAction(page, tab, action) try: action.RunAction(page, tab, prev_action) finally: self.DidRunAction(page, tab, action) # Closing the connections periodically is needed; otherwise we won't be # able to open enough sockets, and the pages will time out. util.CloseConnections(tab)