Links

CmdWindow Methods

ClearScreen

Clears the current console session by running the "cls" command.

Syntax:

public void ClearScreen()

EnterText

Enters the specified text in the console and verifies the input.

Syntax:

public void EnterText(
string textToEnter
)

Parameters:

Parameter
Description
textToEnter
Type: String The text to enter.

MakeReadyForNewCommand

Makes sure the console is ready for a new command. Clears existing input text that is not run yet and aborts a running command with Ctrl+C if necessary.

Syntax:

public bool MakeReadyForNewCommand(
bool throwException = true
)

Parameters:

Parameter
Description
[throwException]
Type: Boolean If set to true throws an exception if console is not ready for a new command, otherwise returns false.

Return Value:

True if console is ready for a new command, false or exception otherwise.

Exceptions:

Exception
Condition
Command window was not ready for a new command

RunCommand

Enters the provided command and runs it by pressing enter. Returns as soon as the first output of the command is received (on the next line) or the command completes. If your command logs output to the console you probably want to follow RunCommand with WaitForCmdToComplete
Example to run you own command from a test case:
var cmd = App.SystemHelpers.OpenCommandLineWindow();
cmd.RunCommand("my command");
cmd.WaitForCmdToComplete(); // not required if my command doesn't log

Syntax:

public void RunCommand(
string command,
int timeoutInSeconds = 60
)

Parameters:

Parameter
Description
command
Type: String The command that shall be entered and run.
[timeoutInSeconds]
Type: Int32 The timeout in seconds until the first output must be received.

Exceptions:

Exception
Condition
Command did not complete within timeoutInSeconds.

VerifyText

Verifies the expected text appears in the output of the last command. Allows to pass in different variants of the text in order to allow for different localisations.

Syntax:

public bool VerifyText(
params string[] expectedTextWithVariants,
out string lastCmd
)

Parameters:

Parameter
Description
expectedTextWithVariants
Type: String[ ] The text to verify in the console. Can be multiple strings that are e.g. different localisations, which are all accepted. Array must not be empty.
[lastCmd]
Type: String Returns the full output of the last command, to enable further checks without the need to get the text again.

Return Value:

Returns true if one of the text variants appears in the output of the last command or the command itself.

WaitForCmdToComplete

Waits for a command to complete by waiting until the console is ready for a new command. Note: an input request is not considered a completed command and will mostly likely timeout the method.

Syntax:

public bool WaitForCmdToComplete(
int timeout = 60,
bool throwException = true
)

Parameters:

Parameter
Description
[timeout]
Type: String The timeout in which the command must be completed.
[throwException]
Type: Int32 If set to true an exception is thrown if command is not completed after the timeout, otherwise returns false.

Return Value:

True if command is completed within the specified timeout, false or exception otherwise.

Exceptions:

Exception
Condition
Command did not complete within timeoutInSeconds and throwException is true.