Click here to Skip to main content
15,886,742 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

Hi


I am writing automation testing.But I have a problem that to test Message Box.


I want to test a MessageBox in C#.


:confused::confused::confused:
Posted
Comments
Toli Cuturicu 15-Dec-10 15:43pm    
No question!

You could try using PowerShell[^] - the author discusses message box testing - not in detail but still, it may help.
 
Share this answer
 
Comments
Espen Harlinn 29-Dec-12 9:48am    
5'ed!
Here is how, for example:
$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

function Message-Box(
	[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
	[string] $message, [string] $header=$null,
 	[switch][bool]$error = $false) {
    $icon = [System.Windows.Forms.MessageBoxIcon]::Information
    if ($error) { $icon = [System.Windows.Forms.MessageBoxIcon]::Error }
    $null = [System.Windows.Forms.MessageBox]::Show($message, $header, [System.Windows.Forms.MessageBoxButtons]::OK, $icon)
} # Message-Box

# use it:
<pre lang="text">message-box "Some message" -header " Some (optional) header"

or
"Some message" | message-box -header " Some (optional) header"

or, for error icon (see implementation of the function):
message-box "Some error message" -header " Some (optional) header" -error
# [switch] attribute shows that the value is not used in command line

Enjoy,
—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 29-Dec-12 9:49am    
5'ed!
Sergey Alexandrovich Kryukov 29-Dec-12 20:07pm    
Thank you, Espen.
Have you done PowerShell? Interesting thing.
—SA
Espen Harlinn 30-Dec-12 5:42am    
I've tried it, but so far I've had little use for it professionally so my experience is limited :-D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900