Пример #1
0
 private void ReloadAndRestorePage(string departureCity, string destinationCountry, string destinationCity)
 {
     _driver.Navigate().GoToUrl(Url);
     InitControls();
     Thread.Sleep(1000);
     DepartureCityElm.SelectByText(departureCity);
     Thread.Sleep(1000);
     DestinationCountryElm.SelectByText(destinationCountry);
     Thread.Sleep(1000);
     DestinationCityElm.SelectByText(destinationCity);
     Thread.Sleep(1000);
     SetDates();
 }
Пример #2
0
        private void FindFlights(string departureCity, string destinationCountry, string destinationCity)
        {
            //set destination City
            DestinationCityElm.SelectByText(destinationCity);
            if (!DatesSet)
            {
                SetDates();
            }

            try
            {
                Screenshot screen = ((ITakesScreenshot)_driver).GetScreenshot();
                screen.SaveAsFile($"PegasBeforeSearch{DateTime.Now.ToString("yyyy.MM.dd.HH.m")}.png", ScreenshotImageFormat.Png);

                SearchButtonElm.Click();
                Thread.Sleep(5000);
            }
            catch (ElementClickInterceptedException ex)
            {
                _logger?.LogError(ex, $"departureCity {departureCity} destination {destinationCity}");
                ReloadAndRestorePage(departureCity, destinationCountry, destinationCity);
            }
            Thread.Sleep(5000);

            var flightTables = _driver.FindElements(By.XPath(OneWayFlightsPath));

            if (flightTables.Any())
            {
                var departureCityCode   = IataCities.FirstOrDefault(icity => icity.Name == departureCity)?.Code;
                var destinationCityCode = IataCities.FirstOrDefault(icity => icity.Name == destinationCity)?.Code;
                if (departureCityCode == null)
                {
                    Debug.WriteLine(departureCityCode);
                }
                if (destinationCityCode == null)
                {
                    Debug.WriteLine(destinationCityCode);
                }
                FlightsList.AddRange(ParseFlights(departureCity, departureCityCode, destinationCountry, destinationCity, flightTables.First()));
            }
            else
            {
                _logger?.LogWarning($"[Pegas] Город вылета {departureCity}. " +
                                    $"Страна прилёта {destinationCountry}. Город прилёта {destinationCity}. " +
                                    $"Нет рейсов");
            }
        }