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

Take snapshot OnError

9 Answers 253 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Morten Røgenes
Top achievements
Rank 1
Morten Røgenes asked on 12 May 2010, 02:00 PM
Hi,

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

Sort by
0
Missing User
answered on 12 May 2010, 03:45 PM
Hi Morten,

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.
0
Missing User
answered on 12 May 2010, 04:16 PM
Hello again Morten,

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.
0
Morten Røgenes
Top achievements
Rank 1
answered on 14 May 2010, 01:47 PM
Hi, and thanks for replying
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 =)
0
Cody
Telerik team
answered on 14 May 2010, 05:29 PM
Hi Morten Røgenes,

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;
    }
}

All the best,
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.
0
Anton
Top achievements
Rank 1
answered on 03 Aug 2012, 04:49 PM

Hi.

what about taking screenshots in WebAii Testing FrameWork?

If I use 

Log.CaptureBrowser(ActiveBrowser, "webaiiscreen");
then screenshot captured in "c:\WebAiiLog\" but picture is "broken".

Please see attach.

And: maybe framework has feature to take screenshot as ByteArray?

0
Cody
Telerik team
answered on 08 Aug 2012, 08:54 PM
Hello,

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();

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Anton
Top achievements
Rank 1
answered on 10 Aug 2012, 11:57 AM

I have simple code:

if (TestContext.CurrentContext.Outcome.Status == TestStatus.Failed ||
                TestContext.CurrentContext.Outcome.Status == TestStatus.Inconclusive)
            {
                TestLog.AttachImage("Screenshot", ActiveBrowser.Window.GetBitmap());
            }
this is for MbUnit framework.

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.

0
Cody
Telerik team
answered on 15 Aug 2012, 01:22 AM
Hi,

I am glad you found a solution. Thank you for the update!

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
srihari
Top achievements
Rank 1
answered on 21 Sep 2015, 02:38 PM

HI,

ActiveBrowser class is doesnt exist in my application. please provide full description for screenshot.

Regards

P. Srihari

Tags
General Discussions
Asked by
Morten Røgenes
Top achievements
Rank 1
Answers by
Missing User
Morten Røgenes
Top achievements
Rank 1
Cody
Telerik team
Anton
Top achievements
Rank 1
srihari
Top achievements
Rank 1
Share this question
or