Hi,
I'm using the Telerik test list setting to 'close and continue' when unexpected dialogs appear. When that happens in my script, I see a line in my log letting me know it happened:
LOG: Unexpected dialog encountered. Closing the dialog, and continuing execution.
My question is, Is there any way to capture an image of, or the text from, the handled dialog, especially if I don't know what text might be on that dialog? I'd like to see the title & any text from the body of the dialog, in order to diagnose what the dialog was reporting.
Thanks,
-Mark
I'm using the Telerik test list setting to 'close and continue' when unexpected dialogs appear. When that happens in my script, I see a line in my log letting me know it happened:
LOG: Unexpected dialog encountered. Closing the dialog, and continuing execution.
My question is, Is there any way to capture an image of, or the text from, the handled dialog, especially if I don't know what text might be on that dialog? I'd like to see the title & any text from the body of the dialog, in order to diagnose what the dialog was reporting.
Thanks,
-Mark
7 Answers, 1 is accepted
0
Daniel
Top achievements
Rank 2
answered on 01 Oct 2013, 12:06 PM
You can use a custom alert dialog handler instead of the settings in the test list.
Here is what I do (as an example for an alert dialog) using the OnBeforeTestStarted method (http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/execute-custom-scripts-before-after-test.aspx):
This is obviously just an example, but here is the reference I used to get that far: http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/advanced-topics/handling-html-popups-and-dialogs/built-in-dialog-handlers/custom-dialog-handler.aspx
Here is what I do (as an example for an alert dialog) using the OnBeforeTestStarted method (http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/execute-custom-scripts-before-after-test.aspx):
public
override
void
OnBeforeTestStarted()
{
// custom alert handler to capture screenshot
AlertDialog myAlertDialog =
new
AlertDialog(ActiveBrowser, DialogButton.OK);
myAlertDialog.HandlerDelegate =
new
DialogHandlerDelegate(MyCustomAlertHandler);
Manager.DialogMonitor.AddDialog(myAlertDialog);
Manager.DialogMonitor.Start();
}
public
void
MyCustomAlertHandler(IDialog dialog)
{
string
ssPath =
this
.ExecutionContext.DeploymentDirectory.ToString() + @
"\Data\alert.png"
;
// capture current dialog window and save file.
System.Drawing.Bitmap image = dialog.Window.GetBitmap();
image.Save(ssPath, System.Drawing.Imaging.ImageFormat.Png);
dialog.Window.Close();
try
{
dialog.Window.WaitForVisibility(
false
, 50);
Log.WriteLine(
"Alert Handled!"
);
}
catch
{
Log.WriteLine(
"Failed to handle alert!"
);
}
}
This is obviously just an example, but here is the reference I used to get that far: http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/advanced-topics/handling-html-popups-and-dialogs/built-in-dialog-handlers/custom-dialog-handler.aspx
0
Mark N.
Top achievements
Rank 1
answered on 01 Oct 2013, 03:48 PM
Hi Daniel,
Thanks for the code example.
Just as information for you, Telerik tells me that the OnBeforeTestStarted() method is obsolete:
(CS0672) Member '<namespace>.<scriptname>.OnBeforeTestStarted()' overrides obsolete member 'ArtOfTest.WebAii.Design.BaseWebAiiTest.OnBeforeTestStarted()'. Add the Obsolete attribute to '<namespace>.<scriptname>.OnBeforeTestStarted()'.
However, it appears to ignore this and compile the code. Is there a different method I should be using?
(Also, by the way, the code-formatter tool this Forum uses removes too many spaces. At first, I thought there were methods named newAlertDialog and newDialogHandlerDelegate that I was missing. 8^)
Cheers,
-Mark
Thanks for the code example.
Just as information for you, Telerik tells me that the OnBeforeTestStarted() method is obsolete:
(CS0672) Member '<namespace>.<scriptname>.OnBeforeTestStarted()' overrides obsolete member 'ArtOfTest.WebAii.Design.BaseWebAiiTest.OnBeforeTestStarted()'. Add the Obsolete attribute to '<namespace>.<scriptname>.OnBeforeTestStarted()'.
However, it appears to ignore this and compile the code. Is there a different method I should be using?
(Also, by the way, the code-formatter tool this Forum uses removes too many spaces. At first, I thought there were methods named newAlertDialog and newDialogHandlerDelegate that I was missing. 8^)
Cheers,
-Mark
0
Daniel
Top achievements
Rank 2
answered on 01 Oct 2013, 05:05 PM
Totally new to me (yes it does still compile but I've never seen the warning before). Let me check into that and see what I can find (unless a Telerik Admin gets to it before me).
It's still documented this way on the website user guide.
Sorry about the code examples! I could have trimmed them down a bit to make it easier to read.
It's still documented this way on the website user guide.
Sorry about the code examples! I could have trimmed them down a bit to make it easier to read.
0
Accepted
Daniel
Top achievements
Rank 2
answered on 01 Oct 2013, 05:29 PM
And answer!
http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/global-variables---another-way.aspx
OnBeforeTestStarted() now takes a BeforeTestStartedArgs parameter.
OnBeforeTestStartedArgs has the following public members:
CancelTestExecution (bool, get/set)
Context (get, from ArtOfTest.WebAii.Design.Execution.ExecutionContext)
Test (get, ArtOfTest.WebAii.Design.ProjectModel.Test)
http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/global-variables---another-way.aspx
OnBeforeTestStarted() now takes a BeforeTestStartedArgs parameter.
OnBeforeTestStartedArgs has the following public members:
CancelTestExecution (bool, get/set)
Context (get, from ArtOfTest.WebAii.Design.Execution.ExecutionContext)
Test (get, ArtOfTest.WebAii.Design.ProjectModel.Test)
public
override
void
OnBeforeTestStarted(BeforeTestStartedArgs args)
{
args.CancelTestExecution =
false
;
string
something = args.Context.CurrentStep.Description.ToString();
int
something2 = args.Test.Steps.Count;
}
0
Mark N.
Top achievements
Rank 1
answered on 01 Oct 2013, 07:44 PM
Thanks again, Daniel. Adding just the parameter seems to fix it.
I'll give the code piece a try to see if it captures the dialog image as I hope!
I'll give the code piece a try to see if it captures the dialog image as I hope!
0
Daniel
Top achievements
Rank 2
answered on 01 Oct 2013, 08:20 PM
Glad it is working. If for some reason it is not, verify the type of Dialog (http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/dialogs-and-popups/dialogs.aspx) and change the code based on which Dialog it is (http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/advanced-topics/handling-html-popups-and-dialogs/built-in-dialog-handlers.aspx).
Have a good one!
Have a good one!
0
Hi Daniel,
Thank you for your input and helping others. We really appreciate it.
I have also updated your Telerik points.
Regards,
Velin Koychev
Telerik
Thank you for your input and helping others. We really appreciate it.
I have also updated your Telerik points.
Regards,
Velin Koychev
Telerik