예제 #1
0
        public static CustomChromeDriver Build(ChromeOptions profile, TimeSpan commandTimeout)
        {
            CustomChromeDriver  driver  = null;
            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            service.SuppressInitialDiagnosticInformation = false;
            var result = Task.Factory.StartNew(() => {
                CustomChromeDriver drv = null;
                try
                {
                    drv = new CustomChromeDriver(service, profile, commandTimeout);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Can not create driver: " + ex.Message);
                }
                return(drv);
            });

            if (result.Wait(TimeSpan.FromSeconds(15)))
            {
                driver           = result.Result;
                driver.driverPid = service.ProcessId;
            }
            else
            {
                if (service.ProcessId > 0)
                {
                    KillProcessAndChildren(service.ProcessId);
                }
            }
            //driver = new CustomChromeDriver(service, profile, commandTimeout);
            return(driver);
        }
예제 #2
0
        public static CustomChromeDriver BuildOld(ChromeOptions profile, TimeSpan commandTimeout)
        {
            CustomChromeDriver driver = null;
            bool lockWasTaken         = false;

            try {
                Monitor.TryEnter(_buildLock, TimeSpan.FromSeconds(5).Milliseconds, ref lockWasTaken); {
                    // catch and story chromedriver pid
                    IList <int> pidsBefore = getProcessDrivers(Process.GetCurrentProcess().Id);
                    driver = new CustomChromeDriver(profile, commandTimeout);
                    IList <int> pidsAfter = getProcessDrivers(Process.GetCurrentProcess().Id);
                    IList <int> rest      = pidsAfter.Except(pidsBefore).ToList();
                    driver.driverPid = rest.DefaultIfEmpty(-1).First();
                }
            }
            finally {
                if (lockWasTaken)
                {
                    Monitor.Exit(_buildLock);
                }
            }
            return(driver);

            //CustomChromeDriver driver = null;
            //lock (_buildLock) {
            //    // catch and story chromedriver pid
            //    IList<int> pidsBefore = getProcessDrivers(Process.GetCurrentProcess().Id);
            //    driver = new CustomChromeDriver(profile, commandTimeout);
            //    IList<int> pidsAfter = getProcessDrivers(Process.GetCurrentProcess().Id);
            //    IList<int> rest = pidsAfter.Except(pidsBefore).ToList();
            //    driver.driverPid = rest.DefaultIfEmpty(-1).First();
            //}
            //return driver;
        }
예제 #3
0
        static private IBrowserSession CreateChromeAdapter(BrowserSettings settings)
        {
            var options = new ChromeOptions();

            options.AddArgument("window-size=1280,768");
            //options.AddArgument("disable-popup-blocking");
            options.AddArgument("disable-3d-apis");
            options.AddArgument("disable-gpu");
            // chrome_options.add_argument("--profile-directory=Profile1")
            string pathToCurrentUserProfiles = Environment.ExpandEnvironmentVariables("%TEMP%") + @"\chrome_selenium_etsy"; // + indx.ToString();

            indx++;
            options.AddArgument("user-data-dir=" + pathToCurrentUserProfiles);
            if (settings.PluginFileName != null)
            {
                options.AddExtension(settings.PluginFileName);
            }
            options.AddArgument("sidfordelete=" + new Random().Next());
            var webDriver = CustomChromeDriver.Build(options, TimeSpan.FromSeconds(settings.CommandTimeout));

            return(new ChromeBrowserSession(webDriver).Configure(settings));
        }