Esempio n. 1
0
        public Firefox SetupFirefoxWithOption()
        {
            FirefoxProfile ffProfile = new FirefoxProfile();

            ffProfile.SetPreference("acceptInsecureCerts", true);
            ffProfile.SetPreference("security.enterprise_roots.enabled", true);
            var firefpoxOptions = new FirefoxOptions {
                Profile = ffProfile
            };


            var firingDriver = new EventFiringWebDriver(new FirefoxDriver(firefpoxOptions));

            firingDriver.ExceptionThrown += firingDriver_TakeScreenshotOnException;

            firingDriver
            .Manage()
            .Timeouts()
            .ImplicitWait = (TimeSpan.FromSeconds(ImplicitTimeWaitInSeconds));
            firingDriver
            .Manage()
            .Timeouts()
            .PageLoad = (TimeSpan.FromSeconds(PageLoadTimeoutInSeconds));
            _driver = firingDriver;
            _driver.Manage().Window.Maximize();
            return(this);
        }
Esempio n. 2
0
        private static IWebDriver GetDriver()
        {
            //var capabilities = new DesiredCapabilities();
            //capabilities.SetCapability(CapabilityType.BrowserName, "UNKNOWN");
            //capabilities.SetCapability(CapabilityType.BrowserVersion, "");
            //var driver = new RemoteWebDriver(new Uri("http://selenoid-uri:4444/wd/hub"), capabilities);

            IWebDriver webDriver     = null;
            var        chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments("--start-maximized");
            chromeOptions.AddArguments("--test-type");
            chromeOptions.AddArguments("--no-sandbox");
            chromeOptions.AddUserProfilePreference("download.default_directory",
                                                   Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""));
            chromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads",
                                                   1);
            chromeOptions.AddAdditionalCapability("enableVNC", true, true);
            chromeOptions.AddAdditionalCapability("version", "90.0", true);
            chromeOptions.AddAdditionalCapability("platform", new Platform(PlatformType.Any), true);

            webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub/"), chromeOptions);
            webDriver.Manage().Window.Maximize();
            var eventFiringWebDriver = new EventFiringWebDriver(webDriver);

            return(eventFiringWebDriver);
        }
 public void Quit()
 {
     driver.Close();
     driver.Quit();
     driver.Dispose();
     driver = null;
 }
Esempio n. 4
0
        // This method will check if the orderId is present on the Buy side book or not. Returns false if the orderId is not present
        public bool VerifyOrderIdInOrderHistoryBook(string orderId, string numberOfRecords)
        {
            bool    flag = true;
            string  orderIdText;
            int     totalCount;
            int     count;
            Actions actions          = new Actions(driver);
            EventFiringWebDriver evw = new EventFiringWebDriver(driver);

            totalCount = Int32.Parse(numberOfRecords);
            count      = totalCount / 10;
            for (int j = 1; j <= count; j++)
            {
                for (int i = 1; i <= 10; i++)
                {
                    By orderIdFromUI = By.XPath("//div[@class='ReactVirtualized__Grid__innerScrollContainer']/div[" + i + "]/div[1]");
                    orderIdText = driver.FindElement(orderIdFromUI).Text;
                    if (!(orderIdText.Equals(orderId)))
                    {
                        flag = false;
                    }
                }
                var queryString = "document.querySelector('div.ReactVirtualized__Grid.ReactVirtualized__Table__Grid').scrollTop=";
                evw.ExecuteScript(queryString + (j * 440));
                Thread.Sleep(1000);
            }
            return(flag);
        }
Esempio n. 5
0
        public void Close()
        {
            if (Navigator.driver == null)
            {
                return;
            }

            this.UnsubscribeToEvents();

            try
            {
                Navigator.driver.Close();
            }
            catch (Exception ex)
            {
                // When running on build server, we might get timeouts => ignore.
                var error = string.Format("[ERROR] Navigator.Close(){0}{1}", Environment.NewLine, ex);
                Trace.TraceError(error);
            }
            finally
            {
                // Quit() calls Dispose() and sends a DriverCommand.Quit command for RemoteWebDrivers.
                Navigator.driver.Quit();
                Navigator.driver = null;
            }
        }
Esempio n. 6
0
        public void SBTestBaseBaseInitialize()
        {
            //base.BaseTestInitialize();

            var browserClosed = "Unable to connect to the remote server";

            try
            {
                if (TestWebDriver.WindowHandles.Count == 1)
                {
                    var localWebDriver = new ChromeDriver(@"C:\Program Files (x86)\AdeptSDK\", new ChromeOptions(), TimeSpan.FromMinutes(4));
                    TestWebDriver = localWebDriver;
                    //base.InitializeWebDriver();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains(browserClosed))
                {
                    base.InitializeWebDriver();
                }
            }

            firingDriver  = new EventFiringWebDriver(TestWebDriver);
            feedback      = new FeedbackDialog(TestWebDriver);
            TestWebDriver = firingDriver;


            firingDriver.ExceptionThrown += firingDriver_ExceptionThrown;
            firingDriver.Navigated       += firingDriver_Navigated;
            firingDriver.ElementClicking += firingDriver_ElementClicking;
        }
        public static IWebDriver Get()
        {
            if (driver != null)
            {
                return(driver);
            }
            driver = new ChromeDriver();

            var firingDriver = new EventFiringWebDriver(driver);

            firingDriver.ElementClicked += (sender, args) =>
            {
                logger.Debug(DateTime.Now, "element clicked");
            };

            firingDriver.ElementClicking += (sender, args) =>
            {
                logger.Debug(DateTime.Now, "element clicking");
            };

            firingDriver.FindElementCompleted += (sender, args) =>
            {
                logger.Debug(DateTime.Now, "element found");
            };

            firingDriver.ExceptionThrown += (sender, args) =>
            {
                Exception e = args.ThrownException;
                logger.Error(DateTime.Now, e?.Message, e?.StackTrace);
            };

            driver = firingDriver;

            return(driver);
        }
        protected override void StartInstance()
        {
            var driver = new OpenQA.Selenium.Chrome.ChromeDriver(@"..\..\..\chromedriver\");

            m_driver = new EventFiringWebDriver(driver);
            m_driver.Manage().Window.Maximize();
        }
Esempio n. 9
0
 private void InitFiringDriver()
 {
     firingDriver                  = new EventFiringWebDriver(driver);
     firingDriver.Navigating      += FiringDriverNavigating;
     firingDriver.Navigated       += FiringDriverNavigated;
     firingDriver.ExceptionThrown += FiringDriverExceptionThrown;
 }
Esempio n. 10
0
        public static BrowserWindow Launch(string uri)
        {
            EventFiringWebDriver driver = null;

            switch (CurrentBrowser)
            {
            case "Firefox":
                driver = new EventFiringWebDriver(new FirefoxDriver());
                break;

            case "IE":
                driver = new EventFiringWebDriver(new InternetExplorerDriver());
                break;

            default:
                driver = new EventFiringWebDriver(new ChromeDriver());
                break;
            }

            if (ActiveBrowserWindowInstances == null)
            {
                ActiveBrowserWindowInstances = new List <BrowserWindow>();
            }

            BrowserWindow browserWindow = new BrowserWindow(driver);

            browserWindow.NavigateToUrl(uri);

            ActiveBrowserWindowInstances.Add(browserWindow);

            return(browserWindow);
        }
Esempio n. 11
0
        static EventFiringWebDriver getEventFiringWD(IWebDriver _dr)
        {
            EventFiringWebDriver eventDr = new EventFiringWebDriver(_dr);

            EventsInitialiser._TriggerDriverEvents(eventDr);
            return(eventDr);
        }
        public void Can_Add_Comment()
        {
            DatabaseHelper.ExecuteCommand("DELETE FROM Messages");
            DatabaseHelper.ExecuteCommand("INSERT INTO Messages (Message) VALUES('foo'),('Bar')");
            using (var driver = new EventFiringWebDriver(new ChromeDriver()))
            {
                driver.Navigate().GoToUrl("http://localhost/TDDDemoApp/");

                var loadingWait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
                loadingWait.Until(x => !x.FindElement(By.Id("message-loading")).Displayed);

                const string inputMessage = "this is my message";
                var          inputElement = driver.FindElement(By.Id("message-text-input"));
                inputElement.SendKeys(inputMessage);

                var buttonElement = driver.FindElement(By.Id("add-message-button"));
                buttonElement.Click();

                var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
                wait.Until(x => string.IsNullOrEmpty(x.FindElement(By.Id("message-text-input")).Text));

                Thread.Sleep(1000);

                var messages = driver.FindElements(By.TagName("blockquote"));
                Assert.That(messages.Any(x => x.Text.Contains(inputMessage)));
            }
        }
Esempio n. 13
0
        public BrowserWindow(EventFiringWebDriver driver)
        {
            ParentSearchContext = driver;
            Driver = driver;

            Driver.ExceptionThrown += TakeScreenshotOnException;
        }
Esempio n. 14
0
 public IWebDriver EnableLoggingForDriver(IWebDriver driver)
 {
     _loggingDriver = new EventFiringWebDriver(driver);
     driver         = _loggingDriver;
     _loggingDriver.ExceptionThrown += LoggingDriver_ExceptionThrown;
     return(driver);
 }
Esempio n. 15
0
 // 경고창과 클릭 예외 처리가 된 클릭 이벤트
 public void Click(EventFiringWebDriver pDriver, By by)
 {
     while (true)
     {
         try
         {
             pDriver.FindElement(by).Click();
             break;
         }
         catch (UnhandledAlertException e)
         {
             Console.WriteLine($": '{e}'");
             try
             {
                 IAlert alert = pDriver.SwitchTo().Alert();
                 Console.WriteLine(alert.Text);
                 alert.Dismiss();
             }
             catch (Exception)
             {
                 //Console.WriteLine($": '{e}'");
             }
         }
         catch (ElementClickInterceptedException e)
         {
             Console.WriteLine($": '{e}'");
         }
         catch (Exception e)
         {
             Console.WriteLine($": '{e}'");
         }
         Thread.Sleep(1000);
     }
 }
        public void InitializeFront()
        {
            TestResultsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestResults", DateTime.Now.ToString("dd-MM-yyyy hh_mm_ss"));

            ExtentFileName = Path.Combine(TestResultsDirectory, TestContext.TestName + '_' + DateTime.Now.ToString("ddMMyyyy_hhmmss") + ".html");

            if (!Directory.Exists(TestResultsDirectory))
            {
                Directory.CreateDirectory(TestResultsDirectory);
            }

            if (!File.Exists(ExtentFileName))
            {
                File.Create(ExtentFileName);
            }

            HtmlReporter = new ExtentHtmlReporter(ExtentFileName);
            Extent       = new ExtentReports();
            Extent.AttachReporter(HtmlReporter);

            Test = Extent.CreateTest(TestContext.TestName + " " + Title, Description);

            GetDriverBrowser();
            Driver = new EventFiringWebDriver(_webDriver);
            Action = new Actions(Driver);
            SetEnviornment();
            Driver.Manage().Window.Position = new System.Drawing.Point(1000, 0);
            Driver.Navigate().GoToUrl(Url);
            Driver.Manage().Window.Maximize();

            Driver.ElementValueChanged += FiringDriver_ElementValueChanged;
            Driver.ElementClicked      += Driver_ElementClicked;
        }
Esempio n. 17
0
        public void Setup()
        {
            statuScenario = new LogStatus();

            if (contadorExtentResports == 0)
            {
                ExtentReport.CreateFileLog();
                contadorExtentResports += 1;
            }
            else
            {
                contadorExtentResports += 1;
            }

            ExecuteCMD("taskkill /im chromedriver.exe /f /t");
            ExecuteCMD("taskkill /im chrome.exe /f /t");
            webDriver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory);

            driver = new EventFiringWebDriver(webDriver);
            driver.ElementClicking      += DriverElementClicking;
            driver.ElementClicked       += DriverElementClicked;
            driver.ElementValueChanging += DriverElementValueChanging;
            driver.ElementValueChanged  += DriverElementValueChanged;

            action = new Actions(driver);

            driver.Navigate().GoToUrl(Url);

            driver.Manage().Window.Maximize();

            action = new Actions(driver);
        }
Esempio n. 18
0
        /// <summary>
        /// Main browser object
        /// </summary>
        /// <param name="driverName">Name of the driver</param>
        /// <param name="wait">Base wait in seconds</param>
        public Browser(string driverName, int wait)
        {
            var driver = CreateBrowser.Create(driverName);

            _edr     = CreateBrowser.CreateEventFiring(driver);
            _wait    = new WebDriverWait(_edr, TimeSpan.FromSeconds(wait));
            _actions = new Actions(_edr);
        }
Esempio n. 19
0
 public Application()
 {
     driver                = new EventFiringWebDriver(new FirefoxDriver());
     this.gmailMainPage    = new GmailMainPage(driver);
     this.gmailInboxPage   = new GmailInboxPage(driver);
     this.googleSignInPage = new GoogleSignInPage(driver);
     InitializeEvents();
 }
Esempio n. 20
0
        private static EventFiringWebDriver GetEventFiringWebDriver(IWebDriver driver)
        {
            var eventDriver = new EventFiringWebDriver(driver);

            eventDriver.ElementClicking      += EventDriver_ElementClicking;
            eventDriver.ElementValueChanging += EventDriver_ElementValueChanging;
            return(eventDriver);
        }
Esempio n. 21
0
        public Application()
        {
            driver = new EventFiringWebDriver(new ChromeDriver());
            this.MainSinopticControl = new MainSinopticControl(driver);
            this.DaysBlockControl    = new DaysBlockControl(driver);

            InitializeEvents();
        }
Esempio n. 22
0
        public void Start()
        {
            ChromeOptions co = new ChromeOptions();

            co.SetLoggingPreference(LogType.Browser, LogLevel.All);
            driver = new EventFiringWebDriver(new ChromeDriver(co));
            wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        }
Esempio n. 23
0
        public IWebDriver LaunchBrowser()
        {
            ChromeOptions options = new ChromeOptions();

            threadDriver = new ScreenShotRemoteWebDriver(new Uri("http://" + _host + ":" + _port + "/wd/hub"), options);
            eveDriver    = new MyEventFiringWebDriver(threadDriver);
            return(eveDriver);
        }
Esempio n. 24
0
 public ProductPage(EventFiringWebDriver driver, WebDriverWait wait)
 {
     _driver = driver;
     _wait   = wait;
     PageFactory.InitElements(_driver, this);
     _mainPage = new MainPage(_driver, _wait);
     ;
 }
Esempio n. 25
0
 public void Start()
 {
     driver = new EventFiringWebDriver(new ChromeDriver());
     driver.FindingElement       += (sender, e) => Console.WriteLine(e.FindMethod);
     driver.FindElementCompleted += (sender, e) => Console.WriteLine(e.FindMethod + " found");
     driver.ExceptionThrown      += (sender, e) => Console.WriteLine(e.ThrownException);
     driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
 }
Esempio n. 26
0
        /// <summary>
        /// Event handler method
        /// </summary>
        /// <param name="inputdriver"></param>
        /// <returns></returns>
        public static IWebDriver RegisterEvents(IWebDriver inputdriver)
        {
            EventFiringWebDriver driver = new EventFiringWebDriver(inputdriver);

            driver.ElementClicked  += new EventHandler <WebElementEventArgs>(driver_ElementClicked);
            driver.ExceptionThrown += new EventHandler <WebDriverExceptionEventArgs>(driver_ExceptionThrown);
            return(driver);
        }
Esempio n. 27
0
 public void start()
 {
     driver = new EventFiringWebDriver(new ChromeDriver());
     driver.FindingElement       += (sender, e) => Console.WriteLine(DateTime.Now.ToString("ddmmyy hh:mm:ss ") + e.FindMethod);
     driver.FindElementCompleted += (sender, e) => Console.WriteLine(DateTime.Now.ToString("ddmmyy hh:mm:ss ") + e.FindMethod + " found");
     driver.ExceptionThrown      += (sender, e) => Console.WriteLine(DateTime.Now.ToString("ddmmyy hh:mm:ss ") + e.ThrownException);
     wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
 }
Esempio n. 28
0
 public void start()
 {
     driver = new EventFiringWebDriver(new ChromeDriver("C:\\Users\\plotn\\Documents" +
                                                        "\\Visual Studio 2017\\Projects\\csharp-example\\csharp-example\\drv\\"));
     driver.FindingElement       += (sender, e) => Console.WriteLine(e.FindMethod);
     driver.FindElementCompleted += (sender, e) => Console.WriteLine(e.FindMethod + " found");
     driver.ExceptionThrown      += (sender, e) => Console.WriteLine(e.ThrownException);
     wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
 }
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService();
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.PhantomJs:
                driver = new PhantomJSDriver(options.DriversPath);

                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));

                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
        //public static bool EmailRecieved()
        //{
        //    var api = new WebApiServiceHelper();
        //    var requestString = string.Format("https://api.mailinator.com/api/inbox?to={0}&token={1}", ScenarioContext.Current["userName"], "7c5b21b2160b42269075e44ff3b7987f");
        //    return api.Get<MailinatorInbox>(requestString).messages.Count > 0;
        //}

        public static string TakeScreenshot()
        {
            var timestamp    = DateTime.Now.ToString("yyyy-MM-dd-hhmm-ss");
            var fileName     = "Exception-" + timestamp + ".png";
            var firingDriver = new EventFiringWebDriver(driver.WrappedDriver);

            firingDriver.TakeScreenshot().SaveAsFile(fileName, ImageFormat.Png);
            return(fileName);
        }
 /// <summary>
 ///     Initializes a new instance of the EventFiringNavigation class
 /// </summary>
 /// <param name="driver">Driver in use</param>
 public EventFiringNavigation(EventFiringWebDriver driver)
 {
     parentDriver = driver;
     wrappedNavigation = parentDriver.WrappedDriver.Navigate();
 }
 public EventedWebDriver(IWebDriver driver)
 {
     this.driver = new EventFiringWebDriver(driver);
     RegisterEvents();
 }
 /// <summary>
 /// Initializes a new instance of the EventFiringTargetLocator class
 /// 
 /// </summary>
 /// <param name="driver">The driver that is currently in use</param>
 public EventFiringTargetLocator(EventFiringWebDriver driver)
 {
   this.parentDriver = driver;
   this.wrappedLocator = this.parentDriver.WrappedDriver.SwitchTo();
 }
 /// <summary>
 /// Initializes a new instance of the EventFiringOptions class
 /// 
 /// </summary>
 /// <param name="driver">Instance of the driver currently in use</param>
 public EventFiringOptions(EventFiringWebDriver driver)
 {
   this.wrappedOptions = driver.WrappedDriver.Manage();
 }
 /// <summary>
 /// Initializes a new instance of the EventFiringNavigation class
 /// 
 /// </summary>
 /// <param name="driver">Driver in use</param>
 public EventFiringNavigation(EventFiringWebDriver driver)
 {
   this.parentDriver = driver;
   this.wrappedNavigation = this.parentDriver.WrappedDriver.Navigate();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:OpenQA.Selenium.Support.Events.EventFiringWebDriver.EventFiringWebElement"/> class.
 /// 
 /// </summary>
 /// <param name="driver">The <see cref="T:OpenQA.Selenium.Support.Events.EventFiringWebDriver"/> instance hosting this element.</param><param name="element">The <see cref="T:OpenQA.Selenium.IWebElement"/> to wrap for event firing.</param>
 public EventFiringWebElement(EventFiringWebDriver driver, IWebElement element)
 {
   this.underlyingElement = element;
   this.parentDriver = driver;
 }
 /// <summary>
 ///     Initializes a new instance of the
 ///     <see cref="T:OpenQA.Selenium.Support.Events.EventFiringWebDriver.EventFiringWebElement" /> class.
 /// </summary>
 /// <param name="driver">
 ///     The <see cref="T:OpenQA.Selenium.Support.Events.EventFiringWebDriver" /> instance hosting this
 ///     element.
 /// </param>
 /// <param name="element">The <see cref="T:OpenQA.Selenium.IWebElement" /> to wrap for event firing.</param>
 public EventFiringWebElement(EventFiringWebDriver driver, IWebElement element)
 {
     WrappedElement = element;
     ParentDriver = driver;
 }