public WeatherDetails GetWeatherInfoFromAPI(string city)
        {
            WeatherDetails APIWeatherInfo = new WeatherDetails();

            string JsonResponse = autoLib.GetWeatherDataFromAPI(city.ToString());

            APIWeatherInfo = parseJsonResponse(JsonResponse);

            return(APIWeatherInfo);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            TestLibrary TestLib = new TestLibrary();

            AutomationLib.WeatherCheck autoLib = new AutomationLib.WeatherCheck();

            ConfigParmaeter configParameter = new ConfigParmaeter();

            configParameter = TestLib.GetConfigParameterFromExternalFile();
            int    varianceForTempratureInCelsius  = configParameter.TemperatureInCelsius;
            int    varianceForHumidityInPercentage = configParameter.HumidityInPercentage;
            int    variaceForWindSpeedInKMPH       = configParameter.WindSpeedInKMPH;
            string city = configParameter.City;

            autoLib.LaunchBrowserAndNavigateToURL(sNDTVUrl, WeatherCheck.eBrowser.CHROME);

            TestLib.NavigateToWeatherPageAndSearchForCity(city);

            if (TestLib.VerifySearchedCityDisplayedOnMap(city) == "true")
            {
                Console.WriteLine("PASS : Searched city is displayed on the map");
            }
            else
            {
                Console.WriteLine("FAIL : Searched city is not displayed on the map");
            }

            WeatherDetails weatherDetailsOnNDTV = new WeatherDetails();

            weatherDetailsOnNDTV = TestLib.GetWeatherInfoFromNDTV(city);

            WeatherDetails weatherDetailsFromAPI = new WeatherDetails();

            weatherDetailsFromAPI = TestLib.GetWeatherInfoFromAPI(city);

            TestLib.VerifySearchedCityDisplayedOnMap(city);

            if (TestLib.VerifyWeatherInfoBetweenNDTVAndAPI(weatherDetailsFromAPI, weatherDetailsOnNDTV, varianceForTempratureInCelsius,
                                                           varianceForHumidityInPercentage, variaceForWindSpeedInKMPH))
            {
                Console.WriteLine("PASS : The weather info between NDTV and API matches");
            }
            else
            {
                Console.WriteLine("FAIL : The weather info between NDTV and API does not match");
            }

            Console.ReadLine();

            autoLib.CloseBrowser();
        }
        private WeatherDetails parseJsonResponse(string originalJson)
        {
            WeatherDetails weatherDetailsFromJson = new WeatherDetails();
            JObject        jsonObj = JObject.Parse(originalJson);

            weatherDetailsFromJson.Condition = (string)jsonObj.SelectToken("weather[0].description");
            string windspeed = (string)jsonObj.SelectToken("wind.speed");

            weatherDetailsFromJson.WindSpeed     = double.Parse(windspeed);
            weatherDetailsFromJson.WindSpeedGust = 0;
            weatherDetailsFromJson.Humidity      = (int)jsonObj.SelectToken("main.humidity");
            weatherDetailsFromJson.Temperature   = (int)jsonObj.SelectToken("main.temp");
            weatherDetailsFromJson.Temperature   = weatherDetailsFromJson.Temperature - 273; //convert temperature in kelvin to celsius

            return(weatherDetailsFromJson);
        }
        public WeatherDetails GetWeatherInfoFromNDTV(string city)
        {
            WeatherDetails NDTVWeatherInfo = new WeatherDetails();

            autoLib.Click(WeatherCheck.eByType.XPATH, getLocatorForCityOnMap(city));

            //condition
            NDTVWeatherInfo.Condition = getWeatherCondition(autoLib.GetAttributeVal(WeatherCheck.eByType.CSS, ePageElements.WEATHER_DETAILS_CONDITION.GetDescription(), WeatherCheck.eAttributeValue.Text));

            //WindSpeed
            string windInfo = autoLib.GetAttributeVal(WeatherCheck.eByType.CSS, ePageElements.WEATHER_DETAILS_WIND.GetDescription(), WeatherCheck.eAttributeValue.Text);

            NDTVWeatherInfo.WindSpeed     = getWeatherWindMin(windInfo);
            NDTVWeatherInfo.WindSpeedGust = getWeatherWindMax(windInfo);

            //humidity
            NDTVWeatherInfo.Humidity = getWeatherHumidity(autoLib.GetAttributeVal(WeatherCheck.eByType.CSS, ePageElements.WEATHER_DETAILS_HUMIDITY.GetDescription(), WeatherCheck.eAttributeValue.Text));

            //temperature
            NDTVWeatherInfo.Temperature = getWeatherTemperature(autoLib.GetAttributeVal(WeatherCheck.eByType.CSS, ePageElements.WEATHER_DETAILS_TEMPERATURE.GetDescription(), WeatherCheck.eAttributeValue.Text));

            return(NDTVWeatherInfo);
        }
        public bool VerifyWeatherInfoBetweenNDTVAndAPI(WeatherDetails InfoFromAPI, WeatherDetails InfoFromNDTV,
                                                       int varianceForTemp = 0, int varianceForHumidity = 0, int varianceForWindSpeed = 0)
        {
            bool finalResult       = false;
            bool windSpeedResult   = false;
            bool humidityResult    = false;
            bool temperatureResult = false;

            //compare weather condition
            if (InfoFromAPI.Condition == InfoFromNDTV.Condition)
            {
                Console.WriteLine("PASS : Weather condition is a match");
            }
            else
            {
                Console.WriteLine("Warning : Weather condition is not a match");
                Console.WriteLine("Condition from API : " + InfoFromAPI.Condition);
                Console.WriteLine("Condition from NDTV : " + InfoFromNDTV.Condition);
            }

            //compare windSpeed
            if (Math.Abs(InfoFromAPI.WindSpeed - InfoFromNDTV.WindSpeed) <= varianceForWindSpeed)
            {
                Console.WriteLine("PASS : Weather windSpeed is a match");
                windSpeedResult = true;
            }
            else
            {
                Console.WriteLine("Fail : Weather windSpeed is not a match");
                Console.WriteLine("windSpeed from API : " + InfoFromAPI.WindSpeed);
                Console.WriteLine("windSpeed from NDTV : " + InfoFromNDTV.WindSpeed);
            }

            //compare humidity
            if ((Math.Abs(InfoFromAPI.Humidity - InfoFromNDTV.Humidity) / InfoFromAPI.Humidity) * 100 <= varianceForHumidity)
            {
                Console.WriteLine("PASS : Weather Humidity is a match");
                humidityResult = true;
            }
            else
            {
                Console.WriteLine("Fail : Weather Humidity is not a match");
                Console.WriteLine("Humidity from API : " + InfoFromAPI.Humidity);
                Console.WriteLine("Humidity from NDTV : " + InfoFromNDTV.Humidity);
            }

            //compare temperature
            if (Math.Abs(InfoFromAPI.Temperature - InfoFromNDTV.Temperature) <= varianceForTemp)
            {
                Console.WriteLine("PASS : Weather Temperature is a match");
                temperatureResult = true;
            }
            else
            {
                Console.WriteLine("Fail : Weather Temperature is not a match");
                Console.WriteLine("Temperature from API : " + InfoFromAPI.Temperature);
                Console.WriteLine("Temperature from NDTV : " + InfoFromNDTV.Temperature);
            }

            finalResult = windSpeedResult && humidityResult && temperatureResult;

            return(finalResult);
        }