public static IWebElement By(IWebDriver driver, By selector) { IWebElement elementToReturn = null; string dirPath = System.IO.Directory.GetCurrentDirectory(); String format = "dd.hh.mm.ss.ffffff";//"dd-mm-yyyy.hh.mm.tt"; driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); try { elementToReturn = driver.FindElement(selector); } catch (NoSuchElementException e) { TakeScreenshot.SaveAs(driver, $"{dirPath}\\Screenshots", DateTime.Now.ToString(format)); throw new NoSuchElementException("exception thrown", e); } catch (Exception e) { TakeScreenshot.SaveAs(driver, $"{dirPath}\\Screenshots", DateTime.Now.ToString(format)); throw e; } // return either the element or null return(elementToReturn); }
public void TearDown(IWebDriver driver) { var result = TestContext.CurrentContext.Result.Outcome.ToString(); var testName = TestContext.CurrentContext.Test.Name; Logger logger = LogManager.GetLogger($"Scenario: { testName }"); if (result == "Passed") { logger.Info("Test Passed"); } else if (result == "Failed") { Console.WriteLine("it failed"); string dirPath = System.IO.Directory.GetCurrentDirectory(); String format = "dd.hh.mm.ss.ffffff";//"dd-mm-yyyy.hh.mm.tt"; string dateTime = testName + DateTime.Now.ToString(format); string filePath = $"{ dirPath }\\Screenshots"; string fileName = $"{ dateTime }"; TakeScreenshot.SaveAs(driver, $"{ dirPath }\\Screenshots", dateTime); logger.Info($"Test Failed: see screenshot: { filePath + "\\" + fileName + ".Png" }"); } else { logger.Info(result); string dirPath = System.IO.Directory.GetCurrentDirectory(); String format = "dd.hh.mm.ss.ffffff";//"dd-mm-yyyy.hh.mm.tt"; string dateTime = testName + DateTime.Now.ToString(format); string filePath = $"{ dirPath }\\Screenshots"; string fileName = $"{ dateTime }"; TakeScreenshot.SaveAs(driver, $"{ dirPath }\\Screenshots", dateTime); logger.Info($"Test Failed: see screenshot: { filePath + "\\" + fileName + ".Png" }"); } driver.Close(); driver.Quit(); }
public static void element(IWebDriver driver, By id) { driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); driver.FindElement(id); TakeScreenshot.SaveAs(driver, "C:\\CSharpUITestProject\\UITestProject\\UITests", "testScreenshotMethod"); }
public static void Element(IWebDriver driver, By id) { Find.Element(driver, id); TakeScreenshot.SaveAs(driver, "C:\\CSharpUITestProject\\UITestProject\\UITests", "testScreenshotMethod"); }