Example #1
0
 public void AfterScenario(ScenarioContext scenarioContext)
 {
     extent.Flush();
     driver?.Quit();
     driver?.Dispose();
     GC.SuppressFinalize(this);
 }
Example #2
0
        private static void Test(string browserName, IWebDriver webDriver, string testCaseName, Action testAction)
        {
            if (!string.IsNullOrWhiteSpace(browserName))
            {
                Report.SetBrowser(browserName);
            }
            if (!string.IsNullOrWhiteSpace(testCaseName))
            {
                Report.SetTestCaseName(testCaseName);
            }

            try
            {
                testAction();
            }
            catch (Exception e)
            {
                LogManager.GetLogger(nameof(TestWrapper)).LogScreenshot(webDriver, Level.Error, "Test case failed", e);
                throw;
            }
            finally
            {
                webDriver?.Dispose();
            }
        }
        public void After()
        {
            if (_scenarioContext.TestError != null)
            {
                var path = Path.Combine(_baseDir, "Screenshots");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                try
                {
                    ((ITakesScreenshot)_driver)?.GetScreenshot().SaveAsFile($@"{path}\{_scenarioContext.ScenarioInfo.Title}.jpg", ScreenshotImageFormat.Jpeg);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected Error trying to take a screen shot");
                    Console.WriteLine($"Error message: {e.Message}");
                }
            }

            try
            {
                _driver?.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected error disposing driver");
                Console.WriteLine($"Error message: {e.Message}");
            }

            _scenarioContext.ScenarioContainer.Dispose();
        }
 public void Dispose()
 {
     if (!TestFailed)
     {
         driver?.Dispose();
     }
 }
Example #5
0
 public void TearDown()
 {
     _driver?.Quit();
     _driver?.Dispose();
     _edgeService?.Dispose();
     _firefoxService?.Dispose();
 }
Example #6
0
        public void ThenICanLunchTheBrowserWithAUrl(Table table)
        {
            var rows = table.Rows;

            foreach (var row in rows)
            {
                var browserName = row.Values.ElementAt(0);
                var urlValue    = row.Values.ElementAt(1);
                if (browserName == SupportedBrowsers.Chrome.ToString())
                {
                    _driver = _browser?.SetBrowserType(SupportedBrowsers.Chrome).Driver;
                }
                if (browserName == SupportedBrowsers.Edge.ToString())
                {
                    _driver = _browser?.SetBrowserType(SupportedBrowsers.Edge).Driver;
                }
                if (browserName == SupportedBrowsers.Firefox.ToString())
                {
                    _driver = _browser?.SetBrowserType(SupportedBrowsers.Firefox).Driver;
                }
                var uri = new Uri(urlValue);

                _driver?.Navigate().GoToUrl(uri);
                Console.WriteLine($"Browser: {browserName} | URL: {urlValue} | Title: {_driver?.Title}");
                _driver?.Dispose();
            }
        }
        public static void FinishHim(IWebDriver driver)
        {
            driver?.Dispose();
            var processes = Process.GetProcesses();

            foreach (var process in processes)
            {
                try
                {
                    Debug.WriteLine(process.ProcessName);
                    if (process.StartTime > TestRunStartTime)
                    {
                        var shouldKill = false;
                        foreach (var processName in _processesToCheck)
                        {
                            if (process.ProcessName.ToLower().Contains(processName))
                            {
                                shouldKill = true;
                                break;
                            }
                        }
                        if (shouldKill)
                        {
                            process.Kill();
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
        }
        public static void FinishHim(IWebDriver driver)
        {
            driver?.Dispose();
            List <Process> processes = Process.GetProcesses().ToList();

            var subsetOfProcesses = processes.Where(x => _processesToCheck.Exists(y => y.ToLower() == x.ProcessName.ToLower()));

            foreach (var process in subsetOfProcesses)
            {
                try
                {
                    Debug.WriteLine(process.ProcessName);
                    if (_processesToCheck.Any(s => s.Equals(process.ProcessName, StringComparison.OrdinalIgnoreCase)))
                    {
                        if (process.StartTime != null && process.StartTime > TestRunStartTime)
                        {
                            Debug.WriteLine($"Killing Process : {process.ProcessName.ToLower()}");
                            process.Kill();
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
        }
Example #9
0
 public void Dispose()
 {
     WebDriver?.Dispose();
     //if (_process.HasExited == false)
     //{
     //    _process.Kill();
     //}
 }
Example #10
0
 public void BrowserTearDown()
 {
     NonAngularWebDriver?.Quit();
     NonAngularWebDriver?.Dispose();
     Driver?.Quit();
     Driver?.Dispose();
     DriverSetup?.StopServices();
 }
Example #11
0
        public void CloseWebDriver()
        {
            testOutputHelper.WriteLine($"Removing web driver");

            webDriver?.Quit();
            webDriver?.Dispose();
            webDriver = null;
        }
Example #12
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         _driver?.Dispose();
         _driver = null;
     }
 }
Example #13
0
 public void AfterScenario(ScenarioContext scenarioContext)
 {
     if (scenarioContext.TestError != null)
     {
         //_driver.TakeScreenshot().SaveAsFile(Path.Combine("..", "..", "TestResults", $"{scenarioContext.ScenarioInfo.Title}.png"), ScreenshotImageFormat.Png);
     }
     _driver?.Dispose();
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _server?.Dispose();
         _browser?.Dispose();
     }
 }
Example #15
0
        private void Initialize()
        {
            InitializeNotificationArea();

            _applicationPunchState = new ApplicationPunchState();

            InitializeUIControlsDealingWithApplicationState();

            Closing += (s, e) =>
            {
                _webDriver?.Dispose();
                Process.GetProcesses().Where(p => p.ProcessName == "phantomjs" || p.ProcessName == "chromedriver").ToList().ForEach(process => process.Kill());
            };

            Loaded += (s, e) =>
            {
                var punchPage = NavigateToPunchPageAndCollectUIControls();
                LoadPunchTimesIntoApplicationState((IWebElement)punchPage.lblStart, (IWebElement)punchPage.lblEnd);

                _timer = new Timer {
                    Interval = _applicationPunchState.PollingIntervalMinutes * 60 * 1000, Enabled = true, AutoReset = true
                };                                                                                                                             // fires every half-hour (or whatever time interval we set in UI)!
                _timer.Elapsed += (s1, e1) =>
                {
                    lock (__syncLock)
                    {
                        PunchAndRefreshApplicationState();
                    }

                    BindApplicationStateToUI();
                };
            };

            SystemEvents.SessionSwitch += (s, e) =>
            {
                if (e.Reason == SessionSwitchReason.SessionUnlock)  // this is useful first thing in the morning at computer login (or better said unlock)
                {
                    lock (__syncLock)
                    {
                        PunchAndRefreshApplicationState();
                    }

                    BindApplicationStateToUI();
                }
            };
        }
Example #16
0
        public void AfterScenario(ScenarioContext scenarioContext)
        {
            if (scenarioContext.TestError != null)
            {
                TakeScreenshot(scenarioContext);
            }

            _driver?.Dispose();
        }
Example #17
0
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            Driver?.Dispose();
        }
Example #18
0
 public void TestCleanup()
 {
     try
     {
         driver?.Dispose();
     }
     catch (ObjectDisposedException)
     { }
 }
Example #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dispose"></param>
 protected virtual void Dispose(bool dispose)
 {
     if (dispose)
     {
         Stop();
         _webDriver?.Dispose();
         _webDriver = null;
     }
 }
Example #20
0
 public void Dispose()
 {
     if (AppConfigManager.Reporting())
     {
         Reporting.TearDownReport(extent);
     }
     _currentDriver.Close();
     _currentDriver?.Dispose();
     _currentDriver.Quit();
 }
Example #21
0
 /// <summary>
 /// Make sure the web driver is shut down
 /// </summary>
 /// <param name="driver">The web driver</param>
 public static void KillDriver(this IWebDriver driver)
 {
     try
     {
         driver?.Close();
         driver?.Quit();
     }
     finally
     {
         driver?.Dispose();
     }
 }
Example #22
0
 private void DisposeWebDriver(IWebDriver webDriver, string webDriverType)
 {
     try
     {
         webDriver?.Quit();
         webDriver?.Dispose();
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex, $"{webDriverType} stop error");
     }
 }
        public static void Dispose(IWebDriver webDriver, ServicesCollection container)
        {
            try
            {
                webDriver?.Quit();
                webDriver?.Dispose();
                container?.UnregisterSingleInstance <IWebDriver>();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            ProcessCleanupService.KillPreviousDriversAndBrowsersOsAgnostic(TestRunStartTime);
        }
Example #24
0
        public static void Dispose(IWebDriver webDriver, ServicesCollection container)
        {
            try
            {
                webDriver?.Close();
                webDriver?.Quit();
                webDriver?.Dispose();
                container?.UnregisterSingleInstance <IWebDriver>();
            }
            catch (Exception ex)
            {
                DebugInformation.PrintStackTrace(ex);
            }

            ProcessCleanupService.KillPreviousDriversAndBrowsersOsAgnostic(TestRunStartTime);
        }
Example #25
0
        private IWebDriver InitDriverAndGoToUrl(string url)
        {
            IWebDriver driver = null;

            try
            {
                driver = SeleniumExtensions.CreateDefaultWebDriver();
                driver.Navigate().GoToUrl(url);

                return(driver);
            }
            catch (Exception)
            {
                driver?.Dispose();
                throw;
            }
        }
Example #26
0
        public void AfterScenario()
        {
            if (_scenarioContext.TestError != null)
            {
                Log.Error(_scenarioContext.TestError.Message);
                Log.Error(_scenarioContext.TestError.StackTrace);
            }

            Log.Info(_scenarioContext.ScenarioExecutionStatus.ToString());
            Log.Info(" Finished Test Scenario : " + _scenarioContext.ScenarioInfo.Title);

            Log.Info("==================================================================================");
            Log.Info("=====  " + _featureContext.FeatureInfo.Title + " Test Ended               =====");
            Log.Info("==================================================================================");

            _driver?.Close();
            _driver?.Dispose();
        }
        public void SetUp()
        {
            WebDriver = (RemoteWebDriver)DriverManager.CreateDriver(Convert.ToString(TestContext.DataRow["browser"]), Convert.ToString(TestContext.DataRow["version"]), Convert.ToString(TestContext.DataRow["platform"]));
            WebDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMilliseconds(30000));
            WebDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(15000));
            WebDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(15000));
            WebDriver.Manage().Window.Maximize();

            try
            {
                WebDriver.Navigate().GoToUrl("https://bfc-test.bftcloud.com/our-partners");
            }
            catch (WebDriverTimeoutException)
            {
                WebDriver.Dispose();
                Assert.Fail("The driver timed out attempting to load the page.");

            }
        }
Example #28
0
        void Window_Closed(object sender, EventArgs e)
        {
            formData = new FormData
            {
                County     = СountyBox.Text,
                District   = DistrictBox.Text,
                Products   = ProductsBox.Text,
                Category   = new TextRange(CategoryBox.Document.ContentStart, CategoryBox.Document.ContentEnd).Text,
                Periods    = new TextRange(PeriodsBox.Document.ContentStart, PeriodsBox.Document.ContentEnd).Text,
                OGRNIP     = OGRNIPBox.Text,
                FirstName  = FirstnameBox.Text,
                Surname    = SurnameBox.Text,
                FatherName = FatherNameBox.Text,
                Snils      = SnilsBox.Text,
                INN        = INNBox.Text
            };

            if (formData != null)
            {
                SaveData();
            }

            driver?.Dispose();
        }
Example #29
0
 /// <summary>
 /// Dispose WebDriver and pushes erros to console from OrderVerifications class
 /// </summary>
 public void CleanUp(ref IWebDriver driver)
 {
     MessageConsoleCreator message = new MessageConsoleCreator();
     message.DriverDisposed();
     driver.Dispose();
 }
 public void AfterScenario()
 {
     _driver?.Dispose();
 }
 public void Dispose()
 {
     Driver?.Dispose();
 }
Example #32
0
        public void TestMethod1()
        {
            //_driver = new InternetExplorerDriver(@".");

            _driver = new ChromeDriver(@".");

            //Navigate to Carfax
            _driver.Navigate().GoToUrl("http://www.carmax.com/");

            new WebDriverWait(_driver, TimeSpan.FromSeconds(15)).Until(ExpectedConditions.ElementExists((By.ClassName("page"))));

            Console.WriteLine("Opened URL");
            //Finds the Search box
            IWebElement searchInput = _driver.FindElement(By.Id("search"));

            //Enters you text you want in the search box
            searchInput.SendKeys("jeep");

            //Clicks enter to what ever you put in the search box
            searchInput.SendKeys(Keys.Enter);

            //

            //********************* Div Click Down ********
            //*************Use Code to as a div drop down
            _driver.FindElement(By.Id("Exterior Color")).Click();

            //**********************Exterior Color Choice***************

            // Color set to first choice black
            IWebElement ExteriorColorBlack = _driver.FindElement(By.XPath(".//*[@id='r_4294963167']"));
            ExteriorColorBlack.Click();
            //Color Choice Blue
            //IWebElement ExteriorColorBlue = _driver.FindElement(By.XPath(".//*[@id='r_4294963171']"));
            //ExteriorColorBlue.Click();
            //IWebElement ExteriorColorGreen = _driver.FindElement(By.XPath(".//*[@id='r_4294963122']"));
            //ExteriorColorGreen.Click();
            //IWebElement ExteriorColorRed = _driver.FindElement(By.XPath(".//*[@id='r_4294963166']"));
            //ExteriorColorRed.Click();
            //IWebElement ExteriorColorSilver = _driver.FindElement(By.XPath(".//*[@id='r_4294963203']"));
            //ExteriorColorSilver.Click();
            //IWebElement ExteriorColorWhite = _driver.FindElement(By.XPath(".//*[@id='r_4294963172']"));
            //ExteriorColorWhite.Click();

            //***********************Car Features*****************
            // Does not need a Div drop down

            //20inch plus wheels option box
            _driver.FindElement(By.Id("r_811")).Click();
            //4WD/AWD
            //_driver.FindElement(By.Id("r_788")).Click();
            //Air Conditioning option box
            //_driver.FindElement(By.Id("r_780")).Click();
            //Automatic Transmisson
            //_driver.FindElement(By.Id("r_781")).Click();
            //AM/FM Radio
            //_driver.FindElement(By.Id("r_819")).Click();
            //Premiun Sound
            //_driver.FindElement(By.Id("r_865")).Click();
            //Tow Hitch
            //_driver.FindElement(By.Id("r_778")).Click();

            //********************* Div Click Down ********
            //*************Use Code to as a div drop down
            //_driver.FindElement(By.Id("Interior Color")).Click();

            //**************Interior Features**********
            //IWebElement InteriorColorBlack = _driver.FindElement(By.XPath(".//*[@id='r_4294961961']"));
            //InteriorColorBlack.Click();
            //IWebElement InteriorColorBlue = _driver.FindElement(By.XPath(".//*[@id='r_4294961959']"));
            //InteriorColorBlue.Click();
            //IWebElement InteriorColorGrey = _driver.FindElement(By.XPath(".//*[@id='r_4294961965']"));
            //InteriorColorGrey.Click();
            //IWebElement InteriorColorTan = _driver.FindElement(By.XPath(".//*[@id='r_4294961963']"));
            //InteriorColorTan.Click();

            //********************* Div Click Down ********
            //*************Use Code to as a div drop down
            //_driver.FindElement(By.Id("MPG highway")).Click();

            //********************MPG Highway*************

            //IWebElement MPG15 = _driver.FindElement(By.XPath(".//*[@id='r_275']"));
            //MPG15.Click();
            //IWebElement MPG20 = _driver.FindElement(By.XPath(".//*[@id='r_276']"));
            //MPG20.Click();
            //IWebElement MPG25 = _driver.FindElement(By.XPath(".//*[@id='r_277']"));
            //MPG25.Click();
            //IWebElement MPG30 = _driver.FindElement(By.XPath(".//*[@id='r_278']"));
            //MPG30.Click();

            //********************* Div Click Down ********
            //*************Use Code to as a div drop down
            //_driver.FindElement(By.Id("Transmission")).Click();

            //********************Transmission*************
            //IWebElement auto = _driver.FindElement(By.XPath(".//*[@id='r_282']"));
            //auto.Click();
            //IWebElement manual = _driver.FindElement(By.XPath(".//*[@id='r_283']"));
            //manual.Click();

            //*************Mile radius and Area code check boxes************

            IWebElement drop = _driver.FindElement(By.Id("dLabel"));
            drop.Click();
            //************Selected Distance
            // Set to 250 miles
            _driver.FindElement(By.CssSelector("#distance > li:nth-child(5) > a")).Click();
            //*****************testing zip
            IWebElement Zip = _driver.FindElement(By.CssSelector("#zip"));
            Zip.SendKeys("76504");
            Zip.SendKeys(Keys.Enter);
            Zip.Click();

            _driver.FindElement(By.Id("zip")).Clear();
            _driver.FindElement(By.Id("zip")).SendKeys("76504");

            //****************Update button
            _driver.FindElement(By.Id("distanceSubmit")).Click();

            string value = _driver.FindElement(By.CssSelector("#resultsHeader > h1")).Text;

            Console.WriteLine(String.Format("{0}", value));

            //*************Selects first car in list ********WORKS*****
            //_driver.FindElement(By.XPath("//*[@id='resultsList']/div[1]/div[3]/div[1]")).Click();

            //Working on this segement
            ////Working Code to always select $32,998*

            //_driver.FindElement(By.Name("//tr[td//a[@value='Select']]/td/a[contains(text(),'$32,998*')]")).Click();

            //WebElement PriceLink = _driver.FindElement(By. ("$32,998*"));

            //var priceClick = new SelectElement(_driver.FindElement(By.XPath(".//*[@id='r_4294963167']")));
            //priceClick.SelectByText("$32,998");

            var priceClick = _driver.FindElement(By.XPath(".//*[@id='r_4294963167']"));
            // priceClick.Click("32998");

            //priceClick.Click("$32,998");

            //IWebElement ExteriorColor = _driver.FindElement(By.XPath(".//*[@id='r_4294963167']"));
            //ExteriorColor.Click();
            //IWebElement Price = _driver.FindElements(By.XPath("//a[contains(text(),'$32,988*')"));

            //_driver.FindElement(By.PartialLinkText("//a[contains(text(),'$32,988*')")).Click();

            //_driver.FindElement(By.PartialLinkText("//*[contains(text(), '$32,988*')]")).Click();

            //****************Checking to see correct cars found*****************
            Assert.AreEqual("1 cars found", value);

            Console.WriteLine("Executed Test");

            _driver.Dispose();
        }
Example #33
0
 public void TestCleanup()
 {
     _driver?.Dispose();
 }
 private static void CloseBrowserAndDispose(IWebDriver driver)
 {
     driver.Close();
     driver.Dispose();
 }