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

OnAfterTestCompleted to be used on all tests

14 Answers 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lisa
Top achievements
Rank 1
Lisa asked on 20 Dec 2017, 09:55 PM
Is there a way to create an OnAfterTestCompleted override to apply to all tests in a project instead of living in a specific test's code?

14 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 21 Dec 2017, 02:17 PM
Hi Lisa,

Thank you for your query. 

I guess you have overridden the OnAfterTestCompleted() method in a coded step for a single test as described here. Though this method is part of the Execution extension which could be used to extend the test execution and control some post and pre-conditions. 

I hope this will be helpful to you. Though please let me know in case of further assistance required. Thanks! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Lisa
Top achievements
Rank 1
answered on 22 Dec 2017, 07:16 PM

Hi Elena,

I've created a class for this ExtensionExecution.cs and I've added it to my project which has .tstest files.

I'm having some trouble, first I can't tell if it's actually ever running the code, and secondly the code looks like it wouldn't work anyway.

The goal is to make sure that the test logs out properly regardless of whether it passed or failed. So I'm using OnAfterTestCompleted and trying to find the logout element on the screen and click it.

Essentially my class looks like:

    public class ExtensionExecutions : IExecutionExtension
    {
        public void OnAfterTestCompleted(ExecutionContext executionContext, TestResult result)
        {
            ActiveBrowser.Find.ByContent("l:Log out", FindContentType.TextContent).Click();
            }

But ActiveBrowser apparently doesn't exist in this context.

 

I'm not married to this particular implementation. But I'd like to be able to log out as a post test action. Can you help me out here? The logout button is defined on some pages so if that helps that is available.

0
Nikolay Petrov
Telerik team
answered on 27 Dec 2017, 11:09 AM
Hi Lisa,

The recommended approach using an execution extension is to create a separate class library and place it in the \bin\Plugins folder of the product as described here.

It is possible to use ActiveBrowser to complete your test with a logout step though. It is located in the:
executionContext.Manager.ActiveBrowser...

I hope this clarification helps.

Best Regards,
Nikolay Petrov
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Lisa
Top achievements
Rank 1
answered on 03 Jan 2018, 03:41 PM
This doesnt' seem to be running after I run a test studio test in VS.
0
Elena
Telerik team
answered on 05 Jan 2018, 03:48 PM
Hi Lisa,

Let me step back in this discussion. 

I reviewed the additional info you have shared in regards the requirements you have to accomplish. What I understood so far is that you have decided to build an execution extension to perform the logout once the test is finished despite of its result. This should be the correct approach in the case when this should be performed after each executed test. 

What I suspect is that the code used might not be working as expected. Would it be possible to provide the exact code you have entered in the OnAfterTestCompleted method? 

Alternatively, there is one more thing you might find useful and applicable in this scenario. There is a Clear Browser Cache step which will actually clear the logged user session and thus the next navigation to the tested page will be with a fresh user session. You could start each test with such a step to ensure the state of the application. Do you think this will work for you as well? 

I am looking forward to hearing from you! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Lisa
Top achievements
Rank 1
answered on 08 Jan 2018, 01:37 PM

Hi Elena,

It could be that I need to reimplement the class, which is what I'm doing. I'm worried I made a mistake before. The code I'm using for the logout is:

 executionContext.Manager.ActiveBrowser.Find.ByContent<HtmlAnchor>("l:Log out", FindContentType.TextContent).Click(); 

I can't use ClearBrowser here unfortunately. The cookies for this seem to persist through ClearBrowser and if I don't do an explicit log out we have issues with the app thinking the user is still logged in.

I'm having an issue with the implementation.

        public System.Data.DataTable OnInitializeDataSource(ExecutionContext executionContext)
        {
            // Your custom implementation here
            return null;
        }

Visual studio using C# doesn't seem to recognize System.Data.DataTable exists. Is there a using I'm missing? I've tried including System.Data but it doesn't seem to make a difference - System.Data isn't recognized. Is it possible the code on the ExecutionExtensions page https://docs.telerik.com/teststudio/advanced-topics/coded-samples/general/execution-extensions is out of date?

0
Elena
Telerik team
answered on 08 Jan 2018, 03:43 PM
Hi Lisa,

Thank you for the details. 

Please let me know is the code you implemented to logout is now working or it is still not? I couldn't understand as of the current info. If it is still not working could you please try debugging it in a coded step instead in the class library file? 

You could try locate the link first with the same find logic and then assert the value of the object is not null. I suspect that the link is not located at all and thus is not clicked. In case you still don't manage to find the correct approach I would like to kindly ask you to share access to the application and a sample test to use for debugging of the issue. 

In regards issue with the OnInitilizeData method please let me know if you have added the usings (not related to Test Studio) listed at the beginning of the article: 
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

along with the references to System.Runtime.Serialization and System.Windows.Forms? 

Please let me know of the results. Thanks! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Lisa
Top achievements
Rank 1
answered on 08 Jan 2018, 03:55 PM

This is what I'm seeing - Visual studio isn't recognizing the System.Data usings.

 

0
Lisa
Top achievements
Rank 1
answered on 08 Jan 2018, 04:07 PM
I won't be able to give you access to our application, it's not allowable. The issue isn't in running the tests anyway, I can't get the class to compile.
0
Lisa
Top achievements
Rank 1
answered on 08 Jan 2018, 04:15 PM

Elena,

Disregard the other replies. It turns out I needed to give the project a reference to System.Data.

0
Lisa
Top achievements
Rank 1
answered on 08 Jan 2018, 04:52 PM

Elena,

I actually can't find %ProgramFiles%\Telerik\Test Studio\Bin\Plugins\ . I don't see a Telerik file in either of my Program Files folders.

0
Elena
Telerik team
answered on 09 Jan 2018, 01:35 PM
Hello Lisa,

Probably the installation folder is %ProgramFiles%\Progress\Test Studio\Bin\Plugins\ - we have changed that as of R3 2017 release (v.2107.3.1010). If you have newly installed that release or the Service pack edition after it the installation folder will be under the Progress one. 

I double checked the article and noticed it is not updated as per the above information and would like to apologize about that. Though the note is taken into account and soon will be fixed. 

Thank you for your understanding! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Lisa
Top achievements
Rank 1
answered on 18 Jan 2018, 03:13 PM

Elena,

For now we are using continue on failure on our test as step calls to make sure we hit the logout step. That seems pretty reasonable for now. Because we are planning on running on a lot of different machines having to install the dll in the program folders of Telerik seems pretty intractable.

0
Elena
Telerik team
answered on 18 Jan 2018, 03:56 PM
Hi Lisa,

Thank you for the feedback. I am glad to know you have found a solution that suits your needs. Though in case of further assistance required please do not hesitate to contact me again! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Lisa
Top achievements
Rank 1
Answers by
Elena
Telerik team
Lisa
Top achievements
Rank 1
Nikolay Petrov
Telerik team
Share this question
or