OnAfterTestCompleted to be used on all tests

15 posts, 0 answers
  1. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 20 Dec 2017 Link to this post

    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?
  2. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 21 Dec 2017 Link to this post

    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
     
  3. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 22 Dec 2017 in reply to Elena Tsvetkova Link to this post

    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.

  4. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 27 Dec 2017 Link to this post

    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
     
  5. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 03 Jan in reply to Nikolay Petrov Link to this post

    This doesnt' seem to be running after I run a test studio test in VS.
  6. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 05 Jan Link to this post

    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
     
  7. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 08 Jan in reply to Elena Tsvetkova Link to this post

    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?

  8. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 08 Jan Link to this post

    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
     
  9. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 08 Jan in reply to Elena Tsvetkova Link to this post

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

     

  10. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 08 Jan in reply to Lisa Link to this post

    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.
  11. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 08 Jan in reply to Lisa Link to this post

    Elena,

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

  12. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 08 Jan in reply to Lisa Link to this post

    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.

  13. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 09 Jan Link to this post

    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
     
  14. Lisa
    Lisa avatar
    34 posts
    Member since:
    Nov 2017

    Posted 18 Jan in reply to Lisa Link to this post

    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.

  15. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    934 posts

    Posted 18 Jan Link to this post

    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
     
Back to Top