def is_false(self, condition, softAssertName, failureMessage=""): # void test() if condition: if not failureMessage or failureMessage == "": raise SoftAssertException( StringProcessor.SafeFormatter( "SoftAssert.IsFalse failed for: {0}", softAssertName)) raise SoftAssertException( StringProcessor.SafeFormatter( "SoftAssert.IsFalse failed for: {0}. {1}", softAssertName, failureMessage)) return invoke_test(test, softAssertName, failureMessage)
def are_equal(self, expectedText, actualText, softAssertName, message=""): #void test() if expectedText != actualText: if (message == "" or message == None): raise SoftAssertException( StringProcessor.SafeFormatter( "SoftAssert.AreEqual failed for {0}. Expected '{1}' but got '{2}'", softAssertName, expectedText, actualText)) raise SoftAssertException( StringProcessor.SafeFormatter( "SoftAssert.AreEqual failed for {0}. Expected '{1}' but got '{2}'. {3}", softAssertName, expectedText, actualText, message)) return invoke_test(test, expectedText, actualText, message)
def log_message(self, expectedText, actualText, message, result): if result: Log.LogMessage( MessageType.SUCCESS, StringProcessor.SafeFormatter( "Soft Assert '{0}' passed. Expected Value = '{1}', Actual Value = '{2}'.", message, expectedText, actualText)) else: Log.LogMessage( MessageType.WARNING, StringProcessor.SafeFormatter( "Soft Assert '{0}' failed. Expected Value = '{1}', Actual Value = '{2}'.", message, expectedText, actualText))
def log_final_assert_data(self): message = [] ##MessageType type message.AppendLine( StringProcessor.SafeFormatter( "Total number of Asserts: {0}. {3}Passed Asserts = {1} {3}Failed Asserts = {2}{3}", NumberOfAsserts, NumberOfPassedAsserts, NumberOfFailedAsserts, os.linesep)) if listOfExceptions.Count > 0: type = MessageType.ERROR message.AppendLine("List of failed exceptions:") for exception in listOfExceptions: # Will log all the exceptions that were caught in Asserts to the log file. message.AppendLine(exception) else: # There are no exceptions that were caught in Asserts. type = MessageType.INFORMATION message.AppendLine( "There are no failed exceptions in the Asserts.") Log.LogMessage(type, message.ToString().TrimEnd())
def log_message(self, messageType, message, args): # If the message level is greater that the current log level then do not log it. if (Logger.should_message_be_logged(messageType)): # Log the message # lock (this.FileLock): date = datetime.now().strftime(Logger.DEFAULTDATEFORMAT) #date = dateTime.now().UtcNow()ToString(Logger.DEFAULTDATEFORMAT, CultureInfo.InvariantCulture); writer = [] try: #using (StreamWriter writer = new StreamWriter(this.FilePath, true)): # Set the style writer.append(get_text_with_color_flag(messageType)) # Add the content writer.WriteLine( StringProcessor.SafeFormatter("{0}{1}", os.linesep, date)) writer.Write( StringProcessor.SafeFormatter("{0}:\t", messageType.ToString())) writer.WriteLine(StringProcessor.SafeFormatter(message, args)) # Close off the style writer.Write("</p>") # Close the pre tag when logging Errors if (messageType == "ERROR"): writer.Write("</pre>") except Exception as e: # Failed to write to the event log, write error to the console instead console = ConsoleLogger() console.LogMessage( MessageType.ERROR, StringProcessor.SafeFormatter( "Failed to write to event log because: {0}", e.message)) console.LogMessage(messageType, message, args)