Skip to content
Mat Walker edited this page Feb 28, 2018 · 7 revisions

Utilities .NET

Introduction

TeamControlium Utilities.NET package provides Automation test engineers with a suite of utilities to assist in development of a Test Framework and/or tests.

Detokenizer

Automated tests frequently need create and/or have access to dynamic data. Instances may include date offsets (such as Yesterdays date, tomorrow's date) random passwords that meets the target applications password strength requirements etc. Handrolling these takes time and is an added burden to the automation engineer. Therefore, the Detokenizer provides the ability to embed tokens in strings that are resolved at runtime.

Examples

Todays date in required format
string todaysDateInRequiredFormat = Detokenizer.ProcessTokensInString("Date today is: {date;today,MMMM dd, yyyy}");
Returns: "Date today is: March 01, 2018" - If that was the day the code was executed.

Day of the week
string dayOfTheWeek = Detokenizer.ProcessTokensInString("Day today is: {date;today,dddd}");
Returns: "Day today is: Wednesday" - If run on a Wednesday

Date 2 months ago in required format
string dateTwoMonthsAgoInRequiredFormat = Detokenizer.ProcessTokensInString("Date 2 months ago was: {date;AddMonths(-2),MMMM dd, yyyy}");
Returns: "Date 2 months ago was: January 01, 2018"

Random float between 1.5 and 2.5 to two decimal places
string randomFloat = Detokenizer.ProcessTokensInString("{random;float(1.5,2.5);0.00}");
Example return: "1.78"

Password with 8 characters, including 1 digit and no consecutive letters or digits
string password = Detokenizer.ProcessTokensInString("{random;from(abcdefgh);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(jklmnop);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(rstuvwxyz);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(abcdefgh);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(jklmnop);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(rstuvwxyz);1}");
string password += Detokenizer.ProcessTokensInString("{random;from(abcdefgh);1}");
string password += Detokenizer.ProcessTokensInString("{random;digit;1}");
Example return: "hjugkua6"

Nested tokens
string fromNested = Detokenizer.ProcessTokensInString("{random;digits;{random;from(2345);1} }");
Would return a string containing 2, 3, 4 or 5 random digits.

Logger

Provides a method for test logging. Logs can be output to console or consumed by a delegate for custom output (IE. To a test log etc). Logger has levels of logging that can be set at the start - or during - test execution to filter log messages. As an example, a test in debug mode may want to output all logging information (Framework information etc!) but in test execution mode just the test log messages. The Logger outputs the level of message, absolute time when the message was created, an time since test start, name of class and method calling the logger and the test message. Logger is thread-safe, allowing multi threaded tests to build and output messages without corruption.

Examples

A test outputs a message to the log
Logger.WriteLn(Logger.LogLevels.TestInformation,"Hello from a test");
This would output: "LOG-I [06:33:34.40][00000.01] [GitHubExampleClass.TestMethod]: Hello from a test"

public string MyLogCatcher(string loggerString) { <do something with loggerString> }
Logger.TestToolLog = (s) => { MyLogCatcher(s); };
Logger.WriteLn(Logger.LogLevels.TestInformation,"Hello from a test");
MyLogCatcher would be called with "LOG-I [06:33:34.40][00000.01] [GitHubExampleClass.TestMethod]: Hello from a test"

TestArguments

Presents test arguments to test code as an array.

Examples

Call test with various parameters
>MyTest.exe -env=TestEnv3 -user=TestUser2 -password=quality123 -database=db4.testenv.local
.
.
.
.
class Program
    {
        static void Main(string[] args)
        {
            TestArguments testArgs = new TestArguments(args);
            string environment = testArgs["env"];
            string database = testArgs["database"];
            string username= testArgs["user"];
            string password= testArgs["pass"];
        }
    }

Clone this wiki locally