AddExtension() public method

Adds a Firefox Extension to this profile
public AddExtension ( string extensionToInstall ) : void
extensionToInstall string The path to the new extension
return void
		internal IWebDriver StartBrowser(string browserType)
		{
			if (_driver != null)
			{
				_driver.Quit();
			}

			switch (browserType)
			{
				case "ie":
					{
						_driver = new InternetExplorerDriver();
						break;
					}
				case "firefox":
					{
						const string fileFirebug = "E:/DotNetNuke/Selenium/firebug-1.11.1-fx.xpi";
						const string fileNetExport = "E:/DotNetNuke/Selenium/netExport-0.9b3.xpi";
						const string resultDir = "E:/DotNetNuke/Results";

						FirefoxProfile firefoxProfile = new FirefoxProfile();
						firefoxProfile.AcceptUntrustedCertificates = true;

						firefoxProfile.AddExtension(fileFirebug);
						firefoxProfile.AddExtension(fileNetExport);

						firefoxProfile.SetPreference("extensions.firebug.currentVersion", "1.11.1"); // Avoid startup screen
						firefoxProfile.SetPreference("extensions.firebug.previousPlacement", 1); //Previous Firebug UI placement within the browser (0-unknown, 1-in browser, 2-in a new window, 3-minimized
						firefoxProfile.SetPreference("extensions.firebug.onByDefault", true);
						firefoxProfile.SetPreference("extensions.firebug.defaultPanelName", "net"); //Panel shown by default; "console", "html", "stylesheet", "script", "dom", "net" + Panels from extensions

						firefoxProfile.SetPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
						firefoxProfile.SetPreference("extensions.firebug.netexport.defaultLogDir", resultDir);
						firefoxProfile.SetPreference("extensions.firebug.netexport.showPreview", false);

						firefoxProfile.SetPreference("extensions.firebug.allPagesActivation", "on"); //Specifies whether Firebug shall be enabled by default for all websites
						firefoxProfile.SetPreference("extensions.firebug.net.enableSites", true); //Specifies whether the Net Panel is enabled

						_driver = new FirefoxDriver(firefoxProfile);
						break;
					}
				case "chrome":
					{
						_driver = new ChromeDriver();
						break;
					}
				}

			_driver.Manage().Window.Maximize();


			return _driver;
		}
Beispiel #2
0
        private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
        {
            FirefoxProfile profileToUse = profile;

            // TODO (JimEvans): Provide a "named profile" override.
            // string suggestedProfile = System.getProperty("webdriver.firefox.profile");
            string suggestedProfile = null;

            if (profileToUse == null && suggestedProfile != null)
            {
                profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
            }
            else if (profileToUse == null)
            {
                profileToUse = new FirefoxProfile();
                profileToUse.AddExtension(false);
            }
            else
            {
                profileToUse.AddExtension(false);
            }

            ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");

            return(extension);
        }
        private IWebDriver BuildFFDriver()
        {
            FirefoxProfile ffProfile = new FirefoxProfile();
            JavaScriptError.AddExtension(ffProfile);

            ffProfile.AddExtension(SaveBinaryResource("firebug-2.0.8-fx.xpi", TestResources.firebug_2_0_8_fx));

            ffProfile.SetPreference("extensions.firebug.showStackTrace", "true");
            ffProfile.SetPreference("extensions.firebug.delayLoad", "false");
            ffProfile.SetPreference("extensions.firebug.showFirstRunPage", "false");
            ffProfile.SetPreference("extensions.firebug.allPagesActivation", "on");
            ffProfile.SetPreference("extensions.firebug.console.enableSites", "true");
            ffProfile.SetPreference("extensions.firebug.defaultPanelName", "console");

            return new FirefoxDriver(ffProfile);
        }
        public void TakeScreenshotsByCityCoordinates()
        {
            FirefoxProfile profile = new FirefoxProfile();
            profile.AddExtension(this.adBlockPath);
            this.driver = new FirefoxDriver(profile);

            //ChromeOptions options = new ChromeOptions();
            //options.AddExtension(this.adBlockChromePath);
            //this.driver = new ChromeDriver(this.chromeDriverPath, options);

            this.driver.Manage().Window.Maximize();
            this.driver.Url = this.baseUrl;
            this.driver.Url = this.cityListUrl;

            CityListPage cityListPage = new CityListPage();
            this.WaitForElement(cityListPage.ResultsTableLocator);
            IWebElement[] links = this.driver.FindElements(cityListPage.ResultsTableLocator).ToArray();

            List<string> linkUrls = new List<string>();
            for (int i = 0; i < 10; i++)
            {
                linkUrls.Add(links[i].GetAttribute("href"));
            }

            CityInfoPage cityInfoPage = new CityInfoPage();
            GoogleMapsPage googleMapsPage = new GoogleMapsPage();
            foreach (var linkUrl in linkUrls)
            {
                this.driver.Url = linkUrl;
                this.WaitForElement(cityInfoPage.CityTableLocator);

                CityInfo info = cityInfoPage.GetCityInfo(this.driver);

                this.driver.Url = info.GoogleMapsLink;
                this.WaitForElement(googleMapsPage.StreetViewControl);
                this.TakeScreenshot(this.screenshotsPath + info.ToString() + ".jpg");
            }

            this.driver.Dispose();
        }
Beispiel #5
0
        private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
        {
            FirefoxProfile profileToUse = profile;

            string suggestedProfile = Environment.GetEnvironmentVariable("webdriver.firefox.profile");

            if (profileToUse == null && suggestedProfile != null)
            {
                profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
            }
            else if (profileToUse == null)
            {
                profileToUse = new FirefoxProfile();
                profileToUse.AddExtension(false);
            }
            else
            {
                profileToUse.AddExtension(false);
            }

            ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");

            return(extension);
        }
        private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
        {
            FirefoxProfile profileToUse = profile;

            string suggestedProfile = Environment.GetEnvironmentVariable("webdriver.firefox.profile");
            if (profileToUse == null && suggestedProfile != null)
            {
                profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
            }
            else if (profileToUse == null)
            {
                profileToUse = new FirefoxProfile();
                profileToUse.AddExtension(false);
            }
            else
            {
                profileToUse.AddExtension(false);
            }

            ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");
            return extension;
        }
Beispiel #7
0
        private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
        {
            FirefoxProfile profileToUse = profile;

            // TODO (JimEvans): Provide a "named profile" override.
            // string suggestedProfile = System.getProperty("webdriver.firefox.profile");
            string suggestedProfile = null;
            if (profileToUse == null && suggestedProfile != null)
            {
                profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
            }
            else if (profileToUse == null)
            {
                profileToUse = new FirefoxProfile();
                profileToUse.AddExtension(false);
            }
            else
            {
                profileToUse.AddExtension(false);
            }

            ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");
            return extension;
        }
        public tstObject(int typNum, ref string profilePath, string baseURL)
        {
            brwsrType = typNum;

                switch (typNum)
                {
                    case 0:
                    {
                        SafariOptions opt1 = new SafariOptions();
                        opt1.CustomExtensionPath = Application.StartupPath + "\\SafariDriver2.32.0.safariextz";
                        opt1.SkipExtensionInstallation = false;

                        driver = new SafariDriver(opt1);
                        break;
                    }
                    case 1:
                    {
                        string runProfile = Application.StartupPath + "\\Firefox Profile";
                        string firebugPath = Application.StartupPath + "\\Firefox Profile\\firebug-1.9.2.xpi";
                        FirefoxProfile profile = new FirefoxProfile(runProfile);

                        //add firebug to the profile
                        //profile.AddExtension(firebugPath);

                        //add firePath to the profile
                        profile.AddExtension(firebugPath);

                        //set the webdriver_assume_untrusted_issuer to false
                        profile.SetPreference("webdriver_assume_untrusted_issuer", false);

                        //run the profile
                        driver = new FirefoxDriver(profile);

                        //maximize window
                        driver.Manage().Window.Maximize();

                        //Wait 4 seconds for an item to appear
                        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
                        break;
                    }
                    //create a Chrome object
                    case 2:
                    {
                        var options = new ChromeOptions();

                        //set the startup options to start maximzed
                        options.AddArguments("start-maximized");

                        //start Chrome maximized
                        driver = new ChromeDriver(@Application.StartupPath, options);

                        //Wait 10 seconds for an item to appear
                        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
                        break;
                    }

                    //create an IE object
                    case 3:
                    {
                        //var options = new InternetExplorerOptions();

                        //set the startup options to start maximzed
                        //options.ToCapabilities();

                        driver = new InternetExplorerDriver(@Application.StartupPath);

                        //maximize window
                        driver.Manage().Window.Maximize();

                        //Wait 4 seconds for an item to appear
                        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));

                        break;
                    }
                }
        }
 /// <summary>
 /// Adds the Firefox extension collecting JS errors to the profile, which allows later use of
 /// ReadErrors(WebDriver).
 /// </summary>
 /// <example><code>
 /// FirefoxProfile profile = new FirefoxProfile();
 /// JavaScriptError.AddExtension(profile);
 /// IWebDriver driver = new FirefoxDriver(profile);
 /// </code></example>
 public static void AddExtension(FirefoxProfile ffProfile)
 {
     ffProfile.AddExtension(extractedXpiPath);
 }
 public static void AddExtension(FirefoxProfile ffProfile, string xpiDirectory)
 {
     ffProfile.AddExtension(Path.Combine(xpiDirectory, xpiFilename));
 }
 private static FirefoxProfile GetFirefoxptions()
 {
     var profile = new FirefoxProfile();
     profile.AddExtension(@"C:\downloads\FirefoxGoogleAnalytics.xpi");
     return profile;
 }
Beispiel #12
0
        public void IntiailizeDriver(ref IWebDriver driver, ref bool isBrowserDimendion, ref List<IWebDriver> driverlist, ref int width, ref int height, ref string addonsPath)
        {
            if ((FirefoxProfilePath.Length != 0) && Directory.Exists(FirefoxProfilePath) && (FirefoxProfilePath.Split('.').Last().ToString().ToLower() != "zip"))
            {
                string ffProfileSourcePath = FirefoxProfilePath;
                DirectoryInfo ffProfileSourceDir = new DirectoryInfo(ffProfileSourcePath);

                if (!ffProfileSourceDir.Exists)
                    throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0012"));

                FfProfile = new FirefoxProfile(ffProfileSourceDir.ToString());
                if ((Common.Utility.GetParameter("FirefoxProfilePath")).Equals(Common.Utility.GetVariable("FirefoxProfilePath")))
                {
                    InitFireFox(ref driver,ref isBrowserDimendion,ref driverlist,ref width,ref height);
                    Common.Utility.SetVariable("FirefoxProfilePath", _ffProfileDestDir.ToString());
                }
                else
                {
                    //If Profile path is empty in parameter file then add setpreference to profile.:
                    if (Common.Utility.GetParameter("FirefoxProfilePath").Equals(""))
                    {
                        FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                    }
                    InitFireFox(ref driver, ref isBrowserDimendion, ref driverlist, ref width, ref height);
                }
            }
            else
            {
                // If "addonsPath" contains path then load addons from that directory path.
                if (addonsPath.Length != 0)
                {
                    try
                    {
                        string adPath = addonsPath;
                        if (!Directory.Exists(adPath))
                            throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0014"));
                        DirectoryInfo adDir = new DirectoryInfo(adPath);
                        DirectoryInfo adDirTemp = new DirectoryInfo("AddonsTemp");
                        adDirTemp.Create();
                        foreach (FileInfo fi in adDir.GetFiles())
                        {
                            fi.CopyTo(Path.Combine(adDirTemp.FullName, fi.Name), true);
                        }

                        int firebugCount = 0;
                        string[] addonFilePaths = Directory.GetFiles(adPath);
                        FfProfile = new FirefoxProfile();
                        FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                        FfProfile.SetPreference("network.cookie.lifetimePolicy", 0);
                        FfProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
                        FfProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
                        SetCommonPreferences();
                        //Assigning profile location so that firefox can next time use same profile to open
                        Common.Utility.SetVariable("FirefoxProfilePath", FfProfile.ProfileDirectory.ToString());
                        // Add all the addons found in the specified addon directory
                        foreach (FileInfo afi in adDirTemp.GetFiles())
                        {
                            if (afi.Name.ToLower().Contains("firebug"))
                                firebugCount++;
                            FfProfile.AddExtension(adDirTemp.Name + '/' + afi.Name);
                        }

                        // If user placed multiple versions of firebug in Addons directory then give error
                        if (firebugCount > 1)
                            throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0015"));

                        // Start firefox with the profile that contains all the addons in addon directory
                        driver = new FirefoxDriver(FfProfile);
                        driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                        driver.Manage().Window.Maximize();
                        if (isBrowserDimendion)
                            driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                        driverlist.Add(driver);
                    }
                    catch (Exception e)
                    {
                        throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0009").Replace("{MSG}", e.Message));
                    }
                }
                else
                {
                    int webDriverPort = 7055;
                    FfProfile = new FirefoxProfile();
                    FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                    FfProfile.SetPreference("network.cookie.lifetimePolicy", 0);
                    FfProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
                    FfProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
                    SetCommonPreferences();
                    for (int port = webDriverPort; port <= webDriverPort + 5; port++)
                    {
                        //Allowing security exception to appear and being able to handle.
                        FfProfile.SetPreference("browser.xul.error_pages.expert_bad_cert", true);
                        FfProfile.AcceptUntrustedCertificates = true;
                        string profileDir = FfProfile.ProfileDirectory;
                        FfProfile.Port = port;
                        driver = new FirefoxDriver(FfProfile);
                        driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                        driver.Manage().Window.Maximize();
                        if (isBrowserDimendion)
                            driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                        driverlist.Add(driver);
                        //Assigning profile location so that firefox can next time use same profile to open
                        Common.Utility.SetVariable("FirefoxProfilePath", FfProfile.ProfileDirectory.ToString());
                        break;
                    }

                    if (driver == null)
                    {
                        throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0016"));
                    }
                }
                //Add WebDriver Profile File to list of files that need to be deleted in temp folder.
                Common.Property.ListOfFilesInTempFolder.Add(Common.Utility.GetVariable("FirefoxProfilePath"));
            }
        }
 /// <summary>
 /// Adds the Firefox extension collecting JS errors to the profile what allows later use of ReadErrors(WebDriver).
 ///  
 ///  Example:
 ///  
 ///     FirefoxProfile profile = new FirefoxProfile();
 ///     JavaScriptError.AddExtension(profile);
 ///     IWebDriver driver = new FirefoxDriver(profile);
 ///  
 /// </summary>
 /// <param name="ffProfile"></param>
 /// <param name="xpiDirectory"></param>
 public static void AddExtension(FirefoxProfile ffProfile, string xpiDirectory)
 {
     ffProfile.AddExtension(Path.Combine(xpiDirectory, "JSErrorCollector.xpi"));
 }
Beispiel #14
0
        /// <summary>
        ///  This method initialize specified web driver.
        ///  Updated for Window Resizing 
        /// /// </summary>
        private void initDriver(bool DeleteCookie=true)
        {
            try
            {

                Property.isSauceLabExecution = false;
                if (string.Compare(isRemoteExecution, "false", true) == 0)
                {
                    switch (browserName.ToLower())
                    {
                        case KryptonConstants.BROWSER_FIREFOX:
                            // If "firefoxProfilePath" contains path then load profile from that directory path.
                            if ((Browser.firefoxProfilePath.Length != 0) && Directory.Exists(Browser.firefoxProfilePath) && (Browser.firefoxProfilePath.Split('.').Last().ToString().ToLower() != "zip"))

                            {
                                string ffProfileSourcePath = Browser.firefoxProfilePath;
                                DirectoryInfo ffProfileSourceDir = new DirectoryInfo(ffProfileSourcePath);

                                if (!ffProfileSourceDir.Exists)
                                    throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0012"));

                                if ((Common.Utility.GetParameter("FirefoxProfilePath")).Equals(Common.Utility.GetVariable("FirefoxProfilePath")))
                                {
                                    #region  This section works for 2.0rc2 release of selenium

                                    ffProfile = new FirefoxProfile(ffProfileSourceDir.ToString());
                                    //Support for Firefox version 5.0
                                    ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);
                                    #region Handling Downloading Window.
                                    ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.useDownloadDir", true);
                                    ffProfile.SetPreference("browser.download.defaultFolder", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.folderList", 2);
                                    ffProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
                                    #endregion
                                    #region Handling Unresponsive Script Warning.
                                    ffProfile.SetPreference("dom.max_script_run_time", 10 * 60);
                                    ffProfile.SetPreference("dom.max_chrome_script_run_time", 10 * 60);
                                    #endregion
                                    driver = new FirefoxDriver(ffProfile);
                                    driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                                    driver.Manage().Window.Maximize();
                                    if (IsBrowserDimendion)
                                        driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                                    driverlist.Add(driver);
                                    DirectoryInfo ffProfileDestDir = new DirectoryInfo(ffProfile.ProfileDirectory);

                                    //Assigning profile location so that firefox can next time use same profile to open
                                    Common.Utility.SetVariable("FirefoxProfilePath", ffProfileDestDir.ToString());
                                    #endregion
                                }

                               // This else loop approches where there is a profile already created within same test case
                                else
                                {
                                    ffProfile = new FirefoxProfile(ffProfileSourceDir.ToString());
                                    //If Profile path is empty in parameter file then add setpreference to profile.:
                                    if (Common.Utility.GetParameter("FirefoxProfilePath").Equals(""))
                                    {
                                        ffProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                                    }
                                    //For ff5.0 version support.
                                    ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);
                                    #region Handling Downloading Window.
                                    ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.useDownloadDir", true);
                                    ffProfile.SetPreference("browser.download.defaultFolder", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.folderList", 2);
                                    ffProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
                                    #endregion
                                    #region Handling Unresponsive Script Warning.
                                    ffProfile.SetPreference("dom.max_script_run_time", 10 * 60);
                                    ffProfile.SetPreference("dom.max_chrome_script_run_time", 10 * 60);
                                    #endregion
                                    ffProfile.Port = 9966;
                                    driver = new FirefoxDriver(ffProfile);
                                    driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                                    driver.Manage().Window.Maximize();
                                    if (IsBrowserDimendion)
                                        driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                                    driverlist.Add(driver);
                                }

                            }
                            else
                            {
                                // If "addonsPath" contains path then load addons from that directory path.
                                if (Browser.addonsPath.Length != 0)
                                {
                                    try
                                    {
                                        string adPath = Browser.addonsPath;

                                        if (!Directory.Exists(adPath))
                                            throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0014"));

                                        DirectoryInfo adDir = new DirectoryInfo(adPath);
                                        DirectoryInfo adDirTemp = new DirectoryInfo("AddonsTemp");
                                        adDirTemp.Create();
                                        foreach (FileInfo fi in adDir.GetFiles())
                                        {
                                            fi.CopyTo(Path.Combine(adDirTemp.FullName, fi.Name), true);
                                        }

                                        int firebugCount = 0;
                                        string[] addonFilePaths = Directory.GetFiles(adPath);
                                        ffProfile = new FirefoxProfile();
                                        ffProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                                        ffProfile.SetPreference("network.cookie.lifetimePolicy", 0);
                                        ffProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
                                        ffProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
                                        // for ff5 support.
                                        ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);
                                        #region Handling Downloading Window.
                                        ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
                                        ffProfile.SetPreference("browser.download.useDownloadDir", true);
                                        ffProfile.SetPreference("browser.download.defaultFolder", Common.Utility.GetParameter("downloadpath"));
                                        ffProfile.SetPreference("browser.download.folderList", 2);
                                        ffProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
                                        #endregion
                                        #region Handling Unresponsive Script Warning.
                                        ffProfile.SetPreference("dom.max_script_run_time", 10 * 60);
                                        ffProfile.SetPreference("dom.max_chrome_script_run_time", 10 * 60);
                                        #endregion
                                        //Assigning profile location so that firefox can next time use same profile to open
                                        Common.Utility.SetVariable("FirefoxProfilePath", ffProfile.ProfileDirectory.ToString());

                                        // Add all the addons found in the specified addon directory
                                        foreach (FileInfo afi in adDirTemp.GetFiles())
                                        {
                                            if (afi.Name.ToLower().Contains("firebug"))
                                                firebugCount++;

                                            ffProfile.AddExtension(adDirTemp.Name + '/' + afi.Name);
                                        }

                                        // If user placed multiple versions of firebug in Addons directory then give error
                                        if (firebugCount > 1)
                                            throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0015"));

                                        // Start firefox with the profile that contains all the addons in addon directory
                                        driver = new FirefoxDriver(ffProfile);
                                        driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                                        driver.Manage().Window.Maximize();
                                        if (IsBrowserDimendion)
                                            driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                                        driverlist.Add(driver);
                                    }
                                    catch (Exception e)
                                    {
                                        throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0009").Replace("{MSG}", e.Message));
                                    }
                                }
                                else
                                {
                                    int webDriverPort = 7055;
                                    ffProfile = new FirefoxProfile();
                                    ffProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
                                    ffProfile.SetPreference("network.cookie.lifetimePolicy", 0);
                                    ffProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
                                    ffProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
                                    ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);//For FF5 version support.

                                    #region Handling Downloading Window.
                                    ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.useDownloadDir", true);
                                    ffProfile.SetPreference("browser.download.defaultFolder", Common.Utility.GetParameter("downloadpath"));
                                    ffProfile.SetPreference("browser.download.folderList", 2);
                                    ffProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
                                    #endregion
                                    #region Handling Unresponsive Script Warning.
                                    ffProfile.SetPreference("dom.max_script_run_time", 10 * 60);
                                    ffProfile.SetPreference("dom.max_chrome_script_run_time", 10 * 60);
                                    #endregion
                                    for (int port = webDriverPort; port <= webDriverPort + 5; port++)
                                    {
                                        // Allowing security exception to appear and being able to handle
                                        ffProfile.SetPreference("browser.xul.error_pages.expert_bad_cert", true);
                                        ffProfile.AcceptUntrustedCertificates = true;
                                        string profileDir = ffProfile.ProfileDirectory;
                                        ffProfile.Port = port;
                                        driver = new FirefoxDriver(ffProfile);
                                        driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                                        driver.Manage().Window.Maximize();
                                        if (IsBrowserDimendion)
                                            driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                                        driverlist.Add(driver);
                                        //Assigning profile location so that firefox can next time use same profile to open
                                        Common.Utility.SetVariable("FirefoxProfilePath", ffProfile.ProfileDirectory.ToString());

                                        break;
                                    }

                                    if (driver == null)
                                    {
                                        throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0016"));
                                    }
                                }
                                //Add WebDriver Profile File to list of files that need to be deleted in temp folder.
                                Common.Property.listOfFilesInTempFolder.Add(Common.Utility.GetVariable("FirefoxProfilePath"));
                            }
                            break;
                        case KryptonConstants.BROWSER_IE:

                            InternetExplorerOptions options = new InternetExplorerOptions();
                            // Commented to check CSA related problem
                            options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                         //for merging mobile build

                         options.EnablePersistentHover = false; //added for IE-8 certificate related issue.
                            if (DeleteCookie)
                            {
                                options.EnsureCleanSession = true;
                            }
                            driver = new InternetExplorerDriver(Property.ApplicationPath+@"\Exes",options);
                            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                            driver.Manage().Window.Maximize();    //  Added to maximize IE window forcibely, as this code is updated Action file.
                            if (IsBrowserDimendion)
                                driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                            driverlist.Add(driver);
                            break;

                        case Common.KryptonConstants.BROWSER_CHROME:
                            // Selenium v 2.1.17 states to use chrome options instead of capabilities
                            if(signal==0)
                            {
                                if ((Directory.Exists(Browser.chromeProfilePath)))
                                {
                                    string chromeProfileSourcePath = Browser.chromeProfilePath;
                                    DirectoryInfo chromeProfileSourceDir = new DirectoryInfo(chromeProfileSourcePath);

                                    if (!chromeProfileSourceDir.Exists)
                                        throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0012"));
                                    if (File.Exists(chromeProfilePath+ @"\ChromeOptions.txt"))
                                    {
                                        using (StreamReader reader = new StreamReader(chromeProfilePath + @"\ChromeOptions.txt"))
                                        {
                                            string line = string.Empty;
                                            while ((line = reader.ReadLine()) != null)
                                            {
                                                chromeOpt.AddArgument(line);
                                            }

                                        }
                                    }
                                }
                            chromeOpt.AddArguments("--test-type");
                            chromeOpt.AddArgument("--ignore-certificate-errors");
                            chromeOpt.AddArgument("--start-maximized");
                            System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(chromecookPath);
                            Empty(directory);
                            chromeOpt.AddArguments("user-data-dir="+chromecookPath);
                            signal = 1;
                            }
                            driver = new ChromeDriver(Property.ApplicationPath+@"\Exes", chromeOpt);
                            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                            driver.Manage().Window.Maximize();
                            if (IsBrowserDimendion)
                                driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                            driverlist.Add(driver);
                            break;
                        case KryptonConstants.BROWSER_SAFARI:
                            driver = new SafariDriver();
                            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
                            driver.Manage().Window.Maximize();
                            if (IsBrowserDimendion)
                                driver.Manage().Window.Size = new System.Drawing.Size(width, height);
                            driverlist.Add(driver);
                            break;
                        default:
                            Console.WriteLine("No browser is defined.");
                            break;
                    }
                    WebDriverWait wdw = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, new TimeSpan(1000));
                }
                else
                {
                    // Attempt by  for sauce execution
                    //Start
                    if (Common.Property.RemoteUrl.ToLower().Contains("saucelabs"))
                    {
                        DesiredCapabilities capabilities = new DesiredCapabilities();
                            Utility.SetParameter("CloseBrowserOnCompletion", "true");//Forcing the close browser to true.
                            Utility.SetVariable("CloseBrowserOnCompletion", "true");
                            Property.isSauceLabExecution = true;
                            capabilities.SetCapability("username", Common.Utility.GetParameter("username"));//Registered user name of Sauce labs
                            capabilities.SetCapability("accessKey", Common.Utility.GetParameter("password"));// Accesskey provided by the Sauce labs
                            capabilities.SetCapability("platform", Common.Utility.GetParameter("Platform"));// OS on which execution is to be done Eg: Windows 7 , mac , Linux etc..
                            capabilities.SetCapability("name", Common.Utility.GetParameter("TestCaseId"));
                            capabilities.SetCapability("browser", Common.Utility.GetParameter("SauceBrowser"));
                            capabilities.SetCapability("version", Common.Utility.GetParameter("VersionofBrowser"));
                            string RemoteHost = string.Empty;
                            remoteUrl = Common.Property.RemoteUrl + "/wd/hub";

                            // if Sauce connect is required...
                            string isSauceConnectRequired = Common.Utility.GetParameter("IsTestEnvironment");
                            if (isSauceConnectRequired.ToLower()=="true")
                            {
                                executeSauceConnect();
                                Thread.Sleep(20 * 1000);
                            }

                            SeleniumGrid oSeleniumGrid = new SeleniumGrid(remoteUrl, Common.Utility.GetParameter("SauceBrowser"), capabilities);
                            Browser.driver = oSeleniumGrid.GetDriverSauce();
                            if (!string.IsNullOrEmpty(RemoteHost))
                            {
                                Common.Property.RCMachineId = RemoteHost;
                                Utility.SetVariable(Common.Property.RCMachineId, RemoteHost);
                                Utility.SetParameter(Common.Property.RCMachineId, RemoteHost);
                            }
                            driverActions = new Actions(driver);

                    }
                    else
                    {
                        string RemoteHost = string.Empty;
                    remoteUrl = Common.Property.RemoteUrl + "/wd/hub";
                     // (management of remote driver in a seperate class)
                    SeleniumGrid oSeleniumGrid = new SeleniumGrid(remoteUrl, browserName);
                    Browser.driver = oSeleniumGrid.GetDriver(out RemoteHost);
                    if (!string.IsNullOrEmpty(RemoteHost))
                    {
                        Common.Property.RCMachineId = RemoteHost;
                        Utility.SetVariable(Common.Property.RCMachineId, RemoteHost);
                        Utility.SetParameter(Common.Property.RCMachineId, RemoteHost);

                    }

                    //Initializing actions object for later usage
                    driverActions = new Actions(driver);
                    }
                }
            }
            catch (WebDriverException e)
            {
                if (e.Message.Contains(Common.exceptions.ERROR_NORESPONSEURL) || e.Message.IndexOf("Connection refused", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    if (isRemoteExecution.Equals("true"))
                    {

                        this.initDriver();

                    }
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw e;
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf(Common.exceptions.ERROR_PARSINGVALUE, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    if (isRemoteExecution.Equals("true"))
                    {
                        this.initDriver();
                    }
                    throw new WebDriverException(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0007") + ":" + e.Message);
                }
                throw e;
            }
        }
        private IWebDriver BuildFFDriver()
        {
            FirefoxProfile ffProfile = new FirefoxProfile();
            
            string xpiPath;
            int depth = 0;
            do
            {
                string relative = "";
                for (int i = 0; i < depth; i++)
                    relative += @"..\";

                xpiPath = Path.Combine(TestContext.DeploymentDirectory, relative, @"dist\JSErrorCollector.xpi");

                depth++;
                if (depth > 10)
                    throw new FileNotFoundException("Could not find JSErrorCollector.xpi after 10 iterations.");

            } while (!File.Exists(xpiPath));

            ffProfile.AddExtension(xpiPath);

            return new FirefoxDriver(ffProfile);
        }
Beispiel #16
-1
 private RemoteWebDriver OpenPage(string url)
 {
     var profile = new FirefoxProfile();
     profile.AddExtension("firebug-1.6.2.xpi");
     profile.SetPreference("extensions.firebug.currentVersion", "9.99");
     RemoteWebDriver driver = new FirefoxDriver(profile);
     driver.Navigate().GoToUrl(url);
     return driver;
 }