コード例 #1
0
 public static void IsTrue(IWebDriver driver, ExtentTest extentTest, bool assertedValue, string reportingMessage)
 {
     try
     {
         Assert.IsTrue(assertedValue);
         extentTest.Pass(reportingMessage);
         LoggingManager.LogInfo(reportingMessage);
     }
     catch (AssertionException)
     {
         string errorMessage = "Failure occurred when executing check '" + reportingMessage + "'";
         extentTest.Fail(errorMessage, MediaEntityBuilder.CreateScreenCaptureFromPath(ScreenShotsManager.CreateScreenshot(driver)).Build());
         LoggingManager.LogError(errorMessage);
         throw;
     }
 }
コード例 #2
0
        public static IWebDriver GetDriver()
        {
            string     driverType = ConfigurationManager.AppSettings.Get("driver").ToLower();
            IWebDriver driver;
            string     infoMessage = $"Driver type: {driverType}";

            switch (driverType)
            {
            case "chrome":
                driver = new ChromeDriver();
                SetupDriverProperties(driver);
                LoggingManager.LogInfo(infoMessage);
                return(driver);

            case "firefox":
                driver = new FirefoxDriver();
                SetupDriverProperties(driver);
                LoggingManager.LogInfo(infoMessage);
                return(driver);

            case "ie":
                var options = new InternetExplorerOptions
                {
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                    IgnoreZoomLevel    = true,
                    EnableNativeEvents = false
                };

                driver = new InternetExplorerDriver(options);
                SetupDriverProperties(driver);
                LoggingManager.LogInfo(infoMessage);
                return(driver);

            case "edge":
                driver = new EdgeDriver();
                SetupDriverProperties(driver);
                LoggingManager.LogInfo(infoMessage);
                return(driver);

            default:
                string errorMessage = $"Invalid browser name argument! No such browser: {driverType}";
                LoggingManager.LogError(errorMessage);
                throw new ArgumentException(errorMessage);
            }
        }
コード例 #3
0
        public static IWait <IWebDriver> GetDefaultWait(IWebDriver driver)
        {
            string timeoutAsString = ConfigurationManager.AppSettings.Get("timeout").ToLower();
            int    timeout;

            if (!int.TryParse(timeoutAsString, out timeout))
            {
                timeout = DefaultTimeoutTime;
            }

            if (driver == null)
            {
                string errorMessage = "Driver used in Wait can not be null!";
                LoggingManager.LogError(errorMessage);
                throw new ArgumentNullException(errorMessage);
            }

            return(new WebDriverWait(driver, TimeSpan.FromMilliseconds(timeout)));
        }