SystemHelpers Methods

CheckFileExists

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.

Syntax:

public bool CheckFileExists(
    string fileWithPath,
    bool stayInCmd = false
)

Parameters:

Parameter

Description

fileWithPath

Type: String

The full name of the file or folder to check.

[stayInCmd]

Type: Boolean

If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.

Exceptions:

Exception

Condition

The command did not complete within 60 seconds.

CloseAllBrowsers

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.

Syntax:

public void CloseAllBrowsers()

Exceptions:

Exception

Condition

Browser was still open after several retries to close it.

CopyFiles

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.

Syntax:

public void CopyFile(
	string source,
	string destination,
	bool stayInCmd = false,
	int timeoutInSeconds = 300
)

Parameters:

Parameter

Description

source

Type: String

The file (incl path) to be copied. Supports wildcard characters for copying multiple files in the source directory.

destination

Type: String

The path of the destination folder where the file shall be copied to.

[stayInCmd]

Type: Boolean

If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.

[timeoutInSeconds]

Type: Int32

The timeout for the copying command. If the command does not complete within this time a TestStepAbortedException is thrown.

Exceptions:

Exception

Condition

Either the copying command did not complete within the timeoutInSeconds or the command completed with an error.

CopyFolder

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.

Syntax:

public void CopyFile(
	string source,
	string destination,
	bool stayInCmd = false,
	int timeoutInSeconds = 300
)

Parameters:

Parameter

Description

source

Type: String

The folder path to be copied.

destination

Type: String

The path of the destination folder where the folder shall be copied to.

[stayInCmd]

Type: Boolean

If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.

[timeoutInSeconds]

Type: Int32

The timeout for the copying command. If the command does not complete within this time a TestStepAbortedException is thrown.

Exceptions:

Exception

Condition

Either the copying command did not complete within the timeoutInSeconds or the command completed with an error.

CreateFolderPath

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).

Syntax:

public void CreateFolderPath(
	params string[] paths
)

Parameters:

Parameter

Description

paths

Type: String[ ]

One or multiple path strings that should be created.

DeleteFile

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.

Syntax:

public void DeleteFile(
    string fileWithPath,
    bool stayInCmd = false
)

Parameters:

Parameter

Description

fileWithPath

Type: String

The full name of the file or folder to check (for a folder include \ at the end)

[stayInCmd]

Type: Boolean

If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.

Exceptions:

Exception

Condition

The command did not complete within 60 seconds.

EnvironmentReady

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.

Syntax:

public bool EnvironmentReady(
	bool checkSystemResponsive = true
)

Parameters:

Parameter

Description

[checkSystemResponsive]

Type: Boolean If this is false, the responsivenes check is disabled. True by default.

Return Value:

True if the system is responsive. Otherwise methods throws a SUTNotReadyException that will trigger a VM Redeployment for cloud VMs.

Exceptions:

Exception

Condition

If the system is not responsive, a SUTNotReadyException is trown that will trigger a VM Redeployment for cloud VMs.

GetCpuLoadPercentage

Determines the current CPU load percentage on the SUT by running the wmic cpu get loadpercentage.

Syntax:

public int GetCpuLoadPercentage()

Return Value:

An integer value between 0 and 100 indicating the CPU load percentage on the SUT.

Exceptions:

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.

GetComputerName

Gets the computer name of the SUT with the hostname command.

Syntax:

public string GetComputerName()

Return Value:

The computer name as a string.

Exceptions:

Exception

Condition

The command to get the computer name did not complete or did not return anything.

GetFileAndFolderNames

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.

Syntax:

public IList<string> GetFileAndFolderNames(
    string folderPath,
    string fileNameFilter = ""
    bool stayInCmd = true
)

Return Value:

A List of filtered and sorted file/folder names.

Parameters:

Parameter

Description

folderPath

Type: String The folder path to get the file/folder names from

[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.

Exceptions:

Exception

Condition

InteractionFailedException

When the command window cannot be opened after 3 retries.

GetOsBuildVersion

Gets the build version of the operating system on the SUT.

Syntax:

public string GetOsBuildVersion()

Return Value:

A string with the OS build version.

KillProcess

Kills a program or process from the run menu in windows (using Win-R key-shortcut).

Syntax:

public void KillProcess(
	string processName
)

Parameters:

Parameter

Description

processName

Type: String

The name of the process that shall be killed.

LogEnvironmentModelVersion

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.

Syntax:

public void LogEnvironmentModelVersion()

LoginRecentUser

Logs in the most recent user to windows from the welcome or lock screen if required. If login failed a TestStepAbortedException is thrown.

Syntax:

public void LoginRecentUser(
    string password = null
)

Parameters:

Parameter

Description

[password]

Type: String

Optional parameter for the password. If not set (or NullOrEmpty) the password from the connection string is used.

OpenCommandLineWindow

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.

Syntax:

public ICommandLineWindow OpenCommandLineWindow()

Return Value:

An instance of the ICommandLineWindow class that allows to interact with the cmd window that was just opened.

Exceptions:

Exception

Condition

When the command window cannot be opened after 3 retries.

OpenCommandLineWindowAsAdmin

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.

Syntax:

public ICommandLineWindow OpenCommandLineWindowAsAdmin()

Return Value:

An instance of the ICommandLineWindow class that allows to interact with the cmd window that was just opened.

Exceptions:

Exception

Condition

When the command window cannot be opened after 3 retries.

OpenInExplorer Method

Opens a folder or file, or starts a program from the file explorer.

Syntax:

public void OpenInExplorer(
	string path
)

Parameters:

Parameter

Description

path

Type: String

The name of the folder path, file or program that shall be opened.

OpenWebUrl Method

Runs the webpage.bat from Installer directory that will open the target webpage for the SUT.

Syntax:

public Browser OpenWebUrl()

Return Value:

An instance of the Browser class that allows to interact with the browser window that was just opened.

Exceptions:

Exception

Condition

When the browser window does not open after the wait time.

RenameItem

Renames the specified item to a new Name.

Syntax:

public void RenameItem(
    string itemPath,
    string newName,
    bool stayInCmd = false
)

Parameters:

Parameter

Description

itemPath

Type: String

The item (including path) to rename

newName

Type: String

The new name

[stayInCmd]

Type: Boolean

If true, the cmd window is left open, otherwise it will be closed again.Default false.

RunProcess Method

Starts a program or process from the run menu in windows (using Win-R key-shortcut).

Syntax:

public void RunProcess(
	string processName
)

Parameters:

Parameter

Description

processName

Type: String

The name of the program or process that shall be run.

SetUpRemoteDirectory Method

Overload List

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.

SetUpRemoteDirectory()

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.

Syntax:

public void SetUpRemoteDirectory( )

Exceptions:

Exception

Condition

Either the previous mapping could not be removed or the current remote directory could not be mapped.

SetUpRemoteDirectory(Char)

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.

Syntax:

public void SetUpRemoteDirectory(
	char driveLetter
)

Parameters:

Parameter

Description

driveLetter

Type: Char

The drive letter to which the remote directory shall be mapped to.

Exceptions:

Exception

Condition

Either the previous mapping could not be removed or the current remote directory could not be mapped.

StartHeartBeatMonitor

Start to monitor heartbeat based on Windows clock.

Syntax:

public virtual void StartHeartBeatMonitor()

StopHeartBeatMonitor

Stop the heartbeat monitoring.

Syntax:

public virtual void StopHeartBeatMonitor()

UnzipFile

Extracts an archive (tested with zip, but potentially other archive types work as well) to the destination folder.

Syntax:

public void RunProcess(
	string pathToZipFile,
	string destinationPath,
	bool stayInCmd = false,
	int timeoutInSeconds = 300
)

Parameters:

Parameter

Description

pathToZipFile

Type: String

The path to the zip file.

destinationPath

Type: String

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]

Type: Boolean

If stayInCmd is true, the cmd window is left open, otherwise it will be closed again.

[timeoutInSeconds]

Type: Int32

The timeout for the unzip command. If the command does not complete within this time a TestStepAbortedException is thrown.

Last updated