/// <summary> /// Soft assert method to check if the files are equal /// </summary> /// <param name="expectedText">Expected text</param> /// <param name="actualText">Actual text</param> /// <param name="softAssertName">Soft assert name</param> /// <param name="message">Exception message if desired</param> /// <returns>Boolean if the assert is true</returns> public override bool AreEqual(string expectedText, string actualText, string softAssertName, string message = "") { bool didPass = base.AreEqual(expectedText, actualText, softAssertName, message); if (!didPass && this.appiumTestObject.GetDriverManager <MobileDriverManager>().IsDriverIntialized()) { if (AppiumConfig.GetSoftAssertScreenshot()) { AppiumUtilities.CaptureScreenshot(this.appiumTestObject.AppiumDriver, this.appiumTestObject, this.TextToAppend(softAssertName)); } if (AppiumConfig.GetSavePagesourceOnFail()) { AppiumUtilities.SavePageSource(this.appiumTestObject.AppiumDriver, this.appiumTestObject, StringProcessor.SafeFormatter(" ({0})", this.NumberOfAsserts)); } return(false); } else if (!didPass) { return(false); } return(true); }
/// <summary> /// Soft assert method to check if the Action is false /// </summary> /// <param name="assertFunction">Function to use</param> /// <param name="failureMessage">Message to log</param> /// <param name="assertName">Soft assert name or name of expected assert being called.</param> /// <returns>Boolean of the assert</returns> public override bool Assert(Action assertFunction, string assertName, string failureMessage = "") { bool didPass = base.Assert(assertFunction, assertName, failureMessage); if (!didPass && this.appiumTestObject.GetDriverManager <AppiumDriverManager>().IsDriverIntialized()) { if (AppiumConfig.GetSoftAssertScreenshot()) { AppiumUtilities.CaptureScreenshot(this.appiumTestObject.AppiumDriver, this.appiumTestObject, this.TextToAppend(assertName)); } if (AppiumConfig.GetSavePagesourceOnFail()) { AppiumUtilities.SavePageSource(this.appiumTestObject.AppiumDriver, this.appiumTestObject, $" ({ this.NumberOfAsserts})"); } return(false); } return(didPass); }
/// <summary> /// Take a screen shot if needed and tear down the appium driver /// </summary> /// <param name="resultType">The test result</param> protected override void BeforeLoggingTeardown(TestResultType resultType) { try { // Captures screenshot if test result is not a pass and logging is enabled if (this.TestObject.GetDriverManager <MobileDriverManager>().IsDriverIntialized() && this.Log is FileLogger && resultType != TestResultType.PASS && this.LoggingEnabledSetting != LoggingEnabled.NO) { AppiumUtilities.CaptureScreenshot(this.AppiumDriver, this.TestObject); if (AppiumConfig.GetSavePagesourceOnFail()) { AppiumUtilities.SavePageSource(this.AppiumDriver, this.TestObject, "FinalPageSource"); } } } catch (Exception exception) { this.TryToLog(MessageType.WARNING, "Failed to get screen shot because: {0}", exception.Message); } }