示例#1
0
        public Web()
        {
            FirefoxProfileManager allProfiles = new FirefoxProfileManager();
            //FirefoxProfile profile = allProfiles.GetProfile(
            //TODO: Read the browser type from an external configuration file.
            string driverTypeProp = Sut.Instance.GetProperty("webdriver", "browser");

            if (driverTypeProp.ToLower().Equals("chrome"))
            {
                driver = WebdriverFactory.CreateDriver(Webdriver_infra.WebdriverFactory.DriverType.Chrome, null);
                driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080);
            }
            else if (driverTypeProp.ToLower().Equals("iexplore") || driverTypeProp.ToLower().Equals("explorer") || driverTypeProp.ToLower().Equals("explore") || driverTypeProp.ToLower().Equals("internetexplorer"))
            {
                driver = WebdriverFactory.CreateDriver(Webdriver_infra.WebdriverFactory.DriverType.InternetExplorer, null);
            }
            else if (driverTypeProp.ToLower().Equals("firefox"))
            {
                driver = WebdriverFactory.CreateDriver(Webdriver_infra.WebdriverFactory.DriverType.Firefox, null);
            }

            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
            driver.Navigate().GoToUrl(Url);
        }
示例#2
0
        public void CloseBrowserAndSaveCookies()
        {
            var cookies = driver.Manage().Cookies.AllCookies;

            if (driver != null)
            {
                driver.Quit();
            }
            driver = WebdriverFactory.CreateDriver(Webdriver_infra.WebdriverFactory.DriverType.InternetExplorer, null);
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            driver.Navigate().GoToUrl(Url);
            foreach (Cookie cookie in cookies)
            {
                driver.Manage().Cookies.AddCookie(cookie);
            }
            driver.Navigate().GoToUrl(Url);
        }