public static void ClassCleanup() { mGR.StopAgents(); mDriver = null; mGR = null; try { proc.Kill(); } catch { } }
public void StartAgentDriver(IAgent IAgent) { Agent agent = (Agent)IAgent; BusinessFlow BusinessFlow = agent.BusinessFlow; ProjEnvironment ProjEnvironment = agent.ProjEnvironment; bool Remote = agent.Remote; DriverBase Driver = null; try { agent.mIsStarting = true; agent.OnPropertyChanged(Fields.Status); try { if (Remote) { throw new Exception("Remote is Obsolete, use GingerGrid"); } else { switch (agent.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 (agent.DriverConfiguration == null) { agent.DriverConfiguration = new ObservableList <DriverConfigParam>(); } ((SeleniumDriver)Driver).RemoteGridHub = agent.GetParamValue(SeleniumDriver.RemoteGridHubParam); ((SeleniumDriver)Driver).RemoteBrowserName = agent.GetParamValue(SeleniumDriver.RemoteBrowserNameParam); ((SeleniumDriver)Driver).RemotePlatform = agent.GetParamValue(SeleniumDriver.RemotePlatformParam); ((SeleniumDriver)Driver).RemoteVersion = agent.GetParamValue(SeleniumDriver.RemoteVersionParam); break; case eDriverType.SeleniumEdge: Driver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Edge); break; case eDriverType.ASCF: Driver = new ASCFDriver(BusinessFlow, agent.Name); break; case eDriverType.DOSConsole: Driver = new DOSConsoleDriver(BusinessFlow); break; case eDriverType.UnixShell: Driver = new UnixShellDriver(BusinessFlow, ProjEnvironment); ((UnixShellDriver)Driver).SetScriptsFolder(System.IO.Path.Combine(agent.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.PerfectoMobileAndroid: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileAndroidWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileIOS: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeIOS, BusinessFlow); break; case eDriverType.PerfectoMobileIOSWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebIOS, BusinessFlow); break; case eDriverType.WebServices: WebServicesDriver WebServicesDriver = new WebServicesDriver(BusinessFlow); Driver = WebServicesDriver; break; case eDriverType.WindowsAutomation: Driver = new WindowsDriver(BusinessFlow); break; case eDriverType.PowerBuilder: Driver = new PBDriver(BusinessFlow); break; case eDriverType.JavaDriver: Driver = new JavaDriver(BusinessFlow); break; case eDriverType.MainFrame3270: Driver = new MainFrameDriver(BusinessFlow); break; //case eDriverType.AndroidADB: // string DeviceConfigFolder = agent.GetOrCreateParam("DeviceConfigFolder").Value; // if (!string.IsNullOrEmpty(DeviceConfigFolder)) // { // Driver = new AndroidADBDriver(BusinessFlow, System.IO.Path.Combine(agent.SolutionFolder, @"Documents\Devices", DeviceConfigFolder, @"\")); // } // else // { // //TODO: Load create sample folder/device, or start the wizard // throw new Exception("Please set device config folder"); // } // break; default: { throw new Exception("Matching Driver was not found."); } } } } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, "Failed to set Agent Driver", e); return; } if (agent.AgentType == eAgentType.Service) { throw new Exception("Error - Agent type is service and trying to launch from Ginger.exe"); // we should never get here with service } else { agent.Driver = Driver; Driver.BusinessFlow = agent.BusinessFlow; agent.SetDriverConfiguration(); //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix if (Driver.IsSTAThread()) { agent.CTS = new CancellationTokenSource(); agent.MSTATask = new Task(() => { Driver.StartDriver(); }, agent.CTS.Token, TaskCreationOptions.LongRunning); agent.MSTATask.Start(); } else { Driver.StartDriver(); } } } finally { if (agent.AgentType == eAgentType.Service) { agent.mIsStarting = false; } else { if (Driver != null) { // Give the driver time to start Thread.Sleep(500); Driver.IsDriverRunning = true; Driver.driverMessageEventHandler += agent.driverMessageEventHandler; } agent.mIsStarting = false; agent.OnPropertyChanged(Fields.Status); agent.OnPropertyChanged(Fields.IsWindowExplorerSupportReady); } } }
public static void ClassInit(TestContext context) { WorkSpaceEventHandler WSEH = new WorkSpaceEventHandler(); WorkSpace.Init(WSEH); // launch PB Test App if (proc == null || proc.HasExited) { proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = @"pb_test_app.exe"; proc.StartInfo.WorkingDirectory = TestResources.GetTestResourcesFolder("PBTestApp"); Console.WriteLine(proc.StartInfo.WorkingDirectory); Console.WriteLine(proc.StartInfo.FileName); proc.Start(); GingerCore.General.DoEvents(); GingerCore.General.DoEvents(); } mGR = new GingerRunner(); mGR.CurrentSolution = new Ginger.SolutionGeneral.Solution(); mBF = new BusinessFlow(); mBF.Activities = new ObservableList <Activity>(); mBF.Name = "BF Test PB Driver"; Platform p = new Platform(); p.PlatformType = ePlatformType.PowerBuilder; mBF.TargetApplications.Add(new TargetApplication() { AppName = "PBTestAPP" }); Activity activity = new Activity(); activity.TargetApplication = "PBTestApp"; mBF.Activities.Add(activity); mBF.CurrentActivity = activity; mDriver = new PBDriver(mBF); mDriver.StartDriver(); Agent a = new Agent(); a.Active = true; a.Driver = mDriver; a.DriverType = Agent.eDriverType.PowerBuilder; mGR.SolutionAgents = new ObservableList <Agent>(); mGR.SolutionAgents.Add(a); ApplicationAgent AA = new ApplicationAgent(); AA.AppName = "PBTestApp"; AA.Agent = a; mGR.ApplicationAgents.Add(AA); mGR.CurrentBusinessFlow = mBF; mGR.SetCurrentActivityAgent(); // Do Switch Window, to be ready for actions ActSwitchWindow c = new ActSwitchWindow(); c.LocateBy = eLocateBy.ByTitle; c.LocateValueCalculated = "Simple Page"; c.WaitTime = 10; mDriver.RunAction(c); //if(c.Status.Value==eRunStatus.Failed) //{ // c = new ActSwitchWindow(); // c.LocateBy = eLocateBy.ByTitle; // c.LocateValueCalculated = "Simple Page"; // c.WaitTime = 10; // mDriver.RunAction(c); //} ActPBControl action = new ActPBControl(); action.LocateBy = eLocateBy.ByXPath; action.ControlAction = ActPBControl.eControlAction.SetValue; action.AddNewReturnParams = true; action.Wait = 4; action.LocateValueCalculated = "/[AutomationId:1001]"; action.Value = proc.StartInfo.WorkingDirectory = TestResources.GetTestResourcesFolder("PBTestApp") + @"\Browser.html"; action.Active = true; mBF.CurrentActivity.Acts.Add(action); mBF.CurrentActivity.Acts.CurrentItem = action; //Act mGR.RunAction(action, false); action = new ActPBControl(); action.LocateBy = eLocateBy.ByName; action.ControlAction = ActPBControl.eControlAction.SetValue; action.LocateValueCalculated = "Launch Widget Window"; action.Active = true; mBF.CurrentActivity.Acts.Add(action); mBF.CurrentActivity.Acts.CurrentItem = action; //Act mGR.RunAction(action, false); c = new ActSwitchWindow(); c.LocateBy = eLocateBy.ByTitle; c.LocateValueCalculated = "CSM Widgets Test Applicaiton"; c.WaitTime = 10; mDriver.RunAction(c); string actual = ""; do { action = new ActPBControl(); action.LocateBy = eLocateBy.ByName; action.ControlAction = ActPBControl.eControlAction.IsExist; action.LocateValueCalculated = "Script Error"; action.AddNewReturnParams = true; action.Timeout = 10; action.Active = true; mBF.CurrentActivity.Acts.Add(action); mBF.CurrentActivity.Acts.CurrentItem = action; //Act mGR.RunAction(action, false); Assert.AreEqual(action.Status, eRunStatus.Passed, "Action Status"); actual = action.GetReturnParam("Actual"); if (actual.Equals("True")) { ActPBControl PbAct = new ActPBControl(); PbAct.LocateBy = eLocateBy.ByXPath; PbAct.ControlAction = ActPBControl.eControlAction.Click; PbAct.LocateValueCalculated = @"/Script Error/[LocalizedControlType:title bar]/Close"; PbAct.Active = true; mBF.CurrentActivity.Acts.Add(PbAct); mBF.CurrentActivity.Acts.CurrentItem = PbAct; mGR.RunAction(PbAct, false); } } while (actual.Equals("True")); //proceed for switch window and initialize browser c = new ActSwitchWindow(); c.LocateBy = eLocateBy.ByTitle; c.LocateValueCalculated = "CSM Widgets Test Applicaiton"; c.WaitTime = 2; mDriver.RunAction(c); int count = 1; ActBrowserElement actBrowser = new ActBrowserElement(); do { actBrowser.LocateBy = eLocateBy.ByXPath; actBrowser.LocateValue = @"/[AutomationId:1000]/[LocalizedControlType:pane]/[LocalizedControlType:pane]/[LocalizedControlType:pane]"; actBrowser.ControlAction = ActBrowserElement.eControlAction.InitializeBrowser; actBrowser.Wait = 2; actBrowser.Timeout = 10; actBrowser.Active = true; mBF.CurrentActivity.Acts.Add(actBrowser); mBF.CurrentActivity.Acts.CurrentItem = actBrowser; mGR.RunAction(actBrowser, false); count--; } while (actBrowser.Status.Equals(eRunStatus.Failed) && count > 0); if (actBrowser.Status.Equals(eRunStatus.Failed)) { Assert.AreEqual(actBrowser.Status, eRunStatus.Passed, "actBrowser.Status"); Assert.AreEqual(actBrowser.Error, null, "actBrowser.Error"); } }
public void StartAgentDriver(IAgent agent) { Agent zAgent = (Agent)agent; BusinessFlow BusinessFlow = zAgent.BusinessFlow; ProjEnvironment ProjEnvironment = zAgent.ProjEnvironment; bool Remote = zAgent.Remote; DriverBase Driver = null; zAgent.mIsStarting = true; zAgent.OnPropertyChanged(Fields.Status); try { try { if (Remote) { throw new Exception("Remote is Obsolete, use GingerGrid"); //We pass the agent info } else { switch (zAgent.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 (zAgent.DriverConfiguration == null) { zAgent.DriverConfiguration = new ObservableList <DriverConfigParam>(); } ((SeleniumDriver)Driver).RemoteGridHub = zAgent.GetParamValue(SeleniumDriver.RemoteGridHubParam); ((SeleniumDriver)Driver).RemoteBrowserName = zAgent.GetParamValue(SeleniumDriver.RemoteBrowserNameParam); ((SeleniumDriver)Driver).RemotePlatform = zAgent.GetParamValue(SeleniumDriver.RemotePlatformParam); ((SeleniumDriver)Driver).RemoteVersion = zAgent.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, zAgent.Name); break; case eDriverType.DOSConsole: Driver = new DOSConsoleDriver(BusinessFlow); break; case eDriverType.UnixShell: Driver = new UnixShellDriver(BusinessFlow, ProjEnvironment); ((UnixShellDriver)Driver).SetScriptsFolder(System.IO.Path.Combine(zAgent.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.PerfectoMobileAndroid: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileAndroidWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebAndroid, BusinessFlow); break; case eDriverType.PerfectoMobileIOS: Driver = new PerfectoDriver(PerfectoDriver.eContextType.NativeIOS, BusinessFlow); break; case eDriverType.PerfectoMobileIOSWeb: Driver = new PerfectoDriver(PerfectoDriver.eContextType.WebIOS, 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 = zAgent.GetOrCreateParam("DeviceConfigFolder").Value; if (!string.IsNullOrEmpty(DeviceConfigFolder)) { Driver = new AndroidADBDriver(BusinessFlow, System.IO.Path.Combine(zAgent.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) { Reporter.ToUser(eUserMsgKeys.FailedToConnectAgent, zAgent.Name, e.Message); } if (zAgent.AgentType == eAgentType.Service) { zAgent.StartPluginService(); zAgent.OnPropertyChanged(Fields.Status); } else { zAgent.Driver = Driver; Driver.BusinessFlow = zAgent.BusinessFlow; zAgent.SetDriverConfiguration(); //if STA we need to start it on seperate thread, so UI/Window can be refreshed: Like IB, Mobile, Unix if (Driver.IsSTAThread()) { zAgent.CTS = new CancellationTokenSource(); zAgent.MSTATask = new Task(() => { Driver.StartDriver(); }, zAgent.CTS.Token, TaskCreationOptions.LongRunning); zAgent.MSTATask.Start(); } else { Driver.StartDriver(); } } } finally { if (zAgent.AgentType == eAgentType.Service) { zAgent.mIsStarting = false; } else { // Give the driver time to start Thread.Sleep(500); zAgent.mIsStarting = false; Driver.IsDriverRunning = true; zAgent.OnPropertyChanged(Fields.Status); Driver.driverMessageEventHandler += zAgent.driverMessageEventHandler; zAgent.OnPropertyChanged(Fields.IsWindowExplorerSupportReady); } } //return Driver; }