Show
Ignore:
Timestamp:
08/14/08 13:15:20 (4 months ago)
Author:
bhenderson
Message:

Updated using WatiN and added Firefox 2.0 Functionality

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation.sln

    r1675 r1733  
    66Global 
    77    GlobalSection(SolutionConfigurationPlatforms) = preSolution 
     8        AutomatedDebug|Any CPU = AutomatedDebug|Any CPU 
    89        Debug|Any CPU = Debug|Any CPU 
    910        Release|Any CPU = Release|Any CPU 
    1011    EndGlobalSection 
    1112    GlobalSection(ProjectConfigurationPlatforms) = postSolution 
     13        {2D920B27-1608-408C-8339-68EC491F3A64}.AutomatedDebug|Any CPU.ActiveCfg = Debug|Any CPU 
     14        {2D920B27-1608-408C-8339-68EC491F3A64}.AutomatedDebug|Any CPU.Build.0 = Debug|Any CPU 
    1215        {2D920B27-1608-408C-8339-68EC491F3A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 
    1316        {2D920B27-1608-408C-8339-68EC491F3A64}.Debug|Any CPU.Build.0 = Debug|Any CPU 
  • honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/Automation.cs

    r1698 r1733  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Diagnostics; 
    34using System.Linq; 
    45using System.Text; 
     
    1415        private static IE ie; 
    1516        private static Firefox firefox; 
     17        private static Process[] myOpenFirefoxs; 
    1618 
    1719        /// <summary> 
     
    3133                if (args[0].Equals("firefox")) 
    3234                { 
     35                    myOpenFirefoxs = Process.GetProcessesByName("firefox"); 
     36                    foreach (Process myOpenFirefox in myOpenFirefoxs) 
     37                    { 
     38                        myOpenFirefox.Kill(); 
     39                    } 
    3340                    firefox = new Firefox(args[1]); 
    3441                } 
  • honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/BrowserAutomation.csproj

    r1699 r1733  
    3232  </PropertyGroup> 
    3333  <ItemGroup> 
     34    <Reference Include="Interop.SHDocVw, Version=1.1.0.0, Culture=neutral"> 
     35      <SpecificVersion>False</SpecificVersion> 
     36      <HintPath>..\References\Interop.SHDocVw.dll</HintPath> 
     37    </Reference> 
    3438    <Reference Include="System" /> 
    3539    <Reference Include="System.Core"> 
     
    4448    <Reference Include="System.Data" /> 
    4549    <Reference Include="System.Xml" /> 
     50    <Reference Include="WatiN.Core, Version=2.0.0.1000, Culture=neutral, processorArchitecture=MSIL"> 
     51      <SpecificVersion>False</SpecificVersion> 
     52      <HintPath>..\References\WatiN.Core.dll</HintPath> 
     53    </Reference> 
    4654  </ItemGroup> 
    4755  <ItemGroup> 
     
    5058    <Compile Include="Automation.cs" /> 
    5159    <Compile Include="Properties\AssemblyInfo.cs" /> 
    52   </ItemGroup> 
    53   <ItemGroup> 
    54     <COMReference Include="SHDocVw"> 
    55       <Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid> 
    56       <VersionMajor>1</VersionMajor> 
    57       <VersionMinor>1</VersionMinor> 
    58       <Lcid>0</Lcid> 
    59       <WrapperTool>tlbimp</WrapperTool> 
    60       <Isolated>False</Isolated> 
    61     </COMReference> 
    6260  </ItemGroup> 
    6361  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 
  • honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/IE.cs

    r1699 r1733  
    11using System; 
    2 using System.Collections.Generic; 
    32using System.Linq; 
    43using System.Text; 
    54using System.Threading; 
    6 using System.Diagnostics; 
    7 using SHDocVw; 
    8  
    9  
     5using WatiN.Core; 
    106 
    117namespace BrowserAutomation 
    128{ 
    13     /// <summary> 
    14     /// The IE class controls an instance of Internet Explorer 
    15     /// </summary> 
    169    class IE 
    1710    { 
    18         private SHDocVw.InternetExplorer internetExplorer; 
     11        private WatiN.Core.IE ie; 
     12        private Thread hardTimeoutThread; 
    1913        private Thread ieThread; 
     14        private bool started; 
    2015        private String url; 
    21         private object o; 
    22         private int unfinishedDownloads; 
    23         private int navigateCounter; 
    24         private bool completed; 
    2516        private DateTime startTime; 
    2617        private TimeSpan duration; 
    27         private Process[] myOpenIEs; 
    2818 
    2919        /// <summary> 
    30         /// Constructor for an instance of IE 
     20        /// Constructor for an instance of Firefox 
    3121        /// </summary> 
    3222        /// <param name="url">URL to be navigated to</param> 
     
    3424        { 
    3525            this.url = url; 
     26            started = false; 
     27            hardTimeoutThread = new Thread(new ThreadStart(HardTimeoutCallback)); 
    3628            ieThread = new Thread(new ThreadStart(IECallback)); 
    37             completed = false; 
    38             navigateCounter = 0; 
    39             unfinishedDownloads = 0; 
    40             internetExplorer = new SHDocVw.InternetExplorerClass(); 
    41             internetExplorer.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandler(this.navigationError); 
    42             internetExplorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.documentComplete); 
    43             internetExplorer.DownloadBegin += new DWebBrowserEvents2_DownloadBeginEventHandler(this.downloadBegin); 
    44             internetExplorer.DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(this.downloadComplete); 
    45             internetExplorer.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.beforeNavigate); 
    46             internetExplorer.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(this.navigateComplete); 
     29            ieThread.SetApartmentState(ApartmentState.STA); 
    4730            ieThread.Start(); 
     31            hardTimeoutThread.Start(); 
    4832        } 
    49          
     33 
     34        private void IECallback() 
     35        { 
     36            ie = new WatiN.Core.IE(); 
     37                
     38            ie.GoTo(url); 
     39            Thread.Sleep(1000); 
     40            ie.Close(); 
     41                 
     42            hardTimeoutThread.Abort(); 
     43            ieThread.Abort(); 
     44        } 
     45 
    5046        /// <summary> 
    51         /// This method will be called when the thread is started 
     47        ///  
    5248        /// </summary> 
    53         private void IECallback() 
     49        private void HardTimeoutCallback() 
    5450        { 
    5551            while (true) 
    5652            { 
    57                 if (url != null
     53                if (!started
    5854                { 
    59                     internetExplorer.Visible = true; 
    60                     internetExplorer.Navigate(url, ref o, ref o, ref o, ref o); 
    61                     url = null; 
     55                    started = true; 
    6256                    startTime = DateTime.Now; 
    6357                } 
     
    6559                duration = DateTime.Now - startTime; 
    6660 
    67                 if(duration.Seconds >= 30) 
     61                if (duration.Seconds >= 30) 
    6862                { 
    69                     myOpenIEs = Process.GetProcessesByName("iexplore"); 
    70                     foreach (Process myOpenIE in myOpenIEs) 
    71                     { 
    72                         myOpenIE.Kill(); 
    73                     } 
     63                    ie.Close(); 
    7464                    ieThread.Abort(); 
    75                 } 
    76                 else 
    77                 { 
    78                     if (completed && (unfinishedDownloads == 0) && !internetExplorer.Busy) 
    79                     { 
    80                         Thread.Sleep(2000); 
    81                         if (completed && (unfinishedDownloads == 0) && !internetExplorer.Busy) 
    82                         { 
    83                             Thread.Sleep(10000); 
    84                             internetExplorer.Quit(); 
    85                             ieThread.Abort(); 
    86                         } 
    87                     } 
     65                    hardTimeoutThread.Abort(); 
    8866                } 
    8967            } 
    9068        } 
    91  
    92         /// <summary> 
    93         /// This method is called when a Navigation Error event occurs 
    94         /// </summary> 
    95         /// <param name="pDisp"></param> 
    96         /// <param name="URL">The URL that caused the Navigation Error</param> 
    97         /// <param name="Frame"></param> 
    98         /// <param name="StatusCode">Status code of the Navigation Error (ex. 404, 501)</param> 
    99         /// <param name="Cancel"></param> 
    100         private void navigationError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel) 
    101         { 
    102              
    103         } 
    104  
    105         /// <summary> 
    106         /// This method is called when a Document Complete event occurs 
    107         /// </summary> 
    108         /// <param name="pDisp"></param> 
    109         /// <param name="URL">URL of the completed document</param> 
    110         private void documentComplete(object pDisp, ref object URL) 
    111         { 
    112             completed = true;   
    113         } 
    114  
    115         /// <summary> 
    116         /// This method is called when a Download Begins event occurs 
    117         /// Download Begins occurs every time the browser makes a valid  
    118         /// request for content form a server. 
    119         /// </summary> 
    120         private void downloadBegin() 
    121         { 
    122             unfinishedDownloads++; 
    123         } 
    124  
    125         /// <summary> 
    126         /// This method is called when a Download Complete event occurs 
    127         /// Download Complete occurs everytime the content downloaded after  
    128         /// a Download Begins is completed. 
    129         /// </summary> 
    130         private void downloadComplete() 
    131         { 
    132             unfinishedDownloads--; 
    133         } 
    134  
    135         /// <summary> 
    136         /// This method is event that is triggered before a URL is navigated to 
    137         /// A web page will usually make multiple requests to Navigate URLs 
    138         /// </summary> 
    139         /// <param name="pDisp"></param> 
    140         /// <param name="URL">URL to be navigated to</param> 
    141         /// <param name="Flags"></param> 
    142         /// <param name="TargetFrameName"></param> 
    143         /// <param name="PostData"></param> 
    144         /// <param name="Headers"></param> 
    145         /// <param name="Cancel"></param> 
    146         private void beforeNavigate(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) 
    147         { 
    148             if(!((String)URL).Equals("about:blank")) 
    149             { 
    150                 navigateCounter++; 
    151             } 
    152             completed = false; 
    153         } 
    154  
    155         /// <summary> 
    156         /// A Navigation Complete event occurs when the browser has finished navigating to 
    157         /// a URL. It seems that this event is not triggered for each beforeNavigate event. 
    158         /// It also seems that this event can be triggered more than once for each beforeNavigate 
    159         /// event. 
    160         /// </summary> 
    161         /// <param name="pDisp"></param> 
    162         /// <param name="URL">URL of the completed navigation</param> 
    163         private void navigateComplete(object pDisp, ref object URL) 
    164         { 
    165             navigateCounter--; 
    166         } 
    16769    } 
    16870} 
  • honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/obj/Debug/BrowserAutomation.csproj.FileListAbsolute.txt

    r1699 r1733  
    33D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\Interop.SHDocVw.dll 
    44D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\ResolveAssemblyReference.cache 
    5 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\Interop.SHDocVw.dll 
    6 D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.csproj.ResolveComReference.cache 
    75D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.exe 
    86D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\obj\Debug\BrowserAutomation.pdb 
     7D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\WatiN.Core.dll 
     8D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\nunit.framework.dll 
     9D:\Work\HoneyClient\BrowserAutomation\BrowserAutomation\bin\Debug\WatiN.Core.xml