Software Models

Overview

If you want to benefit from re-usability and easy maintenance of your test automation solution it is important to introduce the test model of your software. Instead of copy-pasting images and functions throughout you solution you will rather call a function of your test model.

The example below illustrates the problem and why it makes sense to introduce the software test model.

Test Case 1:

[TestStep(1,
            TestInput = "From the Home page go to the Contact Us page",
            ExpectedResults = "The Contact Us page is displayed")]
        public void Step1(ITester t)
        {
            //we are clicking on the Contact Us item in the Top Menu
            t.Testee.Mouse.Click(TestImages.TC001_Rev1.Images.TopMenu.ContactUs);

            //we are checking if the Contact Us page has been displayed
            if(t.Testee.FindImage(TestImages.TC001_Rev1.Images.Screens.ContactUs).HasSucceeded)
                t.Report.PassStep("The Contact Us page is displayed");
            else
                t.Report.FailStep("The Contact Us page is not displayed");
        } 

Test Case 2:

[TestStep(1,
            TestInput = "From the About Us page go to the Contact Us page",
            ExpectedResults = "The Contact Us page is displayed")]
        public void Step1(ITester t)
        {
            //we are clicking on the Contact Us item in the Top Menu
            t.Testee.Mouse.Click(TestImages.TC002_Rev1.Images.TopMenu.ContactUs);

            //we are checking if the Contact Us page has been displayed
            if(t.Testee.FindImage(TestImages.TC002_Rev1.Images.Screens.ContactUs).HasSucceeded)
                t.Report.PassStep("The Contact Us page is displayed");
            else
                t.Report.FailStep("The Contact Us page is not displayed");
        } 

Both test cases share the exact same functionality - navigating in the top menu and checking if the the Contact us page is displayed. In both cases not only do we duplicate the same code, but we also duplicate the same images. If you switch to a software model approach our test cases would look as follows:

Test Case 1:

[TestStep(1,
            TestInput = "From the Home page go to the Contact Us page",
            ExpectedResults = "The Contact Us page is displayed")]
        public void Step1(ITester t)
        {
            //we are clicking on the Contact Us item in the Top Menu
            App.TopMenu.ContactUs();

            //we are checking if the Contact Us page has been displayed
            if(App.Screen.ContactUs.IsDisplayed())
                t.Report.PassStep("The Contact Us page is displayed");
            else
                t.Report.FailStep("The Contact Us page is not displayed");
        } 

Test Case 2:

[TestStep(1,
            TestInput = "From the About Us page go to the Contact Us page",
            ExpectedResults = "The Contact Us page is displayed")]
        public void Step1(ITester t)
        {
            //we are clicking on the Contact Us item in the Top Menu
            App.TopMenu.ContactUs();

            //we are checking if the Contact Us page has been displayed
            if(App.Screen.ContactUs.IsDisplayed())
                t.Report.PassStep("The Contact Us page is displayed");
            else
                t.Report.FailStep("The Contact Us page is not displayed");
        } 

Now both test cases use the same model and therefore any change which would be done to the navigation and checking methods would need to be done only in the model and not the test case definition itself. In other words by introducing the model you are making sure that a change in the functionality of you software only needs to be updated in one place.

Last updated