private static void Main() { var testDriverFactory = new TestDriverFactory( new DriverOptions { DriverExePath = ConfigurationManager.AppSettings["FirefoxDriverPath"], Port = int.Parse(ConfigurationManager.AppSettings["FirefoxBrowserPort"]), Url = ConfigurationManager.AppSettings["StartUrl"] }); var firfoxTestDriver = testDriverFactory.CreateTestDriver <FirefoxTestDriver>(); firfoxTestDriver.GoToUrl(null); // will use default passed in to factory as part of DriverOptions struct firfoxTestDriver.MaximiseWindow(); firfoxTestDriver.MouseOverElement(FinderStrategy.PartialLinkText, "HACCP Certification"); firfoxTestDriver.FindByPartialLinkTextClick("HACCP Principles", ExpectedCondition.ElementIsVisible, 10); var heading = firfoxTestDriver.FindByTagName("h1", seconds: 5); Console.WriteLine(heading.Text); firfoxTestDriver.Quit(); Console.WriteLine("{0}Press any key to close ...", Environment.NewLine); Console.ReadKey(); }
private static ITestDriver GetNewChromeTestDriver() { ITestDriverFactory foundry = new TestDriverFactory(new DriverOptions { DriverExePath = ConfigurationManager.AppSettings["ChromeExePath"], Port = int.Parse(ConfigurationManager.AppSettings["ChromeBrowserPort"]) }); var chromeTestDriver = foundry.CreateTestDriver <ChromeTestDriver>(); return(chromeTestDriver); }
static void Main(string[] args) { ITestDriverFactory testDriverFactory = new TestDriverFactory( new KesselRun.SeleniumCore.Infrastructure.DriverOptions { DriverExePath = ConfigurationManager.AppSettings["ChromeDriverPath"], Port = int.Parse(ConfigurationManager.AppSettings["ChromeBrowserPort"]), Url = ConfigurationManager.AppSettings["StartUrl"] }); var chromeTestDriver = testDriverFactory.CreateTestDriver <ChromeTestDriver>(); chromeTestDriver.GoToUrl(null); // will use default passed in to factory as part of DriverOptions struct chromeTestDriver.MaximiseWindow(); try { var heading = chromeTestDriver.FindByXPath("//*[@id='mainheader']", seconds: 5); // #menuLink2 is the javascript selector for the menu item to hover Console.WriteLine("Heading: {0}", heading.TagName); Debug.WriteLine("Heading: {0}", heading.TagName); //var day = chromeTestDriver.FindByXPath("(//*[@id='mainheader']/ancestor::div[@class='contentwrapper']/div[starts-with(@class,'container')])[1]", ExpectedCondition.ElementIsVisible, 5); var day = chromeTestDriver.FindByXPath("//*[@id='mainheader']/ancestor::div[@class='contentwrapper']/div[5]", ExpectedCondition.ElementIsVisible, 5); day.Click(); Console.WriteLine("Day: {0}", day.Text); //var ps = chromeTestDriver.FindByXPathFromWebElement(day, "following-sibling::div[1]/child::p", 5); var ps = day.FindElements(By.XPath(@"following-sibling::div[1]/child::p")); //var ps = day.FindElement(By.XPath("self::div")); Console.WriteLine(day.Text); //Console.WriteLine("Elem: {0}", ps.Text); //var day = chromeTestDriver.FindByXPathFromWebElement(heading, "(//*div[following-sibling::div])[1]", 5); Trace.WriteLine("Hit IT!"); } catch (Exception e) { //Trace.WriteLine("Wrong!"); //chromeTestDriver.MouseOverElement(FinderStrategy.Id, "menuLink2"); // #menuLink2 is the javascript selector for the menu item to hover //chromeTestDriver.FindByIdClickWithRetries("menuLink2_1"); } chromeTestDriver.Quit(); Console.WriteLine("{0}Press any key to close ...", Environment.NewLine); Console.ReadKey(); }
private static ITestDriver GetNewFirefoxTestDriver() { ITestDriverFactory foundry = new TestDriverFactory(new DriverOptions { DriverExePath = ConfigurationManager.AppSettings["FirefoxExePath"], Port = int.Parse(ConfigurationManager.AppSettings["FirefoxBrowserPort"]), Url = ConfigurationManager.AppSettings["StartUrl"] }); var firefoxTestDriver = foundry.CreateTestDriver <FirefoxTestDriver>(); return(firefoxTestDriver); }
public void GlobalSetup() { UiTestContext.Driver = TestDriverFactory.CreateDriver(); UiTestContext.Extent = ExtentReportsFactory.CreateHtmlReporter(UiTestContext.Driver, FileUtil.GetCurrentDirectory()); }
private bool ForEachDriver <T>(MultiMap <TestFrameworkSelection, T> testFrameworkPartitions, Func <ITestDriver, IList <T>, int, bool> func) where T : class { var testDriverPartitions = new Dictionary <TestDriverFactory, TestDriverData <T> >(); foreach (var testFrameworkPartition in testFrameworkPartitions) { if (testFrameworkPartition.Value.Count != 0) { TestFrameworkSelection testFrameworkSelection = testFrameworkPartition.Key; ComponentHandle <ITestFramework, TestFrameworkTraits> testFrameworkHandle = testFrameworkSelection.TestFrameworkHandle; TestDriverFactory testDriverFactory = testFrameworkHandle.GetComponent().GetTestDriverFactory(); TestDriverData <T> testDriverData; if (!testDriverPartitions.TryGetValue(testDriverFactory, out testDriverData)) { testDriverData = new TestDriverData <T>(testFrameworkSelection.TestFrameworkOptions); testDriverPartitions.Add(testDriverFactory, testDriverData); } else { testDriverData.ItemIndex = new HashSet <T>(ReferentialEqualityComparer <T> .Instance); GenericCollectionUtils.AddAll(testDriverData.Items, testDriverData.ItemIndex); } testDriverData.TestFrameworkHandles.Add(testFrameworkHandle); foreach (var item in testFrameworkPartition.Value) { if (testDriverData.ItemIndex == null) { testDriverData.Items.Add(item); } else if (!testDriverData.ItemIndex.Contains(item)) { testDriverData.Items.Add(item); testDriverData.ItemIndex.Add(item); } } } } int testDriverCount = testDriverPartitions.Count; foreach (var testDriverPartition in testDriverPartitions) { TestDriverFactory testDriverFactory = testDriverPartition.Key; TestDriverData <T> testDriverData = testDriverPartition.Value; try { ITestDriver driver = testDriverFactory(testDriverData.TestFrameworkHandles, testDriverData.TestFrameworkOptions, logger); if (func(driver, testDriverData.Items, testDriverCount)) { return(true); } } catch (Exception ex) { //UnhandledExceptionPolicy.Report("An unhandled exception occurred while invoking a test driver.", ex); throw new ModelException("An exception occurred while invoking a test driver.", ex); } } return(false); }