public void SeleniumControlTestSetup() { ControlID = "control"; ControlLocator = "id=" + ControlID; SeleniumMock = new Mock<ISelenium>(MockBehavior.Strict); Driver = new SeleniumDriver(SeleniumMock.Object); }
public void TestUserControl() { // Setup var seleniumMock = new Mock<ISelenium>(); var driver = new SeleniumDriver(seleniumMock.Object); var page = new PageUsingUserControl(driver); var value = "text"; var expectedSeleniumLocator = "id=field"; // Exercise page.Control.TextField.Type(value); // Validate seleniumMock.Verify(x => x.Type(expectedSeleniumLocator, value)); }
public void Setup() { _seleniumMock = new Mock<ISelenium>(); _seleniumDriver = new SeleniumDriver(_seleniumMock.Object); }
public void Setup() { _seleniumMock = new Mock<ISelenium>(MockBehavior.Strict); _driver = new SeleniumDriver(_seleniumMock.Object); }
public void SetUserAgentTest() { //arrange Activity activity = new Activity(); mBF.Activities.Add(activity); mBF.CurrentActivity = activity; Platform p = new Platform(); p.PlatformType = ePlatformType.Web; mBF.TargetApplications.Add(new TargetApplication() { AppName = "DeviceEmulationUserAgent" }); mBF.CurrentActivity.TargetApplication = "DeviceEmulationUserAgent"; var mDriver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Chrome); mDriver.AutoDetect = true; mDriver.HttpServerTimeOut = 60; //Set Browser User Agent mDriver.BrowserUserAgent = "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"; mDriver.BrowserHeight = "960"; mDriver.BrowserWidth = "600"; mDriver.StartDriver(); Agent agent = new Agent(); agent.Active = true; agent.Driver = mDriver; agent.DriverType = Agent.eDriverType.SeleniumChrome; mGR.SolutionAgents.Add(agent); ApplicationAgent AA = new ApplicationAgent(); AA.AppName = "DeviceEmulationUserAgent"; AA.Agent = agent; mGR.ApplicationAgents.Add(AA); mGR.CurrentBusinessFlow = mBF; mGR.CurrentBusinessFlow.CurrentActivity = activity; mGR.SetCurrentActivityAgent(); ActBrowserElement actBrowser = new ActBrowserElement(); actBrowser.ControlAction = ActBrowserElement.eControlAction.GotoURL; actBrowser.GetOrCreateInputParam("Value", "http://www.google.com"); actBrowser.Active = true; activity.Acts.Add(actBrowser); //act //get user agent string ActBrowserElement actBrowser2 = new ActBrowserElement(); actBrowser2.ControlAction = ActBrowserElement.eControlAction.RunJavaScript; actBrowser2.GetOrCreateInputParam("Value", "navigator.userAgent"); actBrowser2.Active = true; actBrowser2.AddNewReturnParams = true; activity.Acts.Add(actBrowser2); mGR.RunActivity(activity); //assert Assert.AreEqual(true, actBrowser2.ReturnValues.FirstOrDefault().Actual.Contains("iPad")); }
public void SetEmulationDeviceNameTest() { //arrange Activity activity = new Activity(); mBF.Activities.Add(activity); mBF.CurrentActivity = activity; Platform p = new Platform(); p.PlatformType = ePlatformType.Web; mBF.TargetApplications.Add(new TargetApplication() { AppName = "DeviceEmulation" }); mBF.CurrentActivity.TargetApplication = "DeviceEmulation"; var mDriver = new SeleniumDriver(GingerCore.Drivers.SeleniumDriver.eBrowserType.Chrome); mDriver.AutoDetect = true; mDriver.HttpServerTimeOut = 60; //Set emulation device name mDriver.EmulationDeviceName = "iPad"; mDriver.StartDriver(); Agent agent = new Agent(); agent.Active = true; agent.Driver = mDriver; agent.DriverType = Agent.eDriverType.SeleniumChrome; mGR.SolutionAgents.Add(agent); ApplicationAgent AA = new ApplicationAgent(); AA.AppName = "DeviceEmulation"; AA.Agent = agent; mGR.ApplicationAgents.Add(AA); mGR.CurrentBusinessFlow = mBF; mGR.CurrentBusinessFlow.CurrentActivity = activity; mGR.SetCurrentActivityAgent(); ActBrowserElement actBrowser = new ActBrowserElement(); actBrowser.ControlAction = ActBrowserElement.eControlAction.GotoURL; actBrowser.GetOrCreateInputParam("Value", "http://www.google.com"); actBrowser.Active = true; activity.Acts.Add(actBrowser); //act ActBrowserElement actBrowser2 = new ActBrowserElement(); actBrowser2.ControlAction = ActBrowserElement.eControlAction.RunJavaScript; actBrowser2.GetOrCreateInputParam("Value", "navigator.userAgent"); actBrowser2.Active = true; actBrowser2.AddNewReturnParams = true; activity.Acts.Add(actBrowser2); mGR.RunActivity(activity); //assert Assert.AreEqual(true, actBrowser2.ReturnValues.FirstOrDefault().Actual.Contains("iPad")); }
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(); IVirtualDriver VirtualDriver = null; if (agent.Driver is IVirtualDriver VD) { VirtualDriver = VD; string ErrorMessage; if (!VirtualDriver.CanStartAnotherInstance(out ErrorMessage)) { throw new NotSupportedException(ErrorMessage); } } //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(); } if (VirtualDriver != null) { VirtualDriver.DriverStarted(agent.Guid.ToString()); } } } 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); } } }
/// <summary> /// Creates a new <see cref="SeleniumCollectionElementDriver"/> instance /// </summary> public SeleniumCollectionElementDriver(SeleniumDriver seleniumDriver, string xpath, int index) { _seleniumDriver = seleniumDriver; _xpath = xpath; _index = index; }