//public static void createAndStartService()
        //{
        //    ChromeDriverService service;
        //    IWebDriver driver;
        //    service = ChromeDriverService.CreateDefaultService()
        //        .usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
        //        .usingAnyFreePort()
        //        .build();
        //    service.Start();
        //}
        public static IWebDriver OpenChromeBrowserWithUrl(IWebDriver driver, string strUrlToOpen, Boolean OpenInNewWindow = false)
        {
            try
            {
                DesiredCapabilities capability = DesiredCapabilities.Chrome();

                //ChromeOptions options = new ChromeOptions();
                //string[] strPaths = { @"C:\Users\kiwi\Downloads\logmeonce_2.6.8.crx" };
                //options.AddExtensions(strPaths);
                //capability.SetCapability(ChromeOptions.Capability, options);

                capability.IsJavaScriptEnabled = true;
                capability.SetCapability(capability.BrowserName, DesiredCapabilities.Chrome().BrowserName);
                capability.SetCapability("webdriver.chrome.driver", "C:\\chromedriver.exe");

                Uri remote_grid = new Uri("http://localhost:4444/wd/hub");


                driver = new ScreenShotRemoteWebDriver(remote_grid, capability);
                //if (OpenInNewWindow) driver = new ScreenShotRemoteWebDriver(remote_grid, capability);
                driver.Navigate().GoToUrl(strUrlToOpen);
                driver.Manage().Window.Maximize();

                Report.AddToHtmlReportPassed("Chrome Browser Open for '" + strUrlToOpen + "' .");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("ex::", ex.Message);
                Report.AddToHtmlReportFailed(driver, ex, "Chrome Browser Open for '" + strUrlToOpen + "' .");
            }

            return(driver);
        }
示例#2
0
        //    public static test()
        //    {
        //         FirefoxProfile profile = new FirefoxProfile();
        //if (System.getProperty("os.name").equalsIgnoreCase("Mac OS X")) {
        // path = "/Users/Jignesh/developer/test-automation";
        //} else {
        // path = "c:\\Downloads_new";
        //}

        //profile.setPreference("dom.max_chrome_script_run_time", "999");
        //profile.setPreference("dom.max_script_run_time", "999");
        //profile.setPreference("browser.download.folderList", 2);
        //profile.setPreference("browser.download.dir", path);
        //profile.setPreference(
        //  "browser.helperApps.neverAsk.openFile",
        //  "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
        //profile.setPreference(
        //  "browser.helperApps.neverAsk.saveToDisk",
        //  "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
        //profile.setPreference("browser.download.manager.showWhenStarting",
        //  false);
        //profile.setPreference("browser.download,manager.focusWhenStarting",
        //  false);
        //// profile.setPreference("browser.download.useDownloadDir",true);
        //profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        //profile.setPreference("browser.download.manager.alertOnEXEOpen",
        //  false);
        //profile.setPreference("browser.download.manager.closeWhenDone",
        //  false);
        //profile.setPreference(
        //  "browser.download.manager.showAlertOnComplete", false);
        //profile.setPreference("browser.download.manager.useWindow", false);
        //profile.setPreference("browser.download.manager.showWhenStarting",
        //  false);

        //profile.setPreference(
        //  "services.sync.prefs.sync.browser.download.manager.showWhenStarting",
        //  false);
        //profile.setPreference("pdfjs.disabled", true);
        //profile.setAcceptUntrustedCertificates(true);
        //profile.setPreference("security.OCSP.enabled", 0);
        //profile.setEnableNativeEvents(false);
        //profile.setPreference("network.http.use-cache", false);

        //// added Dependancy to disable hardware acceleration.

        ///*
        // * profile.setPreference("gfx.direct2d.disabled",true);
        // * profile.setPreference("layers.acceleration.disabled", true);
        // */

        //profile.setPreference("gfx.direct2d.disabled", true);
        //profile.setPreference("layers.acceleration.disabled", true);
        //// profile.setPreference("webgl.force-enabled", true);
        //// Proxy proxy = new Proxy().setHttpProxy("localhost:3129");

        //// cap.setCapability(CapabilityType.PROXY, proxy);

        //capability = DesiredCapabilities.firefox();
        //// proxy code
        //// capability.setCapability(CapabilityType.PROXY,proxy);
        //capability.setJavascriptEnabled(true);
        //capability.setCapability(FirefoxDriver.PROFILE, profile);
        //browserName = capability.getBrowserName();
        //osName = System.getProperty("os.name");
        //browserVersion = capability.getVersion().toString();

        //System.out.println("=========" + "firefox Driver " + "==========");
        //driver = new RemoteWebDriver(remote_grid, capability);
        //    }
        public static IWebDriver OpenFirefoxBrowserWithUrl(IWebDriver driver, string strUrlToOpen, Boolean OpenInNewWindow = false)
        {
            try
            {
                //driver = new FirefoxDriver();

                Uri remote_grid = new Uri("http://" + "localhost" + ":" + "4444" + "/wd/hub");
                DesiredCapabilities capability = null;
                //browser = System.getProperty("browser");

                string browser = "firefox";

                if (browser == null || browser.Contains("firefox"))
                {
                    //FirefoxProfileManager myProfile = new FirefoxProfileManager();
                    //FirefoxProfile profile = myProfile.GetProfile("default");
                    FirefoxProfile profile = new FirefoxProfile();

                    capability = DesiredCapabilities.Firefox();
                    capability.IsJavaScriptEnabled = true;
                    profile.EnableNativeEvents     = true;

                    //
                    profile.SetPreference("gfx.direct2d.disabled", true);
                    profile.SetPreference("layers.acceleration.disabled", true);

                    capability.SetCapability(FirefoxDriver.ProfileCapabilityName, profile);
                }

                Console.WriteLine(capability);
                driver = new ScreenShotRemoteWebDriver(remote_grid, capability);

                //Console.WriteLine(strUrlToOpen);

                driver.Navigate().GoToUrl(strUrlToOpen);
                Report.AddToHtmlReportPassed("FireFox Browser Open for '" + strUrlToOpen + "' .");

                driver.Manage().Window.Maximize();
            }
            catch (Exception ex)
            {
                Report.AddToHtmlReportFailed(driver, ex, "FireFox Browser Open for '" + strUrlToOpen + "' .");
            }
            return(driver);
        }
        public static IWebDriver OpenFirefoxBrowserWithUrl(IWebDriver driver, string strUrlToOpen, Boolean OpenInNewWindow = false)
        {
            try
            {
                //driver = new FirefoxDriver();

                Uri remote_grid = new Uri("http://" + "localhost" + ":" + "4444" + "/wd/hub");
                DesiredCapabilities capability = null;
                //browser = System.getProperty("browser");

                string browser = "firefox";

                if (browser == null || browser.Contains("firefox"))
                {
                    FirefoxProfile profile = new FirefoxProfile();

                    capability = DesiredCapabilities.Firefox();
                    capability.IsJavaScriptEnabled = true;
                    profile.EnableNativeEvents     = true;

                    //webdriverEx

                    capability.SetCapability(FirefoxDriver.ProfileCapabilityName, profile);
                }

                //driver.Manage().Cookies.DeleteCookieNamed("logmeonce_user");
                //driver.Manage().Cookies.DeleteCookieNamed("_jsuid");
                //driver.Manage().Cookies.DeleteCookieNamed("logmeonce_session");
                //driver.Manage().Cookies.DeleteCookieNamed("__unam");
                //driver.Manage().Cookies.DeleteCookieNamed("logmeonce_extension");
                //driver.Manage().Cookies.DeleteCookieNamed("logmeonce_policy");
                //driver.Manage().Cookies.DeleteCookieNamed("_eventqueue");
                //driver.Manage().Cookies.DeleteCookieNamed("logmeonce_timeout");

                driver = new ScreenShotRemoteWebDriver(remote_grid, capability);

                //Console.WriteLine(strUrlToOpen);

                driver.Navigate().GoToUrl(strUrlToOpen);
                Report.AddToHtmlReportPassed("FireFox Browser Open for '" + strUrlToOpen + "' .");

                /* **** ORIGINAL WORKING
                 * try{
                 */
                //////DesiredCapabilities cap = new DesiredCapabilities();
                //////cap.IsJavaScriptEnabled = true;
                //////if (OpenInNewWindow) driver = new FirefoxDriver(cap);
                //////driver.Navigate().GoToUrl(strUrlToOpen);
                //////Report.AddToHtmlReportPassed("FireFox Browser Open for '" + strUrlToOpen + "'.");

                /*   }
                 */

                driver.Manage().Window.Maximize();
            }
            catch (Exception ex)
            {
                Report.AddToHtmlReportFailed(driver, ex, "FireFox Browser Open for '" + strUrlToOpen + "' .");
            }
            return(driver);
        }