/// <summary> /// To capture a page source during execution /// </summary> /// <param name="appiumDriver">The AppiumDriver</param> /// <param name="testObject">The TestObject to associate the file and log with</param> /// <param name="appendName">Appends a name to the end of a filename</param> /// <returns>Boolean if the save of the page source was successful</returns> public static bool SavePageSource(this AppiumDriver appiumDriver, IAppiumTestObject testObject, string appendName = "") { try { string path = string.Empty; // Check if we are using a file logger if (testObject.Log is IFileLogger logger) { // Calculate the file name string fullpath = logger.FilePath; string directory = Path.GetDirectoryName(fullpath); string fileNameWithoutExtension = $"{Path.GetFileNameWithoutExtension(fullpath)}_PS{appendName}"; path = SavePageSource(appiumDriver, testObject, directory, fileNameWithoutExtension); } else { // Since this is not a file logger we will need to use a generic file name path = SavePageSource(appiumDriver, testObject, LoggingConfig.GetLogDirectory(), $"PageSource{appendName}"); } testObject.Log.LogMessage(MessageType.INFORMATION, $"Page Source saved: {path}"); return(true); } catch (Exception exception) { testObject.Log.LogMessage(MessageType.ERROR, $"Page Source error: {exception}"); return(false); } }
/// <summary> /// To capture Page Source during execution /// </summary> /// <param name="appiumDriver">The AppiumDriver</param> /// <param name="testObject">The TestObject to associate the file and log with</param> /// <param name="directory">The directory file path</param> /// <param name="fileNameWithoutExtension">Filename without extension</param> /// <returns>Path to the log file</returns> public static string SavePageSource(this AppiumDriver appiumDriver, IAppiumTestObject testObject, string directory, string fileNameWithoutExtension) { // Save the current page source into a string string pageSource = appiumDriver.PageSource; // Make sure the directory exists if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // Calculate the file name string path = Path.Combine(directory, $"{fileNameWithoutExtension}.txt"); // Create new instance of Streamwriter and Auto Flush after each call StreamWriter writer = new StreamWriter(path, false) { AutoFlush = true }; // Write page source to a new file writer.Write(pageSource); writer.Close(); testObject.AddAssociatedFile(path); return(path); }
/// <summary> /// To capture a screenshot during execution /// </summary> /// <param name="appiumDriver">The AppiumDriver</param> /// <param name="testObject">The TestObject to associate the screenshot with</param> /// <param name="directory">The directory file path</param> /// <param name="fileNameWithoutExtension">Filename without extension</param> public static void CaptureScreenshot(this AppiumDriver appiumDriver, IAppiumTestObject testObject, string directory, string fileNameWithoutExtension) { Screenshot screenshot = ((ITakesScreenshot)appiumDriver).GetScreenshot(); string path = Path.Combine(directory, $"{fileNameWithoutExtension}.Png"); screenshot.SaveAsFile(path, ScreenshotImageFormat.Png); testObject.AddAssociatedFile(path); }
/// <summary> /// To capture a screenshot during execution /// </summary> /// <param name="appiumDriver">The AppiumDriver</param> /// <param name="testObject">The TestObject to associate the screenshot with</param> /// <param name="appendName">Appends a name to the end of a filename</param> /// <returns>Boolean if the save of the image was successful</returns> public static bool CaptureScreenshot(this AppiumDriver appiumDriver, IAppiumTestObject testObject, string appendName = "") { try { if (!(testObject.Log is IFileLogger)) { return(false); } string fullpath = ((IFileLogger)testObject.Log).FilePath; string directory = Path.GetDirectoryName(fullpath); string fileNameWithoutExtension = $"{Path.GetFileNameWithoutExtension(fullpath)}{appendName}"; CaptureScreenshot(appiumDriver, testObject, directory, fileNameWithoutExtension); testObject.Log.LogMessage(MessageType.INFORMATION, "Screenshot saved"); return(true); } catch (Exception exception) { exception = exception.InnerException ?? exception; testObject.Log.LogMessage(MessageType.ERROR, $"Screenshot error: {exception}"); return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="IOSLoginPageModel" /> class. /// </summary> /// <param name="testObject">The appium test object</param> public IOSLoginPageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="IOSHomePageModel" /> class. /// </summary> /// <param name="testObject">The appium test object</param> public IOSHomePageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="BaseAppiumPageModel"/> class. /// </summary> /// <param name="testObject">The Appium test object</param> protected BaseAppiumPageModel(IAppiumTestObject testObject) { this.TestObject = testObject; this.AppiumDriver = testObject.AppiumDriver; this.lazyElementStore = new Dictionary <string, LazyMobileElement>(); }
/// <summary> /// Initializes a new instance of the <see cref="AHomePageModel"/> class /// </summary> /// <param name="testObject">The base Appium test object</param> protected AHomePageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="ALoginPageModel"/> class /// </summary> /// <param name="testObject">The base Appium test object</param> protected ALoginPageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="LazyMobileElement" /> class /// </summary> /// <param name="testObject">The base Appium test object</param> /// <param name="appiumDriver">The Appium driver</param> /// <param name="locator">The 'by' selector for the element</param> /// <param name="userFriendlyName">A user friendly name, for logging purposes</param> public LazyMobileElement(IAppiumTestObject testObject, AppiumDriver appiumDriver, By locator, [CallerMemberName] string userFriendlyName = null) : base(testObject, appiumDriver, () => appiumDriver.GetWaitDriver(), locator, userFriendlyName) { }
/// <summary> /// Initializes a new instance of the AppiumSoftAssert class /// </summary> /// <param name="appiumTestObject">The related Appium test object</param> public AppiumSoftAssert(IAppiumTestObject appiumTestObject) : base(appiumTestObject.Log) { this.appiumTestObject = appiumTestObject; }
/// <summary> /// Initializes a new instance of the <see cref="AndroidLoginPageModel" /> class. /// </summary> /// <param name="testObject">The appium test object</param> public AndroidLoginPageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="AndroidHomePageModel" /> class. /// </summary> /// <param name="testObject">The appium test object</param> public AndroidHomePageModel(IAppiumTestObject testObject) : base(testObject) { }
/// <summary> /// Initializes a new instance of the <see cref="SeleniumPageModel"/> class /// </summary> /// <param name="testObject">The base Appium test object</param> public NotepadPageModel(IAppiumTestObject testObject) : base(testObject) { }