This is a migrated thread and some comments may be shown as answers.

Capturing image of unexpected dialog?

7 Answers 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark N.
Top achievements
Rank 1
Mark N. asked on 30 Sep 2013, 07:27 PM
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

7 Answers, 1 is accepted

Sort by
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):

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


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!
0
Daniel
Top achievements
Rank 2
answered on 01 Oct 2013, 08:20 PM
0
Velin Koychev
Telerik team
answered on 02 Oct 2013, 11:52 AM
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
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Mark N.
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 2
Mark N.
Top achievements
Rank 1
Velin Koychev
Telerik team
Share this question
or