Powered By Blogger

Search Here!

Showing posts with label Create Logging In Webdriver. Show all posts
Showing posts with label Create Logging In Webdriver. Show all posts

Sunday, June 16, 2013

Create Logging In Webdriver !

private static IWebDriver IEWebDriver()
        {
            //Get The Machine Processor Architecture
            String getProcessorArchitecture = Microsoft.Win32.Registry.GetValue(
                "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
                , "PROCESSOR_ARCHITECTURE", null).ToString();
            //Get IE Driver Path
            String getIeDriverPath =
                (Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
                + "\\..\\..\\..\\..\\ExternalAssemblies\\" + ((getProcessorArchitecture == "x86") ? "x86" : "x64")).Replace("file:\\", "");
            //Start Internet Explorer Driver Service
            InternetExplorerDriverService ieservice = InternetExplorerDriverService.CreateDefaultService(getIeDriverPath);
            ieservice.LoggingLevel = InternetExplorerDriverLogLevel.Trace;
            //Get Log Execution Path
            String getExecutingPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
            ieservice.LogFile = Path.Combine(getExecutingPath, "Log", "IEDriver" + DateTime.Now.Ticks + ".log");
            //Set Internet Explorer Options
            InternetExplorerOptions options = new InternetExplorerOptions
                                                  {
                                                      IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                                                      UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore,
                                                      IgnoreZoomLevel = true,
                                                      EnableNativeEvents = true,
                                                      RequireWindowFocus = true,
                                                  };
            //Create Internet Explorer Driver Object
            IWebDriver webDriver = new InternetExplorerDriver(ieservice, options, TimeSpan.FromMinutes(20));
            //Set WebDriver Page Load Time
            webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(timeOut));
            //Set The Cursor Position Center of the Screen
            Cursor.Position = new Point(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            return webDriver;
        }