Exemplo n.º 1
0
        public static void GoTo(IE browser, string url)
        {
            Client.WaitForTurn();
            browser.GoTo(url);
            while (((SHDocVw.InternetExplorerClass)(browser.InternetExplorer)).Busy || browser.Html == null)
            {
                System.Threading.Thread.Sleep(100);
            }
            bool upload = false;

            if (lastServerCommunicationTime == null)
            {
                lastServerCommunicationTime = DateTime.Now;
                upload = true;
            }
            else
            {
                TimeSpan timeSpan = DateTime.Now.Subtract((DateTime)lastServerCommunicationTime);
                if (timeSpan.Minutes <= 5)
                {
                    upload = false;
                }
                else
                {
                    upload = true;
                    lastServerCommunicationTime = DateTime.Now;
                }
            }
            if (upload)
            {
                browser.CaptureWebPageToFile("latest.jpg");
                Client.UploadScreenCapture();
            }
        }
Exemplo n.º 2
0
 public void WebPageToImageTest()
 {
     //Capture(null, null);
     using (var ie = new IE("http://watin.org/"))
     {
         ie.CaptureWebPageToFile(@"c:\temp\g1.jpg");
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a screen shot of the window given with the file name if check evaluates to false.
 /// </summary>
 /// <param name="check">The condition to assert.</param>
 /// <param name="screenShotFileName">The file name for the screen shot.</param>
 /// <param name="screenShotWindow">The window to take a screen shot of.</param>
 public void AssertIsTrue(bool check, string screenShotFileName, IE screenShotWindow)
 {
     if (!check)
     {
         if (File.Exists(Path.Combine(ScreenShotPartialPath, screenShotFileName)))
         {
             File.Delete(Path.Combine(ScreenShotPartialPath, screenShotFileName));
         }
         screenShotWindow.CaptureWebPageToFile(ScreenShotPartialPath + screenShotFileName);
         AppendToHtml(screenShotFileName, ScreenShotPartialPath);
     }
     Assert.IsTrue(check);
 }
 public void DoTestTeardown()
 {
     if (ie != null)
     {
         if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
         {
             ie.CaptureWebPageToFile(@"C:\Documents and Settings\All Users\Favorites.png");
         }
         ie.Close();
         ie.Dispose();
         ie = null;
     }
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            IE     ie  = null;
            String url = "http://localhost:8000/windows/pages/multipleframe.html";

            url = "baidu.com";
//            url = "sina.com";
            String file = "d:\\test2.png";

            Boolean debug = false;

            if (args.Length >= 2)
            {
                url  = args[0];
                file = args[1];
            }

            if (args.Length >= 3 && args[2] == "debug")
            {
                debug = true;
            }
            Console.WriteLine("Capture " + url + " to " + file);

            ie = new IE();

            ie.GoToNoWait(url);
            try
            {
                ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);


                Stream       s      = new FileStream("beidou_ad.user.js", FileMode.Open);
                StreamReader sr     = new StreamReader(s, Encoding.Default);
                String       script = sr.ReadToEnd().ToString();

                ie.WaitForComplete(30);

                Thread.Sleep(1000);

                ie.RunScript(script);

                if (debug)
                {
                    Stream       st = new FileStream("html.txt", FileMode.Create);
                    StreamWriter sw = new StreamWriter(st, Encoding.Default);
                    sw.Write(ie.Html);
                    sw.Close();
                    st.Close();
                }

                //插入截图判断逻辑

                ie.CaptureWebPageToFile(file);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (ie != null)
                {
                    int procId = ie.ProcessID;

                    foreach (Process thisproc in System.Diagnostics.Process.GetProcesses())
                    {
                        if (thisproc.Id == procId)
                        {
                            Execute("ntsd -c q -p " + procId, 1000);
                            break;
                        }
                    }
                }
            }
        }