Ejemplo n.º 1
0
def _ensureRestartWithCrashDump(crashFunction: _Callable[[], None]):
    startTime = _datetime.utcnow()
    spy = _nvdaLib.getSpyLib()
    spy.wait_for_specific_speech(
        "Welcome to NVDA")  # ensure the dialog is present
    spy.emulateKeyPress(
        "enter")  # close the dialog so we can check for it after the crash
    crashFunction()
    _process.wait_for_process(_nvdaProcessAlias, timeout="3 sec")
    _process.process_should_be_stopped(_nvdaProcessAlias)
    crashOccurred, crashPath = _blockUntilConditionMet(
        getValue=lambda: _nvdaRobot.check_for_crash_dump(startTime),
        giveUpAfterSeconds=3,
    )
    if not crashOccurred:
        raise AssertionError(
            "A crash.dmp file has not been generated after a crash")
    waitUntilWindowFocused("Welcome to NVDA")
    # prevent test failure by removing the crash dump file
    crashFileDeleted, _crashFileExists = _blockUntilConditionMet(
        getValue=lambda: _attemptFileRemove(crashPath),
        giveUpAfterSeconds=3,
    )
    _opSys.wait_until_removed(crashPath)
    if not crashFileDeleted:
        raise AssertionError("crash.dmp file could not be deleted")
Ejemplo n.º 2
0
def quits_from_keyboard():
	"""Ensure NVDA can be quit from keyboard."""
	spy = _nvdaLib.getSpyLib()
	_builtIn.sleep(1)  # the dialog is not always receiving the enter keypress, wait a little for it

	spy.emulateKeyPress("NVDA+q")
	exitTitleIndex = spy.wait_for_specific_speech("Exit NVDA")

	spy.wait_for_speech_to_finish()
	actualSpeech = spy.get_speech_at_index_until_now(exitTitleIndex)

	_asserts.strings_match(
		actualSpeech,
		"\n".join([
			"Exit NVDA  dialog",
			"What would you like to do?  combo box  Exit  collapsed  Alt plus d"
		])
	)
	_builtIn.sleep(1)  # the dialog is not always receiving the enter keypress, wait a little longer for it
	_builtIn.should_be_true(_nvdaIsRunning(), msg="NVDA is not running")
	spy.emulateKeyPress("enter", blockUntilProcessed=False)  # don't block so NVDA can exit
	_blockUntilConditionMet(
		getValue=lambda: not _nvdaIsRunning(),
		giveUpAfterSeconds=3,
		errorMessage="NVDA failed to exit in the specified timeout"
	)
	_builtIn.should_not_be_true(_nvdaIsRunning(), msg="NVDA is still running")
Ejemplo n.º 3
0
def _ensureRestartWithCrashDump(crashFunction: _Callable[[], None]):
	startTime = _datetime.utcnow()
	spy = _nvdaLib.getSpyLib()
	spy.wait_for_specific_speech("Welcome to NVDA")  # ensure the dialog is present
	spy.emulateKeyPress("enter")  # close the dialog so we can check for it after the crash
	oldMsgWindowHandle = _getNvdaMessageWindowhandle()

	crashFunction()
	_blockUntilConditionMet(
		getValue=lambda: windowWithHandleExists(oldMsgWindowHandle) is False,
		giveUpAfterSeconds=3,
		errorMessage="Old NVDA is still running"
	)
	_builtIn.should_not_be_true(
		windowWithHandleExists(oldMsgWindowHandle),
		msg="Old NVDA process is stil running"
	)
	crashOccurred, crashPath = _blockUntilConditionMet(
		getValue=lambda: _nvdaRobot.check_for_crash_dump(startTime),
		giveUpAfterSeconds=3,
	)
	if not crashOccurred:
		raise AssertionError("A crash.dmp file has not been generated after a crash")
	waitUntilWindowFocused("Welcome to NVDA")
	# prevent test failure by removing the crash dump file
	crashFileDeleted, _crashFileExists = _blockUntilConditionMet(
		getValue=lambda: _attemptFileRemove(crashPath),
		giveUpAfterSeconds=3,
	)
	_opSys.wait_until_removed(crashPath)
	if not crashFileDeleted:
		raise AssertionError("crash.dmp file could not be deleted")
Ejemplo n.º 4
0
    def _focusChrome(self, startsWithTestCaseTitle: re.Pattern):
        """ Ensure chrome started and is focused.
		Different versions of chrome have variations in how the title is presented.
		This may mean that there is a separator between document name and application name.
		E.G. "htmlTest   Google Chrome", "html – Google Chrome" or perhaps no application name at all.
		Rather than try to get this right, just use the doc title.
		If this continues to be unreliable we could use Selenium or similar to start chrome and inform us
		when it is ready.
		"""
        success, _success = _blockUntilConditionMet(
            getValue=lambda: SetForegroundWindow(startsWithTestCaseTitle,
                                                 builtIn.log),
            giveUpAfterSeconds=3,
            intervalBetweenSeconds=0.5)
        if success:
            return
        windowInformation = ""
        try:
            windowInformation = f"Foreground Window: {GetForegroundWindowTitle()}.\n"
            windowInformation += f"Open Windows: {GetVisibleWindowTitles()}"
        except OSError as e:
            builtIn.log(
                f"Couldn't retrieve active window information.\nException: {e}"
            )
        raise AssertionError("Unable to focus Chrome.\n"
                             f"{windowInformation}")
Ejemplo n.º 5
0
    def _connectToRemoteServer(self, connectionTimeoutSecs=10):
        """Connects to the nvdaSpyServer
		Because we do not know how far through the startup NVDA is, we have to poll
		to check that the server is available. Importing the library immediately seems
		to succeed, but then calling a keyword later fails with RuntimeError:
			"Connection to remote server broken: [Errno 10061]
				No connection could be made because the target machine actively refused it"
		Instead we wait until the remote server is available before importing the library and continuing.
		"""

        builtIn.log(
            f"Waiting for {self._spyAlias} to be available at: {self._spyServerURI}",
            level='DEBUG')
        # Importing the 'Remote' library always succeeds, even when a connection can not be made.
        # If that happens, then some 'Remote' keyword will fail at some later point.
        # therefore we use '_testRemoteServer' to ensure that we can in fact connect before proceeding.
        _blockUntilConditionMet(
            getValue=lambda: _testRemoteServer(self._spyServerURI, log=False),
            giveUpAfterSeconds=connectionTimeoutSecs,
            errorMessage=f"Unable to connect to {self._spyAlias}",
        )
        builtIn.log(f"Connecting to {self._spyAlias}", level='DEBUG')
        # If any remote call takes longer than this, the connection will be closed!
        maxRemoteKeywordDurationSeconds = 30
        builtIn.import_library(
            "Remote",  # name of library to import
            # Arguments to construct the library instance:
            f"uri={self._spyServerURI}",
            f"timeout={maxRemoteKeywordDurationSeconds}",
            # Set an alias for the imported library instance
            "WITH NAME",
            self._spyAlias,
        )
        builtIn.log(f"Getting {self._spyAlias} library instance",
                    level='DEBUG')
        self.nvdaSpy = self._addMethodsToSpy(
            builtIn.get_library_instance(self._spyAlias))
        # Ensure that keywords timeout before `timeout` given to `Remote` library,
        # otherwise we lose control over NVDA.
        self.nvdaSpy.init_max_keyword_duration(
            maxSeconds=maxRemoteKeywordDurationSeconds)
Ejemplo n.º 6
0
def NVDA_restarts():
	"""Ensure NVDA can be restarted from keyboard."""
	spy = _nvdaLib.getSpyLib()
	spy.wait_for_specific_speech("Welcome to NVDA")  # ensure the dialog is present.
	spy.wait_for_speech_to_finish()
	# Get handle of the message window for the currently running NVDA
	oldMsgWindowHandle = _getNvdaMessageWindowhandle()
	spy.emulateKeyPress("NVDA+q")
	spy.wait_for_specific_speech("Exit NVDA")

	_builtIn.sleep(0.5)  # the dialog is not always receiving the enter keypress, wait a little longer for it
	spy.emulateKeyPress("downArrow")
	spy.wait_for_specific_speech("Restart")
	spy.emulateKeyPress("enter", blockUntilProcessed=False)  # don't block so NVDA can exit
	_blockUntilConditionMet(
		getValue=lambda: windowWithHandleExists(oldMsgWindowHandle) is False,
		giveUpAfterSeconds=10,
		errorMessage="Old NVDA is still running"
	)
	_builtIn.should_not_be_true(
		windowWithHandleExists(oldMsgWindowHandle),
		msg="Old NVDA process is stil running"
	)
	waitUntilWindowFocused("Welcome to NVDA")
Ejemplo n.º 7
0
	def _focusNotepad(self, startsWithTestCaseTitle: re.Pattern):
		""" Ensure Notepad started and is focused.
		"""
		success, _success = _blockUntilConditionMet(
			getValue=lambda: SetForegroundWindow(startsWithTestCaseTitle, builtIn.log),
			giveUpAfterSeconds=3,
			intervalBetweenSeconds=0.5
		)
		if success:
			return
		windowInformation = ""
		try:
			windowInformation = f"Foreground Window: {GetForegroundWindowTitle()}.\n"
			windowInformation += f"Open Windows: {GetVisibleWindowTitles()}"
		except OSError as e:
			builtIn.log(f"Couldn't retrieve active window information.\nException: {e}")
		raise AssertionError(
			"Unable to focus Notepad.\n"
			f"{windowInformation}"
		)