SystemHelpers Methods
Checks if a file or folder exists on the SUT filesystem. To check if a folder exist pass in the folder with the path without the last "\" at the end.
If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.
public bool CheckFileExists(
string fileWithPath,
bool stayInCmd = false
)
Exception | Condition |
The command did not complete within 60 seconds. |
Closes all webbrowser windows that are not minimized. Warning for Close all tabs will be confirmed. Throws an exception if after 5 minutes not all windows could be closed.
public void CloseAllBrowsers()
Exception | Condition |
Browser was still open after several retries to close it. |
Copies the file(s) from the source path to the destination folder path using following cmd:
xcopy /q /h /y "{source}" "{destination}"
.
The name of the file will remain the same.
Note: For copying folders including its subdirectories use CopyFolder instead.public void CopyFile(
string source,
string destination,
bool stayInCmd = false,
int timeoutInSeconds = 300
)
Parameter | Description |
source | The file (incl path) to be copied. Supports wildcard characters for copying multiple files in the source directory. |
destination | The path of the destination folder where the file shall be copied to. |
[stayInCmd] | If stayInCmd is true, the cmd window is left open, otherwise it will be closed again. |
[timeoutInSeconds] | The timeout for the copying command. If the command does not complete within this time a TestStepAbortedException is thrown. |
Exception | Condition |
Either the copying command did not complete within the timeoutInSeconds or the command completed with an error. |
Copies the folder (with all files and subfolders) from the source path to the destination folder path using following cmd:
xcopy /q /i /e /h /y "{source}" "{destination}"
If destination folder does not exist yet, it will be created.public void CopyFile(
string source,
string destination,
bool stayInCmd = false,
int timeoutInSeconds = 300
)
Parameter | Description |
source | The folder path to be copied. |
destination | The path of the destination folder where the folder shall be copied to. |
[stayInCmd] | If stayInCmd is true, the cmd window is left open, otherwise it will be closed again. |
[timeoutInSeconds] | The timeout for the copying command. If the command does not complete within this time a TestStepAbortedException is thrown. |
Exception | Condition |
Either the copying command did not complete within the timeoutInSeconds or the command completed with an error. |
Creates new folders for the specified path using
mkdir
command. If a path already exists, command will return an error, but no further action is done (the outcome of the CreateFolderPath method is unaffected).public void CreateFolderPath(
params string[] paths
)
Parameter | Description |
paths | One or multiple path strings that should be created. |
Deletes a file or folder on the SUT filesystem. To delete a folder include the "\" at the end to indicate it's a folder.
If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.
public void DeleteFile(
string fileWithPath,
bool stayInCmd = false
)
Exception | Condition |
The command did not complete within 60 seconds. |
This method checks that the desktop of the environment is completely loaded and checks the CPU load of the SUT from the cmd window to ensure the system is responsive (CPU load below 40%).
If an installer testcase is used, this should be called from installer Precondition step, otherwise from test case Precondition step.
public bool EnvironmentReady(
bool checkSystemResponsive = true
)
Parameter | Description |
[checkSystemResponsive] |
True if the system is responsive. Otherwise methods throws a SUTNotReadyException that will trigger a VM Redeployment for cloud VMs.
Exception | Condition |
If the system is not responsive, a SUTNotReadyException is trown that will trigger a VM Redeployment for cloud VMs. |
Determines the current CPU load percentage on the SUT by running the
wmic cpu get loadpercentage.
public int GetCpuLoadPercentage()
An integer value between 0 and 100 indicating the CPU load percentage on the SUT.
Exception | Condition |
Either the command to get the cpu load did not complete or the cpu load percentage could not be parsed from the response of the command. |
Gets the computer name of the SUT with the
hostname
command.public string GetComputerName()
The computer name as a string.
Exception | Condition |
The command to get the computer name did not complete or did not return anything. |
Returns a list of all file- and folder names contained in the specified
folderPath
that match the providedfileNameFilter
. The result list is sorted by date/time, oldest first.public IList<string> GetFileAndFolderNames(
string folderPath,
string fileNameFilter = ""
bool stayInCmd = true
)
A List of filtered and sorted file/folder names.
Parameter | Description |
folderPath | |
[fileNameFilter] | Type: String
Filter string that can contain wildcard characters '*' to substitute for any string of characters. For example: *.txt filters for all files ending with '.txt' |
[stayInCmd] | Type: Boolean
If true, the cmd window is left open, otherwise it will be closed again. Default false. |
Exception | Condition |
InteractionFailedException | When the command window cannot be opened after 3 retries. |
Gets the build version of the operating system on the SUT.
public string GetOsBuildVersion()
A string with the OS build version.
Kills a program or process from the run menu in windows (using Win-R key-shortcut).
public void KillProcess(
string processName
)
Parameter | Description |
processName | The name of the process that shall be killed. |
Logs the name and version of the environment model contained in this assembly. Should be called in setup test step of every test case using the environment model.
public void LogEnvironmentModelVersion()
Logs in the most recent user to windows from the welcome or lock screen if required. If login failed a TestStepAbortedException is thrown.
public void LoginRecentUser(
string password = null
)
Parameter | Description |
[password] | Optional parameter for the password. If not set (or NullOrEmpty) the password from the connection string is used. |
Checks if a cmd window is already open on the screen, if not opens a new cmd window, if yes prepares it for new commands.
public ICommandLineWindow OpenCommandLineWindow()
An instance of the ICommandLineWindow class that allows to interact with the cmd window that was just opened.
Exception | Condition |
When the command window cannot be opened after 3 retries. |
This is a Windows specific method and cannot be used on other environments! Checks if a cmd window is already open in administrator mode on the screen, if not closes any other cmd window and opens a new cmd window in administrator mode, if yes prepares it for new commands.
public ICommandLineWindow OpenCommandLineWindowAsAdmin()
An instance of the ICommandLineWindow class that allows to interact with the cmd window that was just opened.
Exception | Condition |
When the command window cannot be opened after 3 retries. |
Opens a folder or file, or starts a program from the file explorer.
public void OpenInExplorer(
string path
)
Parameter | Description |
path | The name of the folder path, file or program that shall be opened. |
Runs the webpage.bat from Installer directory that will open the target webpage for the SUT.
public Browser OpenWebUrl()
An instance of the Browser class that allows to interact with the browser window that was just opened.
Exception | Condition |
When the browser window does not open after the wait time. |
Renames the specified item to a new Name.
public void RenameItem(
string itemPath,
string newName,
bool stayInCmd = false
)
Starts a program or process from the run menu in windows (using Win-R key-shortcut).
public void RunProcess(
string processName
)
Parameter | Description |
processName | The name of the program or process that shall be run. |
Name | Description |
Mounts the remote directory that is provided by the execution host. If assigned drive is already in use, it is disconnected first. Uses default drive letter R. | |
Mounts the remote directory that is provided by the execution host to the specified drive. If assigned drive is already in use, it is disconnected first. |
Mounts the remote directory that is provided by the execution host. If assigned drive is already in use, it is disconnected first. Uses default drive letter R.
public void SetUpRemoteDirectory( )
Exception | Condition |
Either the previous mapping could not be removed or the current remote directory could not be mapped. |
Mounts the remote directory that is provided by the execution host to the specified drive and updates ArtifactsDirectory, SupportingFilesDirectory etc accordingly.
If assigned drive is already in use, it is disconnected.
Note: The Drive Letter is not persisted from Installer to TestCase, so if you SetupRemoteDirectory in Installer, the TestCase will again default to 'R' for ArtifactsDirectory etc.
public void SetUpRemoteDirectory(
char driveLetter
)
Parameter | Description |
driveLetter | The drive letter to which the remote directory shall be mapped to. |
Exception | Condition |
Either the previous mapping could not be removed or the current remote directory could not be mapped. |
Start to monitor heartbeat based on Windows clock.
public virtual void StartHeartBeatMonitor()
Stop the heartbeat monitoring.
public virtual void StopHeartBeatMonitor()
Extracts an archive (tested with zip, but potentially other archive types work as well) to the destination folder.
public void RunProcess(
string pathToZipFile,
string destinationPath,
bool stayInCmd = false,
int timeoutInSeconds = 300
)
Parameter | Description |
pathToZipFile | The path to the zip file. |
destinationPath | The path of the folder in which the zip file shall be extracted. With or without at the end. Will be created if it doesn't exist. |
[stayInCmd] | If stayInCmd is true, the cmd window is left open, otherwise it will be closed again. |
[timeoutInSeconds] | The timeout for the unzip command. If the command does not complete within this time a TestStepAbortedException is thrown. |
Last modified 3mo ago