I like the snapshot functionality in WebAii, and have a seperate test that all other tests call as their last step.
This test will wait for a feedback div, and then pass. If it fails, it will take a snapshot, so I can see why the original test failed.
That will work for most of my cases because it rarely fails before this last step, but when it does I do not get the snapshot.
So I was wondering if there was an OnError eventhandler or something that would be called when a test failed, or if there are any other ways to take a snapshot when the test fails.
Thank you
9 Answers, 1 is accepted
Thanks for the post and question. From your user history, I believe you are using WebUI Test Studio Dev Edition even though this post was listed under the framework.
If this is so, there is not a feature like this currently in WebUI, though a feature request is in the works. As a work around, in a code behind file please try the following:
using
System;
using
System.Text;
using
System.Collections.Generic;
using
ArtOfTest.WebAii.Core;
using
ArtOfTest.WebAii.ObjectModel;
using
ArtOfTest.WebAii.Controls.HtmlControls;
using
ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using
ArtOfTest.WebAii.Silverlight;
using
ArtOfTest.WebAii.Silverlight.UI;
using
ArtOfTest.WebAii.Design.Execution;
using
ArtOfTest.WebAii.Design;
using
Telerik.WebAii.Controls.Html;
using
Telerik.WebAii.Controls.Xaml;
namespace
TestProject22
{
//
// You can add custom execution steps by simply
// adding a void function and decorating it with the [CodedStep]
// attribute to the test method.
// Those steps will automatically show up in the test steps on save.
//
// The BaseWebAiiTest exposes all key objects that you can use
// to access the current testcase context. [i.e. ActiveBrowser, Find ..etc]
//
// Data driven tests can use the Data[columnIndex] or Data["columnName"]
// to access data for a specific data iteration.
//
// Example:
//
// [CodedStep("MyCustom Step Description")]
// public void MyCustomStep()
// {
// // Custom code goes here
// ActiveBrowser.NavigateTo("http://www.google.com");
//
// // Or
// ActiveBrowser.NavigateTo(Data["url"]);
// }
//
public
class
ExampleTest : BaseWebAiiTest
{
#region [ Dynamic Pages Reference ]
private
Pages _pages;
/// <summary>
/// Gets the Pages object that has references
/// to all the elements, frames or regions
/// in this project.
/// </summary>
public
Pages Pages
{
get
{
if
(_pages ==
null
)
{
_pages =
new
Pages(Manager.Current);
}
return
_pages;
}
}
public
override
void
CleanUp()
{
//
// Place any additional cleanup here
//
if
(
this
.ExecutionContext.TestResult.FailureException !=
null
)
Log.CaptureBrowser(ActiveBrowser,
"SnapShotName"
);
#region WebAii CleanUp
// Shuts down WebAii manager and closes all browsers currently running
// after each test. This call is ignored if recycleBrowser is set
base
.CleanUp();
#endregion
}
#endregion
}
}
If you are using the framework, you can use the same as above in the WebAii Unit templates, but all you would need to add is ovverride Cleanup() method added in. Here is a link to another user thread something similar for more reference.
Please reply back if you have any questions on the above.
Kind regards,
Nelson Sin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
My coworker reminded me that the new WebUI Dev and QA editions both automatically take screenshots on step failure. Please look in the Test Project's TestResult folder, then look in the time stamped test run folder for the screenshot taken.
Quick Edit: You can also see the screenshots in Quick Execution mode by double clicking on the far right red 'X' on the failing test step. The images should be under an Image tab in the Failure Window popup.
Again, if you are using the WebAii Framework, you can use ovveride CleanUp() method or some other try/catch/finally implementation.
Sorry about the confusion.
Best wishes,
Nelson
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Sorry for posting in the wrong forum. I guess "General discussion" is the right one?
For my problem...
When I run tests from test view, there is no images in the testresult folder, but I get the image tab when I run a quick execution.
The CleanUp() method has been overriden in my own base class, that derives from your base class, so I dont have to include it in all of my tests.
The CleanUp() takes snapshots as I want it to, but when the test is data driven, it only runs after the last row, so if the first row failed, I get the wrong image.
Is there another workaround?
Thanks for the good support =)
This is the right forum for questions surrounding using the framework with pure coded tests instead of in combination with WebUI Test Studio.
You're right in that taking a screenshot in the CleanUp method will only happen after all the data rows have run. You have a couple of options instead:
You could add place the snapshot code in the TestCleanup method like this:
// Use TestCleanup to run code after each test has run
[TestCleanup()]
public
void
MyTestCleanup()
{
//
// Place any additional cleanup here
//
if
(
this
.TestContext.CurrentTestOutcome != UnitTestOutcome.Passed)
Log.CaptureBrowser(ActiveBrowser,
"SnapShotName"
);
#region WebAii CleanUp
// Shuts down WebAii manager and closes all browsers currently running
// after each test. This call is ignored if recycleBrowser is set
this
.CleanUp();
#endregion
}
Or you could add a Try/Catch block with your test method like this:
[TestMethod]
public
void
SampleWebAiiTest()
{
try
{
// test code here
}
catch
(Exception ex)
{
Log.CaptureBrowser(ActiveBrowser,
"SnapShotName"
);
throw
ex;
}
}
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Hi.
what about taking screenshots in WebAii Testing FrameWork?
If I use
Log.CaptureBrowser(ActiveBrowser,
"webaiiscreen"
);
Please see attach.
And: maybe framework has feature to take screenshot as ByteArray?
I apologize for the delay getting back to you.
Just as a poitn of clarification anytime you start writing code, you are using our framework API. The only difference about WebAii Testing FrameWork is the API is all you have to use.. no IDE, no recording, no scheduling server, etc.
I've never seen the captured image containing only part of the browser like that. If you can show me how to reproduce that I'd like to investigate the cause.
You can grab the browser as a System.Drawing.Bitmap object:
System.Drawing.Bitmap bmap = ActiveBrowser.Window.GetBitmap();
Cody
the Telerik team
Test Studio Trainings
I have simple code:
if
(TestContext.CurrentContext.Outcome.Status == TestStatus.Failed ||
TestContext.CurrentContext.Outcome.Status == TestStatus.Inconclusive)
{
TestLog.AttachImage(
"Screenshot"
, ActiveBrowser.Window.GetBitmap());
}
I try this code and it's works.
ActiveBrowser.ContentWindow.GetBitmap()
My Env: IE9, Win7 x64, Gallio 3.3.1, Project compiled for x86 cpu.
I am glad you found a solution. Thank you for the update!
Greetings,Cody
the Telerik team
Test Studio Trainings
HI,
ActiveBrowser class is doesnt exist in my application. please provide full description for screenshot.
Regards
P. Srihari