/// <summary>
        /// Stops the driver services
        /// </summary>
        public void StopDriverServices()
        {
            if (EdgeService != null && EdgeService.IsRunning)
            {
                EdgeService.Dispose();
            }

            if (IEService != null && IEService.IsRunning)
            {
                IEService.Dispose();
            }

            if (ChromeService != null && ChromeService.IsRunning)
            {
                ChromeService.Dispose();
            }

            if (FirefoxService != null && FirefoxService.IsRunning)
            {
                FirefoxService.Dispose();
            }

            if (OperaService != null && OperaService.IsRunning)
            {
                OperaService.Dispose();
            }
        }
        /// <summary>
        /// Gets the capabilities for IE
        /// </summary>
        /// <param name="acceptSlefSignedSSL"></param>
        /// <param name="_ignoreZoomLevel"></param>
        /// <param name="_enableNativeEvents"></param>
        /// <param name="_ensureCleanSession"></param>
        /// <param name="browserTimeoutMilloseconds"></param>
        /// <param name="_scrollBehaviour"></param>
        /// <param name="_promtBehaviour"></param>
        /// <param name="_loadStrategy"></param>
        /// <returns></returns>
        private InternetExplorerOptions GetIEBrowserOptions(
            bool acceptSlefSignedSSL       = false,
            bool _ignoreZoomLevel          = true,
            bool _enableNativeEvents       = false,
            bool _ensureCleanSession       = false,
            int browserTimeoutMilloseconds = 300000,
            InternetExplorerElementScrollBehavior _scrollBehaviour = InternetExplorerElementScrollBehavior.Default,
            UnhandledPromptBehavior _promtBehaviour = UnhandledPromptBehavior.Default,
            PageLoadStrategy _loadStrategy          = PageLoadStrategy.Eager)
        {
            IEService = InternetExplorerDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"IEDriverServer.exe");
            IEService.LoggingLevel            = InternetExplorerDriverLogLevel.Trace;
            IEService.HideCommandPromptWindow = false;
            IEService.Start();

            return(new InternetExplorerOptions()
            {
                ElementScrollBehavior = _scrollBehaviour,
                EnableNativeEvents = _enableNativeEvents,
                IgnoreZoomLevel = _ignoreZoomLevel,
                ForceCreateProcessApi = false,
                ForceShellWindowsApi = true,
                EnablePersistentHover = true,
                FileUploadDialogTimeout = new TimeSpan(0, 0, 0, browserTimeoutMilloseconds),
                RequireWindowFocus = true,
                UnhandledPromptBehavior = _promtBehaviour,
                BrowserAttachTimeout = new TimeSpan(0, 0, 0, browserTimeoutMilloseconds),
                EnsureCleanSession = _ensureCleanSession,
                PageLoadStrategy = _loadStrategy,
                AcceptInsecureCertificates = acceptSlefSignedSSL
            });
        }
示例#3
0
 public FService(IEService e)
 {
     E = e;
 }
示例#4
0
        public static void TestV2()
        {
            IMyContainerV2 container = new MyContainerV2();

            container.AddScoped <IAService, AService>();
            container.AddTransient <IDService, DService>();
            container.AddSingleton <IDALService, MySqlDALServce>();
            container.AddPerThread <IEService, EService>();
            container.AddPerThread <IFService, FService>();

            int loop = 100;

            // test singleton and transient
            for (int i = 0; i < loop; i++)
            {
                Task <IDService> dTask  = Task.Run(() => container.Resolve <IDService>());
                Task <IDService> dTask2 = Task.Run(() => container.Resolve <IDService>());
                Task.WaitAll(dTask, dTask2); // blocking here
                IDService d  = dTask.Result;
                IDService d2 = dTask2.Result;

                // test singleton
                bool same = ReferenceEquals(d.DAL, d2.DAL); // should be true
                if (!same)
                {
                    Console.WriteLine($"loop {i} -- error for DAL in d: d.DAL != d2.DAL");
                }

                // test transient
                bool diff = ReferenceEquals(d, d2); // should be false
                if (diff)
                {
                    Console.WriteLine($"loop {i} -- error: d == d2");
                }
            }

            // test scoped
            for (int i = 0; i < loop; i++)
            {
                Task <IAService[]> request = Task.Run(async() =>
                {
                    IMyContainerV2 childContainer = container.CreateChildContainer();
                    Task <IAService> aTask        = Task.Run(() => childContainer.Resolve <IAService>());
                    Task <IAService> a2Task       = Task.Run(() => childContainer.Resolve <IAService>());
                    return(await Task.WhenAll(aTask, a2Task));
                });

                Task <IAService[]> request2 = Task.Run(async() =>
                {
                    IMyContainerV2 childContainer = container.CreateChildContainer();
                    Task <IAService> aTask        = Task.Run(() => childContainer.Resolve <IAService>());
                    return(await Task.WhenAll(aTask));
                });

                Task.WaitAll(request, request);
                bool sameA = ReferenceEquals(request.Result[0], request.Result[1]); // should be true
                if (!sameA)
                {
                    Console.WriteLine($"loop {i} -- error for A in the same request: a[0] != a[1]");
                }

                bool diffA = ReferenceEquals(request.Result[0], request2.Result[0]); // should be false
                if (diffA)
                {
                    Console.WriteLine($"loop {i} -- error for A in different requests: a[0] == a2[0]");
                }

                bool sameDal = ReferenceEquals(request.Result[0].DAL, request2.Result[0].DAL); // should be true
                if (!sameDal)
                {
                    Console.WriteLine($"loop {i} -- error for DAL in a: different DAL");
                }
            }

            // test per thread
            for (int i = 0; i < 5; i++)
            {
                Task <IEService[]> t = Task.Run(() =>
                {
                    Console.WriteLine($"t thread: {Thread.CurrentThread.ManagedThreadId}");
                    IEService e = container.Resolve <IEService>();
                    IFService f = container.Resolve <IFService>();
                    Thread.Sleep(100);
                    return(new IEService[] { e, f.E });
                });
                Task <IEService[]> t2 = Task.Run(() =>
                {
                    Console.WriteLine($"t2 thread: {Thread.CurrentThread.ManagedThreadId}");
                    IEService e = container.Resolve <IEService>();
                    return(new IEService[] { e });
                });
                Task.WaitAll(t, t2);

                bool sameE = ReferenceEquals(t.Result[0], t.Result[1]); // should be true
                if (!sameE)
                {
                    Console.WriteLine($"error for E in the same thread: e[0] != e[1]");
                }

                bool diffE = ReferenceEquals(t.Result[0], t2.Result[0]); // should be false
                if (diffE)
                {
                    Console.WriteLine($"error for A in different threads: e[0] == e2[0]");
                }
            }
        }