Пример #1
0
        public void StartDriver()
        {
            mIsStarting = true;
            OnPropertyChanged(Fields.Status);
            try
            {
                try
                {
                    if (Remote)
                    {
                        throw new Exception("Remote is Obsolete, use GingerGrid");
                        //We pass the agent info
                    }
                    else
                    {
                        switch (DriverType)
                        {
                        case eDriverType.InternalBrowser:
                            Driver = new InternalBrowser(BusinessFlow);
                            break;

                        case eDriverType.SeleniumFireFox:
                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.FireFox);
                            break;

                        case eDriverType.SeleniumChrome:
                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Chrome);
                            break;

                        case eDriverType.SeleniumIE:

                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.IE);

                            break;

                        case eDriverType.SeleniumRemoteWebDriver:
                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.RemoteWebDriver);
                            // set capabilities
                            if (DriverConfiguration == null)
                            {
                                DriverConfiguration = new ObservableList <DriverConfigParam>();
                            }
                            ((SeleniumDriver)Driver).RemoteGridHub     = GetParamValue(SeleniumDriver.RemoteGridHubParam);
                            ((SeleniumDriver)Driver).RemoteBrowserName = GetParamValue(SeleniumDriver.RemoteBrowserNameParam);
                            ((SeleniumDriver)Driver).RemotePlatform    = GetParamValue(SeleniumDriver.RemotePlatformParam);
                            ((SeleniumDriver)Driver).RemoteVersion     = GetParamValue(SeleniumDriver.RemoteVersionParam);
                            break;

                        case eDriverType.SeleniumEdge:
                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Edge);
                            break;

                        case eDriverType.SeleniumPhantomJS:
                            Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.PhantomJS);
                            break;

                        case eDriverType.ASCF:
                            Driver = new ASCFDriver(BusinessFlow, Name);
                            break;

                        case eDriverType.DOSConsole:
                            Driver = new DOSConsoleDriver(BusinessFlow);
                            break;

                        case eDriverType.UnixShell:
                            Driver = new UnixShellDriver(BusinessFlow, ProjEnvironment);
                            ((UnixShellDriver)Driver).SetScriptsFolder(SolutionFolder + @"\Documents\sh\");
                            break;

                        case eDriverType.MobileAppiumAndroid:
                            Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.Android, BusinessFlow);
                            break;

                        case eDriverType.MobileAppiumIOS:
                            Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOS, BusinessFlow);
                            break;

                        case eDriverType.MobileAppiumAndroidBrowser:
                            Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.AndroidBrowser, BusinessFlow);
                            break;

                        case eDriverType.MobileAppiumIOSBrowser:
                            Driver = new SeleniumAppiumDriver(SeleniumAppiumDriver.eSeleniumPlatformType.iOSBrowser, BusinessFlow);
                            break;

                        case eDriverType.PerfectoMobile:
                            Driver = new PerfectoDriver(BusinessFlow);
                            break;

                        case eDriverType.WebServices:
                            WebServicesDriver WebServicesDriver = new WebServicesDriver(BusinessFlow);
                            Driver = WebServicesDriver;
                            break;

                        case eDriverType.WindowsAutomation:
                            Driver = new WindowsDriver(BusinessFlow);
                            break;

                        case eDriverType.FlaUIWindow:
                            Driver = new WindowsDriver(BusinessFlow, UIAutomationDriverBase.eUIALibraryType.FlaUI);
                            break;

                        case eDriverType.PowerBuilder:
                            Driver = new PBDriver(BusinessFlow);
                            break;

                        case eDriverType.FlaUIPB:
                            Driver = new PBDriver(BusinessFlow, UIAutomationDriverBase.eUIALibraryType.FlaUI);
                            break;

                        case eDriverType.JavaDriver:
                            Driver = new JavaDriver(BusinessFlow);
                            break;

                        case eDriverType.MainFrame3270:
                            Driver = new MainFrameDriver(BusinessFlow);
                            break;

                        case eDriverType.AndroidADB:
                            string DeviceConfigFolder = GetOrCreateParam("DeviceConfigFolder").Value;
                            if (!string.IsNullOrEmpty(DeviceConfigFolder))
                            {
                                Driver = new AndroidADBDriver(BusinessFlow, SolutionFolder + @"\Documents\Devices\" + DeviceConfigFolder + @"\");
                            }
                            else
                            {
                                //TODO: Load create sample folder/device, or start the wizard
                                throw new Exception("Please set device config folder");
                            }
                            break;

                            //TODO: default mess
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                }
                Driver.BusinessFlow = this.BusinessFlow;
                SetDriverConfiguration();

                //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix
                if (Driver.IsSTAThread())
                {
                    CTS = new CancellationTokenSource();

                    MSTATask = new Task(() => { Driver.StartDriver(); }, CTS.Token, TaskCreationOptions.LongRunning);
                    MSTATask.Start();
                }
                else
                {
                    Driver.StartDriver();
                }
            }
            finally
            {
                // Give the driver time to start
                Thread.Sleep(500);
                mIsStarting            = false;
                Driver.IsDriverRunning = true;
                OnPropertyChanged(Fields.Status);
                Driver.driverMessageEventHandler += driverMessageEventHandler;
                OnPropertyChanged(Fields.IsWindowExplorerSupportReady);
            }
        }