public void TestLogAllTypesOfOutcome() { var iteration = StfIterationNo; switch (iteration) { case 1: StfAssert.IsTrue("Pass", true); break; case 2: StfAssert.IsTrue("Fail", false); break; case 3: StfAssert.IsInconclusive("Inconclusive", "Inconclusive"); break; case 4: StfLogger.LogWarning("Warning", "Warning"); break; case 5: StfLogger.LogError("Error", "Error"); break; } }
public void TestLogTextWithNewlines() { StfLogger.LogLevel = StfLogLevel.Info; StfLogger.LogInfo("Single line 1"); StfLogger.LogInfo(string.Format("Entering Multi line{0}Second row{0}Third row{0}{0}Blank line above{0}Last line", Environment.NewLine)); StfLogger.LogInfo("Single line 2"); }
public void TestLogScreenshot() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogTrace("Just before a screenshot is taken"); StfLogger.LogScreenshot(StfLogLevel.Debug, "Grabbed screenshot"); StfLogger.LogTrace("right after a screenshot is taken"); }
public void TestLogFileWriter() { StfLogger.FileName = @"c:\temp\unittestlogger.html"; StfLogger.FileName = @"c:\temp\unittestlogger2.html"; StfLogger.FileName = @"c:\temp\unittestlogger3.html"; StfLogger.CloseLogFile(); }
public void TestScreenshotOnLogFail() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogFail("Screenshot on log fail on by default", string.Empty); StfLogger.Configuration.ScreenshotOnLogFail = false; StfLogger.LogFail("Screenshot on log fail turned off. No screenshot logged.", string.Empty); }
public void TestMethodInit() { var myLogger = new StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodInit2.html" }; myLogger.CloseLogFile(); }
public void TestLogAllWindows() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogTrace("Just before logging all windows"); StfLogger.LogAllWindows(StfLogLevel.Info, "Grabbed all windows"); StfLogger.LogTrace("right after logging all windows"); }
public void DatadrivenLoggerTest3LinesLine1Fail() { var iteration = (int)TestContext.DataRow["Iteration"]; var message = (string)TestContext.DataRow["Message"]; var failPass = ConvertToBool((string)TestContext.DataRow["FailPass"]); StfLogger.LogInfo($"Iteration [{iteration}]: {message}"); Assert.IsTrue(StfAssert.IsTrue("FailPass", failPass) == failPass); }
public void TestMethodKeyValues() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogKeyValue("Bent", "42", "First value for Bent"); StfLogger.LogKeyValue("Bent", "43", "Second value for Bent - this is the only one that should be shown in the list"); StfLogger.LogKeyValue("File Url", @"File://*****:*****@"An explorer should pop up show c:\temp\Stf"); StfLogger.LogKeyValue("Web Url", "Http://www.testautomation.dk", "A browser should pop up show testautomation.dk"); }
public void TestMethodLotsOfEntries() { StfLogger.LogLevel = StfLogLevel.Internal; for (int i = 0; i < 75; i++) { StfLogger.LogInfo($"LogInfo Nr {i}"); } StfLogger.CloseLogFile(); }
/// <summary> /// The helper datadriven with testdata object. /// </summary> /// <returns> /// The <see cref="UnitTestTestDataObject"/>. /// </returns> private UnitTestTestDataObject HelperDatadrivenWithTestdataObject() { var testdata = new UnitTestTestDataObject { Iteration = "-1" }; testdata = InitTestData(testdata); StfLogger.LogInfo($"Iteration [{testdata.Iteration}]: {testdata.Message}"); StfAssert.AreEqual("Iteration", testdata.Iteration, testdata.StfIteration.ToString()); return(testdata); }
public void DatadrivenLoggerTest() { var iteration = (int)TestContext.DataRow["Iteration"]; var message = (string)TestContext.DataRow["Message"]; StfLogger.LogInfo($"Iteration [{iteration}]: {message}"); // need to close the logfile, in order to check the content of the logfile... StfLogger.CloseLogFile(); // we want to fail, if FileContains fails StfAssert.EnableNegativeTesting = false; StfAssert.FileContains(iteration.ToString(), StfLogger.FileName, message); }
public void TestLogTextWithInvalidXmlContent() { var xmlToLog = string.Format(@"<xmltags>{0}<xmltag>{0}Line 1{0} Six Space indent{0}</xmltag>{0}</WRONG_CLOSING_TAG>{0}", Environment.NewLine); StfLogger.LogLevel = StfLogLevel.Info; StfLogger.LogSubHeader("xml without anything"); StfLogger.LogInfo(xmlToLog); StfLogger.LogSubHeader("Using Escape"); StfLogger.LogInfo(System.Security.SecurityElement.Escape(xmlToLog)); StfLogger.LogSubHeader("Using logXml"); StfLogger.LogXmlMessage(xmlToLog); }
private void HelperUnaryAssert( UnaryStringAssert unaryStringAssert, string argument, bool expected) { Func <string, string, bool> stringAssertFunction; switch (unaryStringAssert) { // Empty case UnaryStringAssert.StringEmpty: stringAssertFunction = StfAssert.StringEmpty; break; case UnaryStringAssert.StringNotEmpty: stringAssertFunction = StfAssert.StringNotEmpty; break; default: throw new ArgumentOutOfRangeException(nameof(unaryStringAssert), unaryStringAssert, null); } var argumentValue = GetStringValueUnfoldEmptyNull(argument); var testDescription = $"{unaryStringAssert}({argumentValue})"; StfLogger.LogSubHeader($"Unit Testing: {testDescription} --> Expecting {expected}"); var retVal = stringAssertFunction(testDescription, argument); if (expected != retVal ) { StfLogger.LogSubHeader($"Unit Test Found an error for {testDescription}..."); } if (expected) { Assert.IsTrue(retVal, "Unit Test Result"); } else { Assert.IsFalse(retVal, "Unit Test Result"); } }
/// <summary> /// The helper read key value pairs from file. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="inputFilename"> /// The input filename. /// </param> /// <param name="assignmentOperator"> /// The assignment operator. /// </param> /// <param name="commentIndicator"> /// The comment indicator. /// </param> /// <param name="keyNameIgnoreCase"> /// The key name ignore case. /// </param> private void HelperReadKeyValuePairsFromFile(string testStep, string inputFilename, string assignmentOperator = "=", string commentIndicator = "//", bool keyNameIgnoreCase = true) { StfLogger.LogHeader(testStep); var absolutePathInput = stfTestUtils.GetTestCaseRootFilePath(inputFilename); var absolutePathExpected = stfTestUtils.GetTestCaseRootFilePath($@"Expected\{inputFilename}"); var tempInputPath = stfTestUtils.GetTestCaseTempFilePath(inputFilename, false); var tempActualPath = stfTestUtils.GetTestCaseTempFilePath($@"{inputFilename}-Actual.txt", false); var tempExpectedPath = stfTestUtils.GetTestCaseTempFilePath($@"{inputFilename}-Expected.txt", false); var fileUtils = stfTestUtils.FileUtils; fileUtils.CopyFile(absolutePathInput, tempInputPath); fileUtils.CopyFile(absolutePathExpected, tempExpectedPath); // generate Actual var keyNameValueUtils = new KeyValuePairUtils(assignmentOperator, commentIndicator, keyNameIgnoreCase); var keyValuePairs = keyNameValueUtils.ReadKeyValuePairsFromFile(tempInputPath); keyNameValueUtils.SaveKeyValuePairsToFile(tempActualPath, keyValuePairs); StfAssert.FilesDoNotDiffer(testStep, tempExpectedPath, tempActualPath); }
public void TestMethodAllLogTypeWithFormatting() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogError("{0}", "LogError"); StfLogger.LogWarning("{0}", "LogWarning"); StfLogger.LogInfo("{0}", "LogInfo"); StfLogger.LogDebug("{0}", "LogDebug"); StfLogger.LogTrace("{0}", "LogTrace"); StfLogger.LogInternal("{0}", "LogInternal"); StfLogger.LogHeader("{0}", "LogHeader"); StfLogger.LogSubHeader("{0}", "LogSubHeader"); StfLogger.LogError("{0} - {1}", "LogError", new List <string>()); StfLogger.LogWarning("{0} - {1}", "LogWarning", new { Test = "Test" }); StfLogger.LogInfo("{0} - {1} - {2}", "LogInfo", 42, 84); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction", new object[] { "arg1", "arg2", "arg3" }); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction", 42); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunctionShort"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunctionShort"); // used solely by Assert functions StfLogger.LogPass("testStepName LogPass", "{0}", "LogPass"); StfLogger.LogFail("testStepName LogFail", "{0}", "LogFail"); StfLogger.LogInconclusive("testStepName LogInconclusive", "Inconclusive result: {0}", 1); StfLogger.LogKeyValue("SomeKey", "SomeValue", "{0}", "LogKeyValue"); StfLogger.LogGetEnter(StfLogLevel.Info, "MyTestProperty"); StfLogger.LogGetExit(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogSetEnter(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogSetExit(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogAutomationIdObject(StfLogLevel.Internal, StfLogger, "Using StfLogger as AID for test"); StfLogger.SetRunStatus(); }
public void TestMethodCallStack() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogInfo("NameOfFunction_L0A"); StfLogger.LogInfo("NameOfFunction_L0B"); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction_L1"); StfLogger.LogInfo("NameOfFunction_L1A"); StfLogger.LogInfo("NameOfFunction_L1B"); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction_L2"); StfLogger.LogInfo("NameOfFunction_L2A"); StfLogger.LogInfo("NameOfFunction_L2B"); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction_L3"); StfLogger.LogInfo("NameOfFunction_L3A"); StfLogger.LogInfo("NameOfFunction_L3B"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction_L3"); StfLogger.LogInfo("NameOfFunction_L2A"); StfLogger.LogInfo("NameOfFunction_L2B"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction_L2"); StfLogger.LogInfo("NameOfFunction_L1A"); StfLogger.LogInfo("NameOfFunction_L1B"); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction_L2"); StfLogger.LogInfo("NameOfFunction_L2A"); StfLogger.LogInfo("NameOfFunction_L2B"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction_L2"); StfLogger.LogInfo("NameOfFunction_L1A"); StfLogger.LogInfo("NameOfFunction_L1B"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction_L1"); StfLogger.LogInfo("NameOfFunction_L0A"); StfLogger.LogInfo("NameOfFunction_L0B"); }
public void TestMethodAllLogType() { StfLogger.LogLevel = StfLogLevel.Internal; StfLogger.LogError("LogError"); StfLogger.LogWarning("LogWarning"); StfLogger.LogInfo("LogInfo"); StfLogger.LogDebug("LogDebug"); // normal logging functions - models and adapters StfLogger.LogTrace("LogTrace"); StfLogger.LogInternal("LogInternal"); // Header logging functions - testscripts StfLogger.LogHeader("LogHeader"); StfLogger.LogSubHeader("LogSubHeader"); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunction", new object[] { "arg1", "arg2", "arg3" }); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunction", 42); StfLogger.LogFunctionEnter(StfLogLevel.Info, "Int", "NameOfFunctionShort"); StfLogger.LogFunctionExit(StfLogLevel.Info, "NameOfFunctionShort"); // used solely by Assert functions StfLogger.LogPass("testStepName LogPass", "LogPass"); StfLogger.LogFail("testStepName LogFail", "LogFail"); StfLogger.LogKeyValue("SomeKey", "SomeValue", "LogKeyValue"); StfLogger.LogGetEnter(StfLogLevel.Info, "MyTestProperty"); StfLogger.LogGetExit(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogSetEnter(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogSetExit(StfLogLevel.Info, "MyTestProperty", StfLogger); StfLogger.LogAutomationIdObject(StfLogLevel.Internal, StfLogger, "Using StfLogger as AID for test"); StfLogger.SetRunStatus(); }
public void TestMethodExceptionThrownInTestIsCaughtInCleanup() { StfLogger.LogInfo("This is a message before assert failed exception error"); throw new AssertFailedException(); }
public void TestCleanup() { // Setting to true again resets the failure count StfAssert.ResetStatistics(); StfLogger.LogInfo("UnitTestStfAsserts TestCleanup"); }
public void TestLogXmlMessage() { StfLogger.LogInfo("Using PrettyXml - per LogXmlMessage"); StfLogger.LogXmlMessage(@"<xmltags><xmltag>Line 1 </xmltag><xmltag>Six Space indent</xmltag></xmltags>"); }
public void TestInitialize() { StfAssert.EnableNegativeTesting = true; StfLogger.LogInfo("UnitTestStfAsserts TestInitialize"); }
public void DatadrivenLoggerTest10Lines() { StfLogger.LogInfo($"Iteration [{DateTime.Now}]"); }
public void TestCleanup() { StfLogger.LogInfo("DatadrivenStfLoggerTest TestCleanup"); StfAssert.ResetStatistics(); }
public void TestInitialize() { StfLogger.LogInfo("DatadrivenStfLoggerTest TestInitialize"); StfAssert.EnableNegativeTesting = true; }
private void HelperBinaryAssert( BinaryStringAssert binaryStringAssert, string arg1, string arg2, bool expected) { Func <string, string, string, bool> stringAssertFunction; switch ( binaryStringAssert ) { // EQUALS case BinaryStringAssert.StringEquals: stringAssertFunction = StfAssert.StringEquals; break; case BinaryStringAssert.StringEqualsCi: stringAssertFunction = StfAssert.StringEqualsCi; break; case BinaryStringAssert.StringNotEquals: stringAssertFunction = StfAssert.StringNotEquals; break; case BinaryStringAssert.StringNotEqualsCi: stringAssertFunction = StfAssert.StringNotEqualsCi; break; // CONTAINS case BinaryStringAssert.StringContains: stringAssertFunction = StfAssert.StringContains; break; case BinaryStringAssert.StringNotContains: stringAssertFunction = StfAssert.StringDoesNotContain; break; // ENDS WITH case BinaryStringAssert.StringEndsWith: stringAssertFunction = StfAssert.StringEndsWith; break; case BinaryStringAssert.StringDoesNotEndsWith: stringAssertFunction = StfAssert.StringDoesNotEndsWith; break; // STARTS WITH case BinaryStringAssert.StringStartsWith: stringAssertFunction = StfAssert.StringStartsWith; break; case BinaryStringAssert.StringDoesNotStartWith: stringAssertFunction = StfAssert.StringDoesNotStartWith; break; // MATCHES case BinaryStringAssert.StringMatches: stringAssertFunction = StfAssert.StringMatches; break; case BinaryStringAssert.StringDoesNotMatch: stringAssertFunction = StfAssert.StringDoesNotMatch; break; default: throw new ArgumentOutOfRangeException(nameof(binaryStringAssert), binaryStringAssert, null); } var arg1Value = GetStringValueUnfoldEmptyNull(arg1); var arg2Value = GetStringValueUnfoldEmptyNull(arg2); var testDescription = $"{binaryStringAssert}({arg1Value}, {arg2Value})"; StfLogger.LogSubHeader($"Unit Testing: {testDescription} --> Expecting {expected}"); var retVal = stringAssertFunction(testDescription, arg1, arg2); if (expected != retVal) { StfLogger.LogSubHeader($"Unit Test Found an error for {testDescription}..."); } if (expected) { Assert.IsTrue ( retVal, "Unit Test Result"); } else { Assert.IsFalse ( retVal, "Unit Test Result"); } }