Inheriting from a Base Test Class

6 posts, 0 answers
  1. Mike Trill
    Mike Trill avatar
    4 posts
    Member since:
    May 2006

    Posted 13 Nov 2018 Link to this post

    Hi,

     

    I am new to Test Studio and have to say it is nice.  However, I have come across a problem with how it inherits.  My initial thoughts were I would create a base class with specific coded steps for navigation, I could then easily incorporate these in other tests.  The following is a very basic idea, the first draft I did was split into it's own class:

     

    public class BaseTestClass : BaseWebAiiTest
    {
        [CodedStep(@"Go to My Account")]
        public void Account_Links_GotoMyAccounts()
        {
            var pageLink = Find.ByExpression(LinkAttributes.MyAccountPage);
             
            Assert.IsNotNull(pageLink);
             
            Actions.Click(pageLink);
        }
    }
     
    public class SearchMusic : BaseTestClass
    {
     
        [CodedStep(@"New Coded Step")]
        public void SearchMusic_CodedStep()
        {
            var attr = Find.ByContent<HtmlSpan>("18");
             
            Assert.IsNotNull(attr);
        }
    }

     

     

    The inheritence used in the test studio will no longer pick up SearchMusic_CodedStep() but does find functions from BaseTestClass as in the attached image.  As SearchMusic class descends from BaseTestClass, which descends from BaseWebAiiTest.  It should pick up all public methods from BaseTestClass and SearchMusic class.

     

    In the simple example above, any new coded functions added, will be added to BaseTestClass class, not SearchMusic class.  If BaseTestClass resides within another .cs file then an error is shown.

    If the above worked, it would make it a bit easier for my use, and hopefully others.

     

    FYI I do have simple tests like login etc which are used as"Test as Step" when performing other tests.

     

    regards

     

    Si

     

     

     

  2. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    353 posts

    Posted 16 Nov 2018 Link to this post

    Hello,

    Thank you for the kind words about our product. If I understand correctly you want to reuse coded step in more then one test as you create a base class that contains these steps. I can say that this scenario is completely doable within Test Studio and I see that you have accomplished the most of it. However, as something might be missed and it is hard for me to tell what this could be, I will share the exact steps needed to accomplish the desired scenario. Having those, please check them out and let me know if they work on your side or the issue occurs again:
    1. Create a test.
    2. Add a step and convert it to code.
    3. Create a base class that inherits BaseWebAiiTest. How to create external code file you can find here.
    4. Cut the code of the created coded step and paste it to the base class.
    5. Change the base class of the test's code file with the new created base class.
    6. Change the base test class in the settings of the project. This can be done in the Code Base Class filed in the Recording tab, by adding the name of your base class there.

    Additionally, I managed to develop a Test Studio project that represents all the above steps. For your convenience, I have attached this project to my reply.

    Meanwhile, it is also important to note that we found an issue related to the UI of the coded steps. The problem is that, the base methods are missing in the coded step list methods drop down. Still, this is only a visual glitch and the steps should still execute without issues when you run the test. Further, you can also track the status of this issue as it is already added in our feedback portal.

    As for the 'test as a step' functionality, I believe this is indeed the better approach for reusing steps in different tests. This is mainly because, this way you can create 'test as a step' steps for all tests that have to execute the shared actions.

    I hope the above helps. If there are any further questions or issues, please do let me know.

    Regards,
    Dobry Zranchev
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. Si
    Si avatar
    2 posts
    Member since:
    Nov 2018

    Posted 20 Nov 2018 in reply to Dobry Zranchev Link to this post

    Hi Dobry,

     

    Thanks for the reply, and the demo, I was seeing the same issue in the demo that I experienced when attempting this myself, I have attached the images.

     

    TestInheritence1.png shows when I open the test window, the step is missing from the first coded step and it is rightly highlighted red.

     

    The second image Testinheritence2.png shows that WebTest_CodedStep1 (from base class1.cs) is not available in the drop down list.

    In both instances, I would expect to see the the method "WebTest_CodedStep1" available through inheritence.

     

    FYI I am on version 2018.3.1004.0, my "check for updates" reports I am on the latest version.

    kind regards

     

    Si

     

  4. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    353 posts

    Posted 23 Nov 2018 Link to this post

    Hi Si,

    The fact that you are able to reproduce the faulty behavior on your side as well tells us that the issue is indeed valid no matter the environment Test Studio runs in. This said, I will make sure that the bug is prioritized accordingly on our next planning and hopefully a fix for it will be released with our next Test Studio official release.

    Meanwhile, there is a workaround to overcome the above UI glitch. To use a step from the base class in the test you can follow these steps (have in mind that they are in reference to the sample project I shared in my previous reply):
    1. Copy the method from the base class to the inheritor class. In case of our project you should copy the method
    [CodedStep(@"Navigate to : 'http://www.bing.com/'")]
            public void WebTest_CodedStep1()
            {
                // Navigate to : 'http://www.bing.com/'
                ActiveBrowser.NavigateTo("http://www.bing.com/", true);
                 
            }
    from Class1 (the base class) and paste it to class WebTest.
    2. Create a new coded step and select method WebTest_CodedStep1.
    3. Delete the copied method WebTest_CodedStep1 from the WebTest class - as you can see, the previous 2 steps are only for you to be able to select the method from the drop-down menu. After deleting the method from the WebTest class, we will automatically fall to the same method, but from the base class during execution.
    4. Next, open the test in Test Studio - you will still see the UI issue, but you will be able to execute the test successfully.
    5. Execute the test and see if it succeeds as expected.

    I hope these steps work on your side. Please, let us know if this is not the case.

    Regards,
    Dobry Zranchev
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  5. Si
    Si avatar
    2 posts
    Member since:
    Nov 2018

    Posted 26 Nov 2018 in reply to Dobry Zranchev Link to this post

    Cheers I will give it a try :-)
  6. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    353 posts

    Posted 27 Nov 2018 Link to this post

    Hi Si,

    Of course, take your time to give a try to the proposed solution. And please do not hesitate to write back if you have any questions.

    Regards,
    Dobry Zranchev
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top