Exemple #1
0
        /// <summary>
        /// Return a list of web element using the javascript to find element
        /// </summary>
        /// <param name="pageNameToSwitchTo"></param>
        /// <param name="frameNameToSwitchTo"></param>
        /// <param name="scriptToExecute"></param>
        /// <returns></returns>
        public ReadOnlyCollection <IWebElement> ExecuteJavaScriptIWebElementList(string pageNameToSwitchTo, string frameNameToSwitchTo, string scriptToExecute)
        {
            SAFEBBALog.Debug("scriptToExecute: " + scriptToExecute);
            driver = FindWebDriverElement.SwitchToFrameOrWindowByName(this.driver, pageNameToSwitchTo, frameNameToSwitchTo);
            IJavaScriptExecutor iJavaScriptExecutor          = (IJavaScriptExecutor)driver;
            ReadOnlyCollection <IWebElement> iWebElementList = (ReadOnlyCollection <IWebElement>)iJavaScriptExecutor.ExecuteScript(scriptToExecute);

            SAFEBBALog.Debug("iWebElementList: " + iWebElementList);
            return(iWebElementList);
        }
Exemple #2
0
        public void SeleniumSetup()
        {
            try
            {
                Console.WriteLine("Starting Driver...........");

                String browser = ConfigurationManager.AppSettings["WEB_BROWSER_TO_RUN"];

                var options = new InternetExplorerOptions
                {
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                    EnsureCleanSession = true,
                    //ForceCreateProcessApi=true
                    EnableNativeEvents = false,
                    RequireWindowFocus = false,
                    IgnoreZoomLevel    = true
                };

                ChromeOptions chromeOptions = new ChromeOptions();

                chromeOptions.AddArgument("--test-type");
                chromeOptions.AddArguments("chrome.switches", "--disable-extensions");

                chromeOptions.AddArgument("start-maximized");
                chromeOptions.AddArgument("--enable-automation");
                chromeOptions.AddArgument("test-type=browser");
                chromeOptions.AddArgument("disable-infobars");

                if (browser.Contains("Internet"))
                {
                    driver = new InternetExplorerDriver(TestContext.DeploymentDirectory, options);
                }
                else if (browser.Contains("Chrome"))
                {
                    driver = new ChromeDriver(chromeOptions);
                }

                // driver = new ChromeDriver();
                else
                {
                    driver = null;
                }


                if (driver != null)
                {
                    // Javascript Class
                    javaScriptCalls        = new JavaScriptCalls();
                    javaScriptCalls.Driver = driver;

                    //Find Web Driver
                    findWebDriverElement                 = new FindWebDriverElement();
                    findWebDriverElement.Driver          = driver;
                    findWebDriverElement.JavaScriptCalls = javaScriptCalls;

                    //Operate Web Element
                    operateOnWebDriverElement = new OperateOnWebDriverElement();
                    operateOnWebDriverElement.FindWebDriverElement = findWebDriverElement;
                    operateOnWebDriverElement.JavaScriptCalls      = javaScriptCalls;


                    safeebbalog = new SAFEBBALog();


                    GoToSite(ConfigParameters.WEB_APPLICATION_URL);
                    // driver.Manage().Window.Maximize();
                    //  }
                    // else
                    //  {
                    // SAFEBBALog.Debug("Browser type not specified in the config file...........");
                    //  }
                }
            }
            catch (Exception e)
            {
                SAFEBBALog.Debug("Error Starting Web Driver...........");
                Console.WriteLine(e.StackTrace);
            }
        }