I'm trying to learn Telerik with following materials and can't perform following example.
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/add-messagebox.aspx
I added System.Windows.Forms to the list of Project References but compilation of my test is failed:
MessageBox.tstest.cs: Line 78: (CS0117) 'TestProject1.MessageBox' does not contain a definition for 'Show'
7 Answers, 1 is accepted
You probably just need to add a using statement for System.Windows.Forms to the code-behind file. The Messagebox article has been updated with that information.
Regards,Anthony
the Telerik team
See all my settings here
http://clip2net.com/s/1msdu
http://clip2net.com/s/1mseW
Thank you for the screen shots.
The issue is with the name of your test. It matches the MessageBox command exactly. This is confusing the compiler. Once you rename the test to something different, everything should be fine.
Anthony
the Telerik team
First I'd like you to be aware of our Manual Step feature which accomplishes the same goal without code.
If you'd still like to continue in code, see below. First click the View Class button to see the code-behind file. Then edit your existing code to this:
[CodedStep(@
"New Coded Step"
)]
public
void
BingMessageBox_CodedStep()
{
//MessageBox.Show("This is a message!");
//Edit "desktop" to match your machine name
System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcessesByName(
"iexplore"
,
"desktop"
);
System.Windows.Forms.MessageBox.Show(
new
WindowWrapper(pro[0].MainWindowHandle),
"This is a test"
);
}
public
class
WindowWrapper : System.Windows.Forms.IWin32Window
{
public
WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public
IntPtr Handle
{
get
{
return
_hwnd;
}
}
private
IntPtr _hwnd;
}
Be aware that this won't work for browsers other than IE and might not work if you have more than one instance of IE opened. Regards,
Anthony
the Telerik team
See video
http://screencast.com/t/d3D0J3t5
You are correct; that solution can be unreliable as it uses the iexplore process as a reference point.
Try this new implementation, which breaks the dependence of the separate WindowWrapper class. That class can now be removed from the code-behind file.
Replace the contents of your coded step with the following lines:
NativeWindow a =
new
NativeWindow();
a.AssignHandle(ActiveBrowser.Window.Handle);
System.Windows.Forms.MessageBox.Show(a,
"This is a test"
);
Anthony
the Telerik team