Ejemplo n.º 1
0
        /// <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 <IWebElement> appiumDriver, AppiumTestObject testObject, string appendName = "")
        {
            try
            {
                string path = string.Empty;

                // Check if we are using a file logger
                if (!(testObject.Log is FileLogger))
                {
                    // Since this is not a file logger we will need to use a generic file name
                    path = SavePageSource(appiumDriver, testObject, LoggingConfig.GetLogDirectory(), "PageSource" + appendName);
                }
                else
                {
                    // Calculate the file name
                    string fullpath  = ((FileLogger)testObject.Log).FilePath;
                    string directory = Path.GetDirectoryName(fullpath);
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullpath) + "_PS" + appendName;

                    path = SavePageSource(appiumDriver, testObject, directory, fileNameWithoutExtension);
                }

                testObject.Log.LogMessage(MessageType.INFORMATION, "Page Source saved: " + path);
                return(true);
            }
            catch (Exception exception)
            {
                testObject.Log.LogMessage(MessageType.ERROR, "Page Source error: {0}", exception.ToString());
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <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 <IWebElement> appiumDriver, AppiumTestObject testObject, string appendName = "")
        {
            try
            {
                if (!(testObject.Log is FileLogger))
                {
                    return(false);
                }

                string fullpath  = ((FileLogger)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: {0}", exception.ToString());
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <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 <IWebElement> appiumDriver, AppiumTestObject 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);
        }
Ejemplo n.º 4
0
        /// <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 <IWebElement> appiumDriver, AppiumTestObject 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);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyMobileElement" /> class
 /// </summary>
 /// <param name="testObject">The base Appium test object</param>
 /// <param name="locator">The 'by' selector for the element</param>
 /// <param name="userFriendlyName">A user friendly name, for logging purposes</param>
 public LazyMobileElement(AppiumTestObject testObject, By locator, [CallerMemberName] string userFriendlyName = null) : base(testObject, testObject.AppiumDriver, () => testObject.AppiumDriver.GetWaitDriver(), locator, userFriendlyName)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyMobileElement" /> class
 /// </summary>
 /// <param name="testObject">The base Selenium test object</param>
 /// <param name="locator">The 'by' selector for the element</param>
 /// <param name="userFriendlyName">A user friendly name, for logging purposes</param>
 /// <example>
 /// <code source = "../SeleniumUnitTesting/LazyElementUnitTests.cs" region="LazyElementCreate" lang="C#" />
 /// </example>
 public LazyMobileElement(AppiumTestObject testObject, By locator, string userFriendlyName = "LazyMobileElement")
 {
     this.TestObject       = testObject;
     this.By               = locator;
     this.userFriendlyName = userFriendlyName;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the AppiumSoftAssert class
 /// </summary>
 /// <param name="appiumTestObject">The related Appium test object</param>
 public AppiumSoftAssert(AppiumTestObject appiumTestObject)
     : base(appiumTestObject.Log)
 {
     this.appiumTestObject = appiumTestObject;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseAppiumPageModel"/> class.
 /// </summary>
 /// <param name="testObject">The Appium test object</param>
 protected BaseAppiumPageModel(AppiumTestObject testObject)
 {
     this.TestObject       = testObject;
     this.AppiumDriver     = testObject.AppiumDriver;
     this.lazyElementStore = new Dictionary <string, LazyMobileElement>();
 }