Tuesday, October 30, 2018

MAQS Faker Data Utility

We have discussed about MAQS open framework in two of the previous posts. How to setup Visual Studio to work with MAQS open framework is described in the first post (Functional Test Automation with MAQS Open Framework) and in the second post a sample test automation code is described(Start Test Automation with MAQS Open Framework). In this post, let’s identify simple but useful utility available in MAQS open framework.

Various types of test data are required to perform testing activities. MAQS has utility called Faker Data that provide the ability to generate random and valid data during runtime.
You would be able to get an understanding about faker data utility after going through following code segments.
1. Getting Current System time
Code Segment

  [TestMethod]
        public void FakeDataDate()
        {
           var dateTime= FakerData.GenerateInstantSpecificTime();
           Console.WriteLine(dateTime);
        }
Output
Fackerdate
2. Generate Unique id – Not formatted
Code Segment

   [TestMethod]
        public void FakeDataUniqueIDNotFormatted()
        {
            var uniqueID = FakerData.GenerateUniqueId(false);
            Console.WriteLine(uniqueID);
        }
Output
fakedatauniqueidnotformate
3. Generate Unique id – Formatted
Code Segment

 [TestMethod]
        public void FakeDataUniqueIDFormatted()
        {
            var uniqueID = FakerData.GenerateUniqueId();
            Console.WriteLine(uniqueID);
        }
Output
fakedatauniqueidformatted
4. Generate Phone Number – Formatted
Code Segment

 [TestMethod]
        public void FakeDataPhoneNumberFormatted()
        {
            var phoneNumber = FakerData.GenerateUSPhoneNumber();
            Console.WriteLine(phoneNumber);
        }
Output
fakedataphonenumberformatted
5. Generate Phone Number – Not Formatted
Code Segment

 [TestMethod]
        public void FakeDataPhoneNumberNotFormatted()
        {
            var phoneNumber = FakerData.GenerateUSPhoneNumber(true);
            Console.WriteLine(phoneNumber);
        }
Output
fakedataphonenotformated
6. Generate Social Security Number – With Dashes
Code Segment

   [TestMethod]
        public void FakeDataSocialSecurityNumberWithDashes()
        {
            var socialSecurityNumber = FakerData.GenerateSocialSecurityNumber(true);
            Console.WriteLine(socialSecurityNumber);
        }
Output
fakedatasocialsecuritynumdash
7. Generate Social Security Number – Without Dashes
Code Segment

  [TestMethod]
        public void FakeDataSocialSecurityNumberWithoutDashes()
        {
            var socialSecurityNumber = FakerData.GenerateSocialSecurityNumber();
            Console.WriteLine(socialSecurityNumber);
        }
Output
fakedatasocialwithoutdash
8. Generate Random value from the list
Code Segment

  [TestMethod]
        public void FakeDataRandomNumber()
        {
            List<string> valueList = new List<string> { "AAA","BBB","CCC"};
            var randomListValue = FakerData.GeneralRandomizer(valueList);
            Console.WriteLine(randomListValue);
        }
Output
fakedatalist
You can try out above sample code segments when writing automation code. These methods are useful for generating random sample data required for automated test execution.








1 comment:

  1. This functionality is being deprecated because there is something the MAQS team likes a lot more.
    https://www.nuget.org/packages/Faker.Data/
    This was created by the dev originally responsible for the MAQS faker code. Has all the functionality that MAQS has + some really nice extras.

    ReplyDelete