Esempio n. 1
0
        /// <inheritdoc />
        public void ReleaseBrowser(BrowserAbstract browser)
        {
            // This method is not expected to leak any predictable WebDriver exceptions.
            if (browser == null)
            {
                return;
            }

            FiddlerProxy.ClearHeaders(browser.ProcessId);

            try
            {
                // cleanup the previous state
                browser.DeleteAllCookies();

                // Selenium issue: must navigate away from page after cleaning up cookies otherwise some cookies will persist.
                browser.NavigateTo(browser.DefaultPage);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // suppress any exceptions while removing cookies.
                // If there is a problem, the browser will be marked as Faulted and handled in the next block.
            }

            if (this.browserPools.ContainsKey(browser.BrowserType) &&
                !this.browserPools[browser.BrowserType].PoolContains(browser))
            {
                // put the browser back in rotation
                this.browserPools[browser.BrowserType].ReleaseBrowser(browser);
            }
        }
Esempio n. 2
0
        public void AsposePrintToolServices()
        {
            Logger.LogMethodEntry("Component", "AsposePrintToolServices",
                                  base.IsTakeScreenShotDuringEntryExit);



            try
            {
                IWebElement print = base.GetWebElementPropertiesById("ibtnOk");
                //Thread.Sleep(2000);
                int returnedcode = FiddlerProxy.ClickNavigate(print);
                //Thread.Sleep(2000);
                Assert.AreEqual(200, returnedcode);
            }



            catch (Exception e)
            {
                ExceptionHandler.HandleException(e);
            }

            Logger.LogMethodExit("Component", " AsposePrintToolServices",
                                 base.IsTakeScreenShotDuringEntryExit);
        }
Esempio n. 3
0
        /// <summary>
        /// Cleanup fiddler and browser instances.
        /// </summary>
        internal static void Cleanup()
        {
            FiddlerProxy.Cleanup(Constants.FiddlerPort);
            ((BrowserManager)ObjectResolver.Resolve <IBrowserManager>()).Dispose();

            TestSetupHelpers.CleanupProcess(Constants.ChromeDriver);
        }
Esempio n. 4
0
 public static void StartBrowserProxy()
 {
     FiddlerProxy.Start();
     WinInetInterop.SetConnectionProxy(string.Concat(new object[]
     {
         "127.0.0.1",
         ":",
         "7777"
     }));
 }
Esempio n. 5
0
        public void Start()
        {
            switch (BaseConfiguration.TestBrowser)
            {
            case BrowserType.Firefox:
                var fireFoxOptionsLegacy = new FirefoxOptions {
                    Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation
                };
                this.driver = new FirefoxDriver(fireFoxOptionsLegacy);
                break;

            case BrowserType.FirefoxPortable:
                var fireFoxOptions = new FirefoxOptions {
                    BrowserExecutableLocation = BaseConfiguration.FirefoxPath, Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation
                };
                this.driver = new FirefoxDriver(fireFoxOptions);
                break;

            case BrowserType.InternetExplorer:
                this.driver = new InternetExplorerDriver(this.InternetExplorerProfile);
                break;

            case BrowserType.Chrome:
                this.driver = new ChromeDriver(this.ChromeProfile);
                break;

            case BrowserType.Safari:
                this.driver = new SafariDriver(this.SafariProfile);
                break;

            //case BrowserType.PhantomJs:
            //this.driver = new PhantomJSDriver(this.CurrentDirectory + BaseConfiguration.PhantomJsPath);
            //break;
            //case BrowserType.RemoteWebDriver:
            //this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetCapabilities());
            //break;
            default:
                throw new NotSupportedException(
                          string.Format(CultureInfo.CurrentCulture, "Driver {0} is not supported", BaseConfiguration.TestBrowser));
            }

            this.driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(BaseConfiguration.LongTimeout);
            this.driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(BaseConfiguration.ShortTimeout);
            this.driver.Manage().Timeouts().ImplicitWait           = TimeSpan.FromMilliseconds(BaseConfiguration.ImplicitlyWaitMilliseconds);

            //if (BaseConfiguration.EnableEventFiringWebDriver)
            //{
            //    this.driver = new MyEventFiringWebDriver(this.driver);
            //}

            this.fiddler  = new FiddlerProxy();
            this.ngDriver = new NgWebDriver(this.driver);
            this.mongo    = new MongoDriver(this);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the PluginTestBase class.
        /// </summary>
        public PluginTestBase()
        {
            FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
            if (!hasBeenInitialized)
            {
                Initialize();
                hasBeenInitialized = true;
            }

            this.Context = new Context();
        }
Esempio n. 7
0
        /// <summary>
        /// Browser proxy injects mandatory headers implementation.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsMandatoryHeadersImplementation(BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new[] { "TestKey:TestValue" }, Constants.FiddlerPort);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("TestKey : TestValue");
                }

                // turn off the proxy and make sure the header is not injected
                FiddlerProxy.Initialize(new string[0], 0);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldNotContain("TestKey : TestValue");
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
                FiddlerProxy.Cleanup(0);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Returns an instance of Firefox based driver.
        /// </summary>
        /// <returns>FireFox based driver</returns>
        private static IWebDriver FireFoxWebDriver()
        {
            // Proxy setup starts here
            OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();

            //start fiddler and get the port used
            int proxyport = FiddlerProxy.StartFiddlerProxy(0);

            //use SslProxy for https sites
            proxy.SslProxy = string.Format("127.0.0.1:{0}", proxyport);


            FirefoxProfile profile = new FirefoxProfile();

            profile.AssumeUntrustedCertificateIssuer = false;
            // get Log Execution Path
            String getExecutingPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;

            // set profile preferences
            profile.SetPreference("FireFox" + DateTime.Now.Ticks + ".log", getExecutingPath);
            profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
            profile.SetPreference("browser.download.folderList", 2);
            profile.SetPreference("browser.download.dir", AutomationConfigurationManager.DownloadFilePath.Replace("file:\\", ""));
            profile.SetPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
            profile.SetPreference("browser.download.useDownloadDir", true);
            profile.SetPreference("browser.download.downloadDir", AutomationConfigurationManager.DownloadFilePath.Replace("file:\\", ""));
            profile.SetPreference("browser.download.defaultFolder", AutomationConfigurationManager.DownloadFilePath.Replace("file:\\", ""));
            profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
            profile.EnableNativeEvents = true;
            profile.SetPreference("browser.cache.disk.enable", false);
            profile.SetPreference("browser.cache.memory.enable", false);
            profile.SetPreference("browser.cache.offline.enable", false);
            profile.SetPreference("network.http.use-cache", false);
            //set proxyperference
            profile.SetProxyPreferences(proxy);
            //to be sure that it picks up 32bit of ff always
            string        sBrowserExe = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
            FirefoxBinary Bin         = new FirefoxBinary(sBrowserExe);
            IWebDriver    webDriver   = new FirefoxDriver();

            // set page load duration
            webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(TimeOut));
            // set cursor position center of the screen
            Cursor.Position = new Point(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            return(webDriver);
        }
Esempio n. 9
0
        public void TestFiddlerProxySessionFingerprint()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();
            const BrowserType BrowserType = BrowserType.Chrome;

            var browserInstances = new Dictionary <BrowserType, int> {
                { BrowserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(BrowserType);

                    // expected headers for this browser process
                    FiddlerProxy.RegisterInstanceHeaders(
                        browser.ProcessId,
                        "My User Agent 1.0",
                        "TestKey: Process" + browser.ProcessId);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                    browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);

                    var fiddlerResponseSessionKey = Library.Constants.FiddlerResponseSessionKey.FormatIc(
                        browser.ProcessId,
                        browser.Url);

                    // validate the proxy session fingerprint
                    var fiddlerSession = FiddlerProxy.ResponseSession[fiddlerResponseSessionKey];
                    fiddlerSession.bHasResponse.ShouldBeTrue();
                    fiddlerSession.ResponseBody.Length.ShouldBeGreaterThan(0);
                    fiddlerSession.oResponse.headers.Count().ShouldBeGreaterThan(0);
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Fiddler reporting the wrong
        /// browser process Id when more than one instance of Chrome was present. Here we test explicitly
        /// for that circumstance across all browsers.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsPerRequestHeadersMultipleImplementation(
            BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 3 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var browser = manager.AcquireBrowser(browserType);

                        // expected headers for this browser process
                        FiddlerProxy.RegisterInstanceHeaders(
                            browser.ProcessId,
                            "My User Agent 1.0",
                            "TestKey: Process" + browser.ProcessId);

                        browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                        browser.WaitForPageLoad(10);

                        // Then the expected request header should be present in the page
                        browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                        browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);
                    }
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
Esempio n. 11
0
 public static void ClassCleanup()
 {
     FiddlerProxy.Cleanup(Constants.FiddlerPort);
 }
Esempio n. 12
0
        public static void ClassInit(TestContext testContext)
        {
            FiddlerProxy.Cleanup(Constants.FiddlerPort);

            CreateFirewallRules();
        }
 /// <summary>
 /// Clean the WebDriver.
 /// </summary>
 public void WebDriverCleanUp()
 {
     WebDriverSingleton.GetInstance().Cleanup();
     FiddlerProxy.StopFiddlerProxy();
 }