public Profile[] Discover() { var resultProfilesList = new List<Profile>(); IEnumerable<string> files = Directory.EnumerateFiles(GetProfilesDir(), ProfileFileMaskSearchPattern); foreach (var file in files) { var profile = new Profile(); profile.FileName = Path.GetFileName(file); try { string fileContent = File.ReadAllText(file); JObject parser = JObject.Parse(fileContent); var parsedProfile = parser.ToObject<ProfileConfigurationMapping>(); profile.ProfileConfig = parsedProfile; } catch (Exception ex) { profile.HasErrors = true; profile.Exception = ex; _logger.Error(ex); } resultProfilesList.Add(profile); } resultProfilesList = resultProfilesList.OrderBy(item => item.ProfileConfig.profile.displayPriority) .ThenBy(item => item.DisplayName) .ToList(); return resultProfilesList.ToArray(); }
public void CloseDriver_should_close_the_opened_browser_instance() { Profile browserProfile = new Profile(); browserProfile.ProfileConfig.activation.browserName = WebDriverOptions.browser_Firefox; WebDriverOptions options = new WebDriverOptions() { BrowserProfile = browserProfile, IsRemote = false, }; string specialTitle = "SwdBrowser.CloseDriver TEST TEST"; string[] specialWindows = new string[] { }; specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> at the beginning", specialTitle); SwdBrowser.Initialize(options); string changeTitleScript = string.Format("document.title = '{0}'", specialTitle); SwdBrowser.ExecuteJavaScript(changeTitleScript); specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(1, "Expected only 1 window with title <{0}> after new driver was created", specialTitle); SwdBrowser.CloseDriver(); specialWindows = GetDesktopWindowsWithSpecialTitle(specialTitle); specialWindows.Length.Should().Be(0, "Expected no windows with title <{0}> after the driver was closed", specialTitle); }
private int TryFindPreviousIndex(Profile previousValue, Profile[] addedItems) { int index = -1; if (previousValue == null) return index; if (addedItems == null) return index; for (var i = 0; i < addedItems.Length; i++) { if (previousValue.DisplayName != null && addedItems[i].DisplayName == previousValue.DisplayName) { index = i; break; } } return index; }
public void Initialize_should_be_able_to_start_new_browser() { Profile browserProfile = new Profile(); browserProfile.ProfileConfig.activation.browserName = WebDriverOptions.browser_HtmlUnitWithJavaScript; WebDriverOptions options = new WebDriverOptions() { BrowserProfile = browserProfile, IsRemote = true, RemoteUrl = "http://localhost:4444/wd/hub/", }; bool isSeleniumServerAvailable = true; try { SwdBrowser.TestRemoteHub(options.RemoteUrl); } catch (Exception e) { isSeleniumServerAvailable = false; Console.WriteLine("FAILED: " + e.Message); } if (!isSeleniumServerAvailable) { SwdBrowser.RunStandaloneServer("start_selenium_server.bat"); } SwdBrowser.Initialize(options); var rempteDriver = (RemoteWebDriver) SwdBrowser.GetDriver(); rempteDriver.Capabilities.BrowserName.Should().Be("htmlunit"); SwdBrowser.CloseDriver(); }
public static void RunDefaultBrowser() { var browserProfile = new Profile(); browserProfile.ProfileConfig.activation.browserName = "Firefox"; WebDriverOptions options = new WebDriverOptions() { BrowserProfile = browserProfile, }; SwdBrowser.Initialize(options); }