Beispiel #1
0
        public void IsCreated_BeforeBrowserIsCreated_ReturnsFalse()
        {
            // Arrange
            SeleniumBrowserFactory browserFactory = new SeleniumBrowserFactory();

            // Act
            IBrowser browser = browserFactory.GetBrowser();

            // Assert
            Assert.IsFalse(browser.IsCreated);
        }
Beispiel #2
0
        public void IsCreated_AfterBrowserIsCreated_ReturnsTrue()
        {
            // Arrange
            SeleniumBrowserFactory browserFactory = new SeleniumBrowserFactory();

            // Act
            IBrowser browser = browserFactory.GetBrowser();

            // trying to get the Url will launch the browser
            string url = browser.Url;

            // Assert
            Assert.IsTrue(browser.IsCreated);
        }
Beispiel #3
0
        public Browser(Settings configuration)
        {
            this.configuration = configuration;

            var driverFactory = new SeleniumBrowserFactory(configuration);

            var browserName = configuration.WebDriver.BrowserDriver.ToEnum <BrowserNames>();

            browserDriver = driverFactory.Create(browserName);

            var cfgMaxWait = TimeSpan.FromMilliseconds(configuration.MaxWait == 0 ? 60000 : configuration.MaxWait);

            // set initial browser driver timeout to configuration or 1 minute if not defined
            lock (timeoutHistory)
            {
                timeoutHistory.Push(cfgMaxWait);
                browserDriver.ChangeBrowserDriverTimeout(cfgMaxWait);
            }
        }
Beispiel #4
0
 public static IHostBuilder ConfigureFlightPriceDetection(this IHostBuilder hostBuilder, bool headless = true)
 {
     return(hostBuilder
            .ConfigureServices(services =>
     {
         services
         .AddSingleton <IBrowserActionsRetry, ThreeTimesBrowserActionsRetry>()
         .AddSingleton <IBrowserFactory>(service =>
         {
             return new DelayedBrowserFactory(
                 SeleniumBrowserFactory.GetFirefoxBrowserFactory(service.GetService <ILogger>(), headless),
                 service.GetService <ILogger>());
         })
         .AddSingleton <IFlightPriceDetections>(service =>
         {
             return new FlightPriceDetections(
                 service.GetService <ILogger>(),
                 ("skyscanner", new SkyscannerFlightPriceDetection(
                      service.GetService <IBrowserFactory>(),
                      service.GetService <IBrowserActionsRetry>())));
         });
     }));
 }