示例#1
0
 def teardown_nvda_profile(self):
     builtIn.log("Removing files from NVDA profile")
     opSys.remove_file(_pJoin(nvdaProfileWorkingDir, "nvda.ini"))
     opSys.remove_directory(testSpyPackageDest, recursive=True)
     opSys.remove_file(
         _pJoin(nvdaProfileWorkingDir, "scratchpad", "synthDrivers",
                "speechSpy.py"))
示例#2
0
文件: NvdaLib.py 项目: bocoup/nvda
    def __init__(self):
        # robot is expected to be run from the NVDA repo root directory. We want all repo specific
        # paths to be relative to this. This would allow us to change where it is run from if we decided to.
        self.repoRoot = _abspath("./")
        self.stagingDir = _tempFile.gettempdir()
        opSys.directory_should_exist(self.stagingDir)

        self.whichNVDA = builtIn.get_variable_value("${whichNVDA}", "source")
        self._installFilePath = builtIn.get_variable_value(
            "${installDir}", None)
        self.NVDAInstallerCommandline = None
        if self.whichNVDA == "source":
            self._runNVDAFilePath = _pJoin(self.repoRoot, "runnvda.bat")
            self.baseNVDACommandline = self._runNVDAFilePath
        elif self.whichNVDA == "installed":
            self._runNVDAFilePath = self.findInstalledNVDAPath()
            self.baseNVDACommandline = f'"{str(self._runNVDAFilePath)}"'
            if self._installFilePath is not None:
                self.NVDAInstallerCommandline = f'"{str(self._installFilePath)}"'
        else:
            raise AssertionError(
                "RobotFramework should be run with argument: '-v whichNVDA:[source|installed]'"
            )

        self.profileDir = _pJoin(self.stagingDir, "nvdaProfile")
        self.logPath = _pJoin(self.profileDir, 'nvda.log')
        self.preservedLogsDir = _pJoin(
            builtIn.get_variable_value("${OUTPUT DIR}"), "nvdaTestRunLogs")
示例#3
0
def _findDepPath(depFileName, searchPaths):
	import os
	for path in searchPaths:
		filePath = _pJoin(path, depFileName+".py")
		if os.path.isfile(filePath):
			return filePath
		elif os.path.isfile(_pJoin(path, depFileName, "__init__.py")):
			return _pJoin(path, depFileName)
	raise AssertionError("Unable to find required system test spy dependency: {}".format(depFileName))
示例#4
0
def _findDepPath(depFileName, searchPaths):
	import os
	for path in searchPaths:
		filePath = _pJoin(path, f"{depFileName}.py")
		if os.path.isfile(filePath):
			return filePath
		elif os.path.isfile(_pJoin(path, depFileName, "__init__.py")):
			return _pJoin(path, depFileName)
	raise AssertionError("Unable to find required system test spy dependency: {}".format(depFileName))
示例#5
0
def setupProfile(repoRoot: str, settingsFileName: str, stagingDir: str):
    builtIn.log("Copying files into NVDA profile", level='DEBUG')
    opSys.copy_file(
        # Despite duplication, specify full paths for clarity.
        _pJoin(repoRoot, "tests", "system", "nvdaSettingsFiles",
               settingsFileName),
        _pJoin(stagingDir, "nvdaProfile", "nvda.ini"))
    # create a package to use as the globalPlugin
    _installSystemTestSpyToScratchPad(
        repoRoot, _pJoin(stagingDir, "nvdaProfile", "scratchpad"))
示例#6
0
	def findInstalledNVDAPath(self) -> Optional[str]:
		NVDAFilePath = _pJoin(_expandvars('%PROGRAMFILES%'), 'nvda', 'nvda.exe')
		legacyNVDAFilePath = _pJoin(_expandvars('%PROGRAMFILES%'), 'NVDA', 'nvda.exe')
		exeErrorMsg = f"Unable to find installed NVDA exe. Paths tried: {NVDAFilePath}, {legacyNVDAFilePath}"
		try:
			opSys.file_should_exist(NVDAFilePath)
			return NVDAFilePath
		except AssertionError:
			# Older versions of NVDA (<=2020.4) install the exe in NVDA\nvda.exe
			opSys.file_should_exist(legacyNVDAFilePath, exeErrorMsg)
			return legacyNVDAFilePath
示例#7
0
	def teardown_nvda_profile(self):
		builtIn.log("Removing files from NVDA profile")
		opSys.remove_file(
			_pJoin(nvdaProfileWorkingDir, "nvda.ini")
		)
		opSys.remove_directory(
			testSpyPackageDest,
			recursive=True
		)
		opSys.remove_file(
			_pJoin(nvdaProfileWorkingDir, "scratchpad", "synthDrivers", "speechSpy.py")
		)
示例#8
0
 def setup_nvda_profile(self, settingsFileName):
     builtIn.log("Copying files into NVDA profile")
     opSys.copy_file(
         _pJoin(systemTestSourceDir, "nvdaSettingsFiles", settingsFileName),
         _pJoin(nvdaProfileWorkingDir, "nvda.ini"))
     # create a package to use as the globalPlugin
     opSys.move_directory(
         _createNvdaSpyPackage(),
         _pJoin(testSpyPackageDest, systemTestSpyAddonName))
     # install the test spy speech synth
     opSys.copy_file(
         _pJoin(systemTestSourceDir, "libraries", "speechSpy.py"),
         _pJoin(nvdaProfileWorkingDir, "synthDrivers", "speechSpy.py"))
示例#9
0
	def setup_nvda_profile(self, settingsFileName):
		builtIn.log("Copying files into NVDA profile")
		opSys.copy_file(
			_pJoin(systemTestSourceDir, "nvdaSettingsFiles", settingsFileName),
			_pJoin(nvdaProfileWorkingDir, "nvda.ini")
		)
		# create a package to use as the globalPlugin
		opSys.move_directory(
			_createNvdaSpyPackage(),
			_pJoin(testSpyPackageDest, systemTestSpyAddonName)
		)
		# install the test spy speech synth
		opSys.copy_file(
			_pJoin(systemTestSourceDir, "libraries", "speechSpy.py"),
			_pJoin(nvdaProfileWorkingDir, "scratchpad", "synthDrivers", "speechSpy.py")
		)
示例#10
0
 def save_NVDA_log(self):
     """NVDA logs are saved to the ${OUTPUT DIR}/nvdaTestRunLogs/${SUITE NAME}-${TEST NAME}-nvda.log"""
     builtIn.log("saving NVDA log")
     opSys.create_directory(testOutputNvdaLogsDir)
     opSys.copy_file(
         nvdaLogFilePath,
         _pJoin(testOutputNvdaLogsDir, _createTestIdFileName("nvda.log")))
示例#11
0
def teardownProfile(stagingDir: str):
    """ Cleans up the profile directory
	@todo: this could have an option to preserve the profile for debugging purposes.
	@param stagingDir: Where the profile was constructed
	"""
    builtIn.log("Cleaning up NVDA profile", level='DEBUG')
    opSys.remove_directory(_pJoin(stagingDir, "nvdaProfile"), recursive=True)
示例#12
0
	def save_NVDA_log(self):
		"""NVDA logs are saved to the ${OUTPUT DIR}/nvdaTestRunLogs/${SUITE NAME}-${TEST NAME}-nvda.log"""
		builtIn.log("saving NVDA log")
		opSys.create_directory(testOutputNvdaLogsDir)
		opSys.copy_file(
			nvdaLogFilePath,
			_pJoin(testOutputNvdaLogsDir, _createTestIdFileName("nvda.log"))
		)
示例#13
0
def _installSystemTestSpyToScratchPad(repoRoot: str, scratchPadDir: str):
    """ Assembles the required files for the system test spy.
	Most notably this includes:
	- speechSpyGlobalPlugin - The actual remote Robot library used to get information out of NVDA
	- speechSpySynthDriver - A synth driver that captures and caches speech to provide to speechSpyGlobalPlugin
	"""

    # The globalPlugin will modify the python path to include to this sub dir
    spyPackageLibsDir = _pJoin(scratchPadDir, "globalPlugins",
                               "speechSpyGlobalPlugin", "libs")
    opSys.create_directory(spyPackageLibsDir)
    # copy in required dependencies for global plugin
    _copyPythonLibs(
        pythonImports=[  # relative to the python path
            r"robotremoteserver",
        ],
        libsDest=spyPackageLibsDir)
    # install the global plugin
    # Despite duplication, specify full paths for clarity.
    opSys.copy_file(
        _pJoin(repoRoot, "tests", "system", "libraries", "SystemTestSpy",
               "speechSpyGlobalPlugin.py"),
        _pJoin(scratchPadDir, "globalPlugins", "speechSpyGlobalPlugin",
               "__init__.py"))
    opSys.copy_file(
        _pJoin(repoRoot, "tests", "system", "libraries", "SystemTestSpy",
               "blockUntilConditionMet.py"),
        _pJoin(scratchPadDir, "globalPlugins", "speechSpyGlobalPlugin"))
    # install the test spy speech synth
    opSys.copy_file(
        _pJoin(repoRoot, "tests", "system", "libraries", "SystemTestSpy",
               "speechSpySynthDriver.py"),
        _pJoin(scratchPadDir, "synthDrivers", "speechSpySynthDriver.py"))
示例#14
0
	def _startNVDAProcess(self):
		"""Start NVDA.
		Use debug logging, replacing any current instance, using the system test profile directory
		"""
		opSys.create_directory(testOutputNvdaLogsDir)
		opSys.file_should_exist(NVDACommandPathToCheckExists, "Unable to start NVDA unless path exists.")
		self.nvdaHandle = handle = process.start_process(
			"{baseNVDACommandline} --debug-logging -r -c \"{nvdaProfileDir}\" --log-file \"{nvdaLogFilePath}\"".format(
				baseNVDACommandline=baseNVDACommandline,
				nvdaProfileDir=nvdaProfileWorkingDir,
				nvdaLogFilePath=nvdaLogFilePath
			),
			shell=True,
			alias='nvdaAlias',
			stdout=_pJoin(testOutputNvdaLogsDir, _createTestIdFileName("stdout.txt")),
			stderr=_pJoin(testOutputNvdaLogsDir, _createTestIdFileName("stderr.txt")),
		)
		return handle
示例#15
0
	def save_NVDA_log(self):
		"""NVDA logs are saved to the ${OUTPUT DIR}/nvdaTestRunLogs/${SUITE NAME}-${TEST NAME}-nvda.log"""
		builtIn.log("Saving NVDA log")
		saveToPath = _pJoin(_locations.preservedLogsDir, self._createTestIdFileName("nvda.log"))
		opSys.copy_file(
			_locations.logPath,
			saveToPath
		)
		builtIn.log(f"Log saved to: {saveToPath}", level='DEBUG')
示例#16
0
	def _startNVDAProcess(self):
		"""Start NVDA.
		Use debug logging, replacing any current instance, using the system test profile directory
		"""
		opSys.create_directory(testOutputNvdaLogsDir)
		opSys.file_should_exist(NVDACommandPathToCheckExists, "Unable to start NVDA unless path exists.")
		self.nvdaHandle = handle = process.start_process(
			"{baseNVDACommandline} --debug-logging -r -c \"{nvdaProfileDir}\" --log-file \"{nvdaLogFilePath}\"".format(
				baseNVDACommandline=baseNVDACommandline,
				nvdaProfileDir=nvdaProfileWorkingDir,
				nvdaLogFilePath=nvdaLogFilePath
			),
			shell=True,
			alias='nvdaAlias',
			stdout=_pJoin(testOutputNvdaLogsDir, _createTestIdFileName("stdout.txt")),
			stderr=_pJoin(testOutputNvdaLogsDir, _createTestIdFileName("stderr.txt")),
		)
		return handle
示例#17
0
文件: NvdaLib.py 项目: bocoup/nvda
    def _startNVDAInstallerProcess(self):
        """Start NVDA Installer.
		Use debug logging, replacing any current instance, using the system test profile directory
		"""
        _locations.ensureInstallerPathsExist()
        command = (f"{_locations.NVDAInstallerCommandline}"
                   f" --debug-logging"
                   f" -r"
                   f" -c \"{_locations.profileDir}\""
                   f" --log-file \"{_locations.logPath}\"")
        self.nvdaHandle = handle = process.start_process(
            command,
            shell=True,
            alias=self.nvdaProcessAlias,
            stdout=_pJoin(_locations.preservedLogsDir,
                          self._createTestIdFileName("stdout.txt")),
            stderr=_pJoin(_locations.preservedLogsDir,
                          self._createTestIdFileName("stderr.txt")),
        )
        return handle
示例#18
0
	def __init__(self):
		# robot is expected to be run from the NVDA repo root directory. We want all repo specific
		# paths to be relative to this. This would allow us to change where it is run from if we decided to.
		self.repoRoot = _abspath("./")
		self.stagingDir = _tempFile.gettempdir()
		opSys.directory_should_exist(self.stagingDir)

		self.whichNVDA = builtIn.get_variable_value("${whichNVDA}", "source")
		if self.whichNVDA == "source":
			self._runNVDAFilePath = _pJoin(self.repoRoot, "source/nvda.pyw")
			self.baseNVDACommandline = f"pyw -3.7-32 {self._runNVDAFilePath}"
		elif self.whichNVDA == "installed":
			self._runNVDAFilePath = _pJoin(_expandvars('%PROGRAMFILES%'), 'nvda', 'nvda.exe')
			self.baseNVDACommandline = f'"{str(self._runNVDAFilePath)}"'
		else:
			raise AssertionError("RobotFramework should be run with argument: '-v whichNVDA [source|installed]'")

		self.profileDir = _pJoin(self.stagingDir, "nvdaProfile")
		self.logPath = _pJoin(self.profileDir, 'nvda.log')
		self.preservedLogsDir = _pJoin(
			builtIn.get_variable_value("${OUTPUT DIR}"),
			"nvdaTestRunLogs"
		)
示例#19
0
def _createNvdaSpyPackage():
    import os
    searchPaths = sys.path
    profileSysTestSpyPackageStagingDir = _pJoin(tempDir,
                                                systemTestSpyAddonName)
    # copy in required dependencies, the addon will modify the python path
    # to point to this sub dir
    spyPackageLibsDir = _pJoin(profileSysTestSpyPackageStagingDir, "libs")
    opSys.create_directory(spyPackageLibsDir)
    for lib in requiredPythonImportsForSystemTestSpyPackage:
        libSource = _findDepPath(lib, searchPaths)
        if os.path.isdir(libSource):
            opSys.copy_directory(libSource, spyPackageLibsDir)
        elif os.path.isfile(libSource):
            opSys.copy_file(libSource, spyPackageLibsDir)

    opSys.copy_file(
        _pJoin(systemTestSourceDir, "libraries",
               systemTestSpyAddonName + ".py"),
        _pJoin(profileSysTestSpyPackageStagingDir, "__init__.py"))
    opSys.copy_file(
        _pJoin(systemTestSourceDir, "libraries", "systemTestUtils.py"),
        profileSysTestSpyPackageStagingDir)
    return profileSysTestSpyPackageStagingDir
示例#20
0
def _createNvdaSpyPackage():
	import os
	searchPaths = sys.path
	profileSysTestSpyPackageStagingDir = _pJoin(tempDir, systemTestSpyAddonName)
	# copy in required dependencies, the addon will modify the python path
	# to point to this sub dir
	spyPackageLibsDir = _pJoin(profileSysTestSpyPackageStagingDir, "libs")
	opSys.create_directory(spyPackageLibsDir)
	for lib in requiredPythonImportsForSystemTestSpyPackage:
		libSource = _findDepPath(lib, searchPaths)
		if os.path.isdir(libSource):
			opSys.copy_directory(libSource, spyPackageLibsDir)
		elif os.path.isfile(libSource):
			opSys.copy_file(libSource, spyPackageLibsDir)

	opSys.copy_file(
		_pJoin(systemTestSourceDir, "libraries", systemTestSpyAddonName+".py"),
		_pJoin(profileSysTestSpyPackageStagingDir, "__init__.py")
	)
	opSys.copy_file(
		_pJoin(systemTestSourceDir, "libraries", "systemTestUtils.py"),
		profileSysTestSpyPackageStagingDir
	)
	return profileSysTestSpyPackageStagingDir
示例#21
0
文件: NvdaLib.py 项目: steverep/nvda
	def check_for_crash_dump(
			since: _Optional[_datetime],
			overridePath: _Optional[str] = None,
	) -> _Optional[str]:
		"""
		Checks if a crash.dmp exits and returns the crash dmp path if so
		"""
		crashPath = overridePath or _pJoin(_locations.logPath, "..", "nvda_crash.dmp")
		try:
			opSys.file_should_not_exist(crashPath)
		except Exception:
			crashTime = opSys.get_modified_time(crashPath, format="epoch")
			crashTime = _datetime.fromtimestamp(crashTime)
			since = since.replace(microsecond=0)  # get_modified_time only reports seconds, not microseconds
			if crashTime >= since:
				return crashPath
示例#22
0
builtIn = BuiltIn()  # type: BuiltIn
process = builtIn.get_library_instance('Process')  # type: Process
opSys = builtIn.get_library_instance(
    'OperatingSystem')  # type: OperatingSystem

spyServerPort = 8270  # is `registered by IANA` for remote server usage. Two ASCII values:'RF'
spyServerURI = 'http://127.0.0.1:{}'.format(spyServerPort)
spyAlias = "nvdaSpy"

# robot is expected to be run from the NVDA repo root directory. We want all repo specific
# paths to be relative to this. This would allow us to change where it is run from if we decided to.
repoRoot = _abspath("./")
whichNVDA = builtIn.get_variable_value("${whichNVDA}", "source")
if whichNVDA == "source":
    NVDACommandPathToCheckExists = _pJoin(repoRoot, "source/nvda.pyw")
    baseNVDACommandline = "pythonw " + NVDACommandPathToCheckExists
elif whichNVDA == "installed":
    NVDACommandPathToCheckExists = _pJoin(_expandvars('%PROGRAMFILES%'),
                                          'nvda', 'nvda.exe')
    baseNVDACommandline = '"%s"' % NVDACommandPathToCheckExists
else:
    raise AssertionError(
        "robot should be given argument `-v whichNVDA [source|installed]")

# Paths
systemTestSourceDir = _pJoin(repoRoot, "tests", "system")
tempDir = tempfile.gettempdir()
opSys.directory_should_exist(tempDir)
nvdaProfileWorkingDir = _pJoin(tempDir, "nvdaProfile")
nvdaLogFilePath = _pJoin(nvdaProfileWorkingDir, 'nvda.log')
示例#23
0
文件: NvdaLib.py 项目: bocoup/nvda
    def create_preserved_test_output_filename(self, fileName):
        """EG for nvda.log path will become:
			${OUTPUT DIR}/nvdaTestRunLogs/${SUITE NAME}-${TEST NAME}-nvda.log
		"""
        return _pJoin(_locations.preservedLogsDir,
                      self._createTestIdFileName(fileName))
示例#24
0
 def _getTestCasePath(filename):
     return _pJoin(ChromeLib._testFileStagingPath, filename)
示例#25
0
	def _getTestCasePath(filename):
		return _pJoin(NotepadLib._testFileStagingPath, filename)
示例#26
0
from systemTestUtils import _blockUntilConditionMet

builtIn = BuiltIn()  # type: BuiltIn
process = builtIn.get_library_instance('Process')  # type: Process
opSys = builtIn.get_library_instance('OperatingSystem')  # type: OperatingSystem

spyServerPort = 8270  # is `registered by IANA` for remote server usage. Two ASCII values:'RF'
spyServerURI = 'http://127.0.0.1:{}'.format(spyServerPort)
spyAlias = "nvdaSpy"

# robot is expected to be run from the NVDA repo root directory. We want all repo specific
# paths to be relative to this. This would allow us to change where it is run from if we decided to.
repoRoot = _abspath("./")
whichNVDA = builtIn.get_variable_value("${whichNVDA}", "source")
if whichNVDA == "source":
	NVDACommandPathToCheckExists = _pJoin(repoRoot, "source/nvda.pyw")
	baseNVDACommandline = "pythonw "+NVDACommandPathToCheckExists
elif whichNVDA == "installed":
	NVDACommandPathToCheckExists = _pJoin(_expandvars('%PROGRAMFILES%'),'nvda','nvda.exe')
	baseNVDACommandline='"%s"' % NVDACommandPathToCheckExists
else:
	raise AssertionError("robot should be given argument `-v whichNVDA [source|installed]")

# Paths
systemTestSourceDir = _pJoin(repoRoot, "tests", "system")
tempDir = tempfile.gettempdir()
opSys.directory_should_exist(tempDir)
nvdaProfileWorkingDir = _pJoin(tempDir, "nvdaProfile")
nvdaLogFilePath = _pJoin(nvdaProfileWorkingDir, 'nvda.log')
systemTestSpyAddonName = "systemTestSpy"
testSpyPackageDest = _pJoin(nvdaProfileWorkingDir, "scratchpad", "globalPlugins")