public void TestScreenShotWorksForBrowserInOlderDoctypePage()
        {
            if (_browserType == BrowserType.Safari)
                Assert.Ignore("This test is irrelevant for Safari");

            string screenshot = String.Empty;

            try
            {
                _browser.NavigateBrowser(getTestPage("OlderDoctypePage.htm"));

                SWAT.ErrorSnapShot test = new SWAT.ErrorSnapShot(GetBrowserObject() as IDocumentInfo, _browserType);
                screenshot = test.CaptureBrowser(@"C:\SWAT\trunk\SWAT.Tests\TestPages\", "FakeCommand", this.GetContentHandle(GetBrowserObject()));

                Assert.IsTrue(File.Exists(screenshot.Substring(22)), "Browser screenshot was not created.");
            }
            finally
            {
                // Clean up
                if (!String.IsNullOrEmpty(screenshot))
                    File.Delete(screenshot.Substring(22));
                this.NavigateToSwatTestPage();
            }
        }
        public void TestScreenShotCaptureBrowserAllScreensFailedTest()
        {
            if (_browserType == BrowserType.Safari)
                Assert.Ignore("This test is irrelevant for Safari");

            this.NavigateToSwatTestPage();
            SWAT.ErrorSnapShot capture = new SWAT.ErrorSnapShot(GetBrowserObject() as IDocumentInfo, _browserType);
            string returnValue = capture.CaptureBrowser("C:\test", "Any Command", this.GetContentHandle(GetBrowserObject())); // this will fail because is not a folder and return an error message.

            Assert.AreEqual("Illegal characters in path.", returnValue);

            string filePath = @"C:\SWAT\trunk\SWAT.Tests\TestPages\";
            string command = "ConnectToMssql";
            string expected = string.Format("ScreenShot was not taken because \"{0}\" does not require an interface.", command);

            returnValue = capture.CaptureBrowser(filePath, command, this.GetContentHandle(GetBrowserObject()));

            Assert.AreEqual(expected, returnValue);  
        }
        public void TestScreenShotForDocumentFailsWhenNoHandleExists()
        {
            SWAT.ErrorSnapShot test = new SWAT.ErrorSnapShot(_browser as IDocumentInfo, BrowserType.FireFox);

            string imageSave = string.Empty;
            try
            {
                imageSave = test.CaptureBrowser(@"C:\SWAT\trunk\SWAT.Tests\TestPages\", "Test", IntPtr.Zero);
            }
            finally
            {
                if (File.Exists(imageSave))
                    File.Delete(imageSave.Substring(22));
            }
        }
 public void TestScreenShotAllScreensIsNotTakenForCommand(String command)
 {
     SWAT.ErrorSnapShot test = new SWAT.ErrorSnapShot();
     string imageSave = test.CaptureAllScreens(@"C:\SWAT\trunk\SWAT.Tests\TestPages\", command);
     //We want to make sure that no file was save.
     Assert.IsTrue(!File.Exists(imageSave.Substring(18)), "File not was created and screen shots is working for non-GUI commands.");
 }
 public void TestScreenShotWorksForAllScreens()
 {
     SWAT.ErrorSnapShot test = new SWAT.ErrorSnapShot();
     string imageSave = test.CaptureAllScreens(@"C:\SWAT\trunk\SWAT.Tests\TestPages\", "Test");
     //Want to make sure that the file was saved.
     Assert.IsTrue(File.Exists(imageSave.Substring(22)), imageSave.Substring(18) + "      No file was created and screen shots is not working for all screens.");
     File.Delete(imageSave.Substring(22));
 }
 public void TestScreenShotCaptureAllScreensFailed()
 {
     SWAT.ErrorSnapShot capture = new SWAT.ErrorSnapShot();
     string returnValue = capture.CaptureAllScreens("C:\test", "Any Command"); // this will fail because is not a folder and return an error message.
     Assert.AreEqual(returnValue, "Illegal characters in path.");
 }
        public virtual string TakeScreenshot(string filePrefix)
        {
            string image = "";

            if (SWAT.ScreenShotSettings.SnapShotOption == true)
            {
                //Handles scenario where SnapShotFolder is set using "DriveLetter:\" instead of "\\MacineName\DriveLetter$\".
                //This occurs if user's SWAT.user.config file originated from an older version of SWAT where the SnapShotFolder
                //setting was not checking and updating the format of the folder's path.
                if (SWAT.ScreenShotSettings.SnapShotFolder.Contains(@":"))
                {
                    //Uses the logic from the SnapShotFolder's set method to correctly format the SnapShotFolder path
                    SWAT.ScreenShotSettings.SnapShotFolder = SWAT.ScreenShotSettings.SnapShotFolder;
                    SWAT.UserConfigHandler.Save();
                }
                if (SWAT.ScreenShotSettings.ScreenShotAllScreens == true)
                {
                    SWAT.ErrorSnapShot capture = new SWAT.ErrorSnapShot();
                    image = capture.CaptureAllScreens(SWAT.ScreenShotSettings.SnapShotFolder, filePrefix);
                }
                if (SWAT.ScreenShotSettings.ScreenShotBrowser == true)
                {
                    try
                    {
                        SWAT.ErrorSnapShot capture = new SWAT.ErrorSnapShot(this as IDocumentInfo, browserType);
                        image = capture.CaptureBrowser(SWAT.ScreenShotSettings.SnapShotFolder, filePrefix, GetContentHandle());
                    }
                    catch
                    {
                        image = "Unable to take picture since no browser and/or document was present.";
                    }
                }
            }
            return image;
        }