Functional random keyword-driven tests

All the test cases so far address one type of operation in the application. We have seen how to compare two new files, map the application folder, filter on history, and compare using the default feature. On the whole, we have four main operations. Generally, the user will rarely start the application to perform one operation and then close it. Furthermore, we might want to automate the requirement's use cases that describe user scenarios composed from many operations. The two use cases are illustrated as follows:

  • Use case one:
    1. Open an application.
    2. Map the application folder.
    3. Compare files using the default feature.
    4. Check history.
  • Use case two:
    1. Open an application.
    2. Compare files using the new files option.
    3. Check history.
    4. Map the application folder.

These use cases are nothing but a rearrangement of the basic application functions we listed previously. They also form keyword sets where each numbered bullet maps to one File Comparer function. So we are going to address each function as an atomic unit. Any unique combination of the atomic functions could serve as an automated keyword test and this is exactly what we are going to see in this section.

Let us picture for a second the keyword test structure. The first task is to generate the sequence of random keywords. The second task is to loop over this sequence and call the corresponding tests.

The three new notions that we need to take care of are as follows:

  • Introducing the random factor in the test
  • Saving the randomly generated output into a structure that will be visible to all the test steps
  • Dynamically calling the random tests

Theoretically, we are going to map each basic test from the atomic functions to an integer that starts with 0 and increases by 1 as follows:

  • Value 0 represents Func-1_FileCompare_Equal_Successful
  • Value 1 represents Func-2_FileCompare_DefaultComparison_Successful
  • Value 2 represents Func-3_FileCompare_MapFolder_Successful
  • Value 3 represents Func-4_History_SingleDate_Successful

Create a folder under the Automated Test Scripts folder called Keyword Tests and then add a WPF test called KeywordTests_Random. Open the test and add a coded step called to it and then edit the underlying function's name to KeywordTests_Random_KeywordTestManager. This function will, as its name suggests, produce the random number sequence. In the following way, we would have catered the preceding first notion:

 [CodedStep(@"Generating random number sequence")]
        public void KeywordTests_Random_KeywordTestManager()
        {
            Random random = new Random();
  InfoHolder.tests = new int[]{random.Next(3), random.Next(3), random.Next(3), random.Next(3)};            
        }

The generated number sequence is saved in the InfoHolder.tests structure. This structure is accessible inside all the subsequent coded steps since it will be created in a static class, meaning that there will be only one instance of it throughout the life span of the test. Add this code to the beginning of the class right before the public class KeywordTests_Random statement:

public static class InfoHolder
        {
            public static int[] tests = new int[4];        
            public static int testNum;
        }

The tests integer array will be populated with the random numbers generated when the KeywordTests_Random_KeywordTestManager method executes. The testNum variable is going to hold the index of the loop that will dynamically call the tests based on their mapped number. At any time, this variable is strictly less than four. With this, we have implemented the second notion.

From the Logical button of the Add ribbon, add a loop after the [CodedStep(@"Generating random number sequence")] test step and set the value of its count to 4. Finally, add the following coded step, which is responsible for dynamically calling the keyword test and dragging it inside the loop block:

[CodedStep(@"Execute Random Test")]
        public void KeywordTest_RandomTest()
        {
            
            string testToExecute = String.Empty;
            
            switch (InfoHolder.tests[InfoHolder.testNum])
                {
                case 0:
                    testToExecute = "Automated Test Scripts\Functional Tests\Func-1_FileCompare_Equal_Successful.tstest";
                    break;
                case 1:
                    testToExecute = "Automated Test Scripts\Functional Tests\Func-2_FileCompare_DefaultComparison_Successful.tstest";
                    break;
                case 2:
                    testToExecute = "Automated Test Scripts\Functional Tests\Func-3_FileCompare_MapFolder_Successful.tstest";
                        break;
                case 3:
                    testToExecute = "Automated Test Scripts\Functional Tests\Func-4_History_SingleDate_Successful.tstest";
                        break; 
                }
            
InfoHolder.testNum++;
            
            Log.WriteLine("Executing Keyword test");
            this.ExecuteTest(testToExecute);
           
        }

The switch case block assigns the physical file path to the testToExecute variable, based on the theoretical numbering of the atomic functions. This variable is the parameter of the built-in Test Studio framework's Execute method. When it executes, it will call the automated test, which will run under the KeywordTests_Random scope. With this step we have finalized the preceding three notions.

Set up the test, so that it launches the File Comparer application using the Configure button and then run it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.28