/// <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 }); }
/// <summary> /// Gets the capabilities for Edge /// </summary> /// <param name="_alertBehaviour"></param> /// <param name="acceptSlefSignedSSL"></param> /// <param name="_useInPrivateBrowsing"></param> /// <param name="_loadStrategy"></param> /// <returns></returns> private EdgeOptions GetEdgeBrowserOptions(UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default, bool acceptSlefSignedSSL = false, bool _useInPrivateBrowsing = false, PageLoadStrategy _loadStrategy = PageLoadStrategy.Normal) { return(new EdgeOptions() { UnhandledPromptBehavior = _alertBehaviour, UseInPrivateBrowsing = _useInPrivateBrowsing, PageLoadStrategy = _loadStrategy, StartPage = BaseUrl, AcceptInsecureCertificates = acceptSlefSignedSSL, }); }
private void ExecuteTestWithUnhandledPrompt(UnhandledPromptBehavior behavior, string expectedAlertText) { bool silentlyHandlePrompt = behavior == UnhandledPromptBehavior.Accept || behavior == UnhandledPromptBehavior.Dismiss; UnhandledPromptBehaviorOptions options = new UnhandledPromptBehaviorOptions(); if (behavior != UnhandledPromptBehavior.Default) { options.UnhandledPromptBehavior = behavior; } localDriver = EnvironmentManager.Instance.CreateDriverInstance(options); localDriver.Url = alertsPage; localDriver.FindElement(By.Id("prompt-with-default")).Click(); WaitFor(ElementTextToBeEqual("text", expectedAlertText, silentlyHandlePrompt), "Did not find text"); }
/// <summary> /// Gets the capabilities for FIREFOX /// </summary> /// <param name="_logLevel"></param> /// <param name="_alertBehaviour"></param> /// <param name="acceptSlefSignedSSL"></param> /// <param name="_loadStrategy"></param> /// <returns></returns> private FirefoxOptions GetFirefoxBrowserOptions(FirefoxDriverLogLevel _logLevel = FirefoxDriverLogLevel.Default, UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default, bool acceptSlefSignedSSL = true, PageLoadStrategy _loadStrategy = PageLoadStrategy.Default) { FirefoxService = FirefoxDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"geckodriver.exe"); FirefoxService.HideCommandPromptWindow = true; FirefoxService.Start(); return(new FirefoxOptions() { LogLevel = _logLevel, UnhandledPromptBehavior = _alertBehaviour, PageLoadStrategy = _loadStrategy, AcceptInsecureCertificates = acceptSlefSignedSSL, UseLegacyImplementation = true }); }
/// <summary> /// Gets the capabilities for Opera /// </summary> /// <param name="_alertBehaviour"></param> /// <param name="acceptSlefSignedSSL"></param> /// <param name="_loadStrategy"></param> /// <returns></returns> private OperaOptions GetOperaBrowserOptions(UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default, bool acceptSlefSignedSSL = true, bool _leaveBrowserRunning = false, PageLoadStrategy _loadStrategy = PageLoadStrategy.Default) { OperaService = OperaDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"operadriver.exe"); OperaService.EnableVerboseLogging = true; OperaService.HideCommandPromptWindow = true; OperaService.Start(); return(new OperaOptions() { UnhandledPromptBehavior = _alertBehaviour, LeaveBrowserRunning = _leaveBrowserRunning, PageLoadStrategy = _loadStrategy, AcceptInsecureCertificates = acceptSlefSignedSSL }); }
public void SomeTestMethod1InBrowserFactoryWithSettings() { string inputBrowser = "Chrome"; switch (inputBrowser) { case "Chrome": //Deprecated. How will you merge cap and options and send to driver constructor. //DesiredCapabilities cap = new DesiredCapabilities(); //cap.SetCapability(CapabilityType.AcceptInsecureCertificates,true); //cap.SetCapability(CapabilityType.AcceptSslCertificates,true); //cap.SetCapability(CapabilityType.HandlesAlerts,true); //cap.SetCapability(CapabilityType.IsJavaScriptEnabled,true); //cap.SetCapability(CapabilityType.UnexpectedAlertBehavior,true); //cap.SetCapability(CapabilityType.UnhandledPromptBehavior,true); ChromeOptions options = new ChromeOptions(); options.AcceptInsecureCertificates = true; options.AddArguments("disable-infobars"); options.AddArgument("ignore-certificate-errors"); options.AddArgument("start-maximized"); options.AddArgument("test-type"); options.EnableMobileEmulation("Nexus 5"); //var proxy = new Proxy(); //proxy.Kind = ProxyKind.Manual; //proxy.IsAutoDetect = true; //proxy.HttpProxy = ""; //proxy.SslProxy = ""; //options.Proxy = proxy; //options.AddExtension(@"load - extension = c:\PathToFirstExtensionHere, c:\PathToSecondExtensionHere"); bool?AcceptInsecureCertificates = options.AcceptInsecureCertificates; ReadOnlyCollection <string> ArgumentsList = options.Arguments; string BinaryLocation = options.BinaryLocation; string BrowserName = options.BrowserName; string BrowserVersion = options.BrowserVersion; string DebuggerAddress = options.DebuggerAddress; ReadOnlyCollection <string> ExtensionsList = options.Extensions; bool LeaveBrowserRunning = options.LeaveBrowserRunning; string MinidumpPath = options.MinidumpPath; PageLoadStrategy PageLoadStrategy = options.PageLoadStrategy; ChromePerformanceLoggingPreferences PerformanceLoggingPreferences = options.PerformanceLoggingPreferences; string PlatformName = options.PlatformName; Proxy Proxy = options.Proxy; UnhandledPromptBehavior UnhandledPromptBehavior = options.UnhandledPromptBehavior; bool UseSpecCompliantProtocol = options.UseSpecCompliantProtocol; Console.WriteLine($" AcceptInsecureCertificates : {AcceptInsecureCertificates}"); foreach (string s in ArgumentsList) { Console.WriteLine($" ArgumentsList : {s}"); } Console.WriteLine($" BinaryLocation : {BinaryLocation}"); Console.WriteLine($" BrowserName : {BrowserName}"); Console.WriteLine($" BrowserVersion : {BrowserVersion}"); Console.WriteLine($" DebuggerAddress : {DebuggerAddress}"); foreach (string s in ExtensionsList) { Console.WriteLine($" ExtensionsList : {s}"); } Console.WriteLine($" LeaveBrowserRunning : {LeaveBrowserRunning}"); Console.WriteLine($" MinidumpPath : {MinidumpPath}"); Console.WriteLine($" PageLoadStrategy : {PageLoadStrategy}"); Console.WriteLine($" PerformanceLoggingPreferences : {PerformanceLoggingPreferences}"); Console.WriteLine($" PlatformName : {PlatformName}"); Console.WriteLine($" Proxy : {Proxy}"); Console.WriteLine($" UnhandledPromptBehavior : {UnhandledPromptBehavior}"); Console.WriteLine($" UseSpecCompliantProtocol : {UseSpecCompliantProtocol}"); //options.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates,true); //options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates,true); //options.AddAdditionalCapability(CapabilityType.HandlesAlerts, true); //options.AddAdditionalCapability(CapabilityType.IsJavaScriptEnabled, true); //options.AddAdditionalCapability(CapabilityType.UnexpectedAlertBehavior,true); //options.AddAdditionalCapability(CapabilityType.UnhandledPromptBehavior, UnhandledPromptBehavior.Accept); //options.AddAdditionalCapability(CapabilityType.Platform,PlatformType.Windows); driver = new ChromeDriver(options); System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"C:\Users\v-rusom\Documents\visual studio 2015\Projects\SomeThingInAutomation\SomeTestingInAutomation\bin\Debug\chromedriver.exe"); break; case "IE": //DesiredCapabilities caps = DesiredCapabilities.InternetExplorer(); //caps.SetCapability("ignoreZoomSetting",true); InternetExplorerOptions ieoptions = new InternetExplorerOptions(); //ieoptions.ForceCreateProcessApi = true; ieoptions.IgnoreZoomLevel = true; ieoptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true; //ieoptions.AcceptInsecureCertificates = true; ieoptions.BrowserCommandLineArguments = "-private"; //var ieproxy = new Proxy(); //ieproxy.Kind = ProxyKind.Manual; //ieproxy.IsAutoDetect = false; //ieproxy.HttpProxy = "127.0.0.1"; //ieproxy.SslProxy = "127.0.0.1"; //ieoptions.Proxy = ieproxy; driver = new InternetExplorerDriver(ieoptions); System.Environment.SetEnvironmentVariable("webdriver.ie.driver", @"C:\Users\v-rusom\Documents\visual studio 2015\Projects\SomeThingInAutomation\SomeTestingInAutomation\bin\Debug\IEDriverServer.exe"); break; default: Console.WriteLine("Plese enter correct browser here"); break; } driver.Manage().Window.Maximize(); driver.Manage().Cookies.DeleteAllCookies(); driver.Url = "http://executeautomation.com/demosite/index.html?UserName=fdghhf&Password=dfgdfg&Login=Login"; IJavaScriptExecutor jse = (IJavaScriptExecutor)driver; jse.ExecuteScript("document.getElementById('TitleId').style.borderColor='Red';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('TitleId').selectedIndex=1;"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('TitleId').style.borderColor='Green';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('Initial').style.borderColor='Red';" + "document.getElementById('Initial').value='Somala';" + "document.getElementById('Initial').style.borderColor='Green';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('FirstName').style.borderColor='Red';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('FirstName').value='Rupesh';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('FirstName').style.borderColor='Green';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('MiddleName').style.borderColor='Red';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('MiddleName').value='Kumar';"); Thread.Sleep(20); jse.ExecuteScript("document.getElementById('MiddleName').style.borderColor='Green';"); Thread.Sleep(20); Assert.AreEqual("Execute Automation", driver.Title); driver.Close(); driver.Quit(); }
public void SetUnhandledPromptBehavior(UnhandledPromptBehavior behavior) { _driverBuilder.SetUnhandledPromptBehavior(behavior); }
public void SetUnhandledPromptBehavior(UnhandledPromptBehavior behavior) { _options.UnhandledPromptBehavior = behavior; }