forked from BugorDmitriy/OpenWeatherJavaProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTest.java
More file actions
464 lines (358 loc) · 16.4 KB
/
Copy pathMainTest.java
File metadata and controls
464 lines (358 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
package tests;
import base.BaseTest;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
import pages.CurrentWeatherPage;
import pages.MainPage;
import pages.TestData;
import utils.TestUtils;
import java.util.List;
public class MainTest extends BaseTest {
@Test
public void testH2Header_WhenSearchingCityCountry() {
final String cityName = "Paris";
final String expectedCityCountryNames = "Paris, FR";
MainPage mainPage = openBaseURL();
final String oldCityCountryName = mainPage.getCityCountryName();
mainPage.clickSearchCityField();
mainPage.inputSearchCriteria(cityName);
mainPage.clickSearchButton();
mainPage.clickParisInDropDownList();
mainPage.waitForCityCountryNameChanged(oldCityCountryName);
String newCityCountryNames = mainPage.getCityCountryName();
Assert.assertEquals(newCityCountryNames, expectedCityCountryNames);
}
@Test
public void testH2Header_WhenSearchingCityCountryChain() {
final String cityName = "Paris";
final String expectedCityCountryNames = "Paris, FR";
MainPage mainPage = openBaseURL();
final String oldCityCountryName = mainPage.getCityCountryName();
String newCityCountryNames =
mainPage
.clickSearchCityField()
.inputSearchCriteria(cityName)
.clickSearchButton()
.clickParisInDropDownList()
.waitForCityCountryNameChanged(oldCityCountryName)
.getCityCountryName();
Assert.assertEquals(newCityCountryNames, expectedCityCountryNames);
}
@Test
public void testH1HeaderColorAndFontSize() {
final String expectedH1Color = "rgba(0, 0, 0, 0)";
final String expectedH1FontSize = "45px";
MainPage mainPage = openBaseURL();
String actualH1Color = mainPage.getH1Color();
String actualH1FontSize = mainPage.getH1FontSize();
Assert.assertEquals(actualH1Color, expectedH1Color);
Assert.assertEquals(actualH1FontSize, expectedH1FontSize);
}
@Test
public void testAmountOfIcons_OnDifferentWeatherPopUp() {
final int expectedAmountOfIcons = 9;
int actualIconsAmount =
openBaseURL()
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.getAmountOfIconsOnDifferentWeatherPopUp();
Assert.assertEquals(actualIconsAmount, expectedAmountOfIcons);
}
@Test
public void testIconsHighlighted_OnDifferentWeatherPopUp() {
final String expectedValueOfAttribute = "activeIcon";
MainPage mainPage = openBaseURL();
List<WebElement> iconsDifferentWeather =
mainPage
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.getListOfIconsOnDifferentWeatherPopUp();
for (WebElement icon : iconsDifferentWeather) {
String actualValueAttribute =
mainPage
.clickIconOnDifferentWeatherPopUp(icon)
.getClassAttribute(icon);
Assert.assertEquals(actualValueAttribute, expectedValueOfAttribute);
}
}
@Test
public void testRefreshPage() {
final String expectedTextWhenLoading = "Loading";
String actualTextWhenLoading =
openBaseURL()
.clickLogo()
.getLoadingText("aria-label");
Assert.assertEquals(actualTextWhenLoading, expectedTextWhenLoading);
}
@Test
public void testCurrentLocationButton() {
final String cityName = "Norway";
final String expectedCityCountryName = "London, GB";
String actualCityCountryName =
openBaseURL()
.clickSearchCityField()
.inputSearchCriteria(cityName)
.clickSearchButton()
.clickCityNorway()
.clickLocationButton()
.getCityCountryName();
Assert.assertEquals(actualCityCountryName, expectedCityCountryName);
}
@Test
public void testXButtonIsDisplayed_OnDifferentWeatherPopUp() {
MainPage mainPage =
openBaseURL()
.clickDifferentWeatherButton();
Assert.assertTrue(mainPage.isXButtonDisplayed(), "X button is not displayed");
}
@Test
public void testTempUnitChangedToC_WhenSwitchingToMetric() {
final String expectedTempUnit = "°C";
String actualTempUnit = openBaseURL()
.switchToMetric()
.waitForGreyContainerDisappeared()
.getTempUnit();
Assert.assertEquals(actualTempUnit, expectedTempUnit);
}
@Test
public void testTempUnitChangedToF_WhenSwitchingToImperial() {
final String expectedTempUnit = "°F";
String actualTempUnit = openBaseURL()
.switchToImperial()
.waitForGreyContainerDisappeared()
.getTempUnit();
Assert.assertEquals(actualTempUnit, expectedTempUnit);
}
@Test
public void testSendButtonIsDisplayed_OnDifferentWeatherPopUp() {
MainPage mainPage =
openBaseURL()
.clickDifferentWeatherButton();
Assert.assertTrue(mainPage.isSendButtonDisplayed(), "Send button is not displayed");
}
@Test
public void testErrorMessageWhenCityDoesNotExists() {
final String cityName = TestUtils.getRandomName();
final String expectedErrorText = "No results for " + cityName;
String actualErrorText =
openBaseURL()
.clickSearchCityField()
.inputSearchCriteria(cityName)
.clickSearchButton()
.getErrorText();
Assert.assertEquals(actualErrorText, expectedErrorText);
}
@Test
public void testSearchErrorMessageBackgroundColor() {
final String cityName = TestUtils.getRandomName();
final String expectedSearchErrorMessageColor = "rgba(120, 203, 191, 0.8)";
String actualSearchErrorMessageColor =
openBaseURL()
.clickSearchCityField()
.inputSearchCriteria(cityName)
.clickSearchButton()
.getErrorButtonBackgroundColor();
Assert.assertEquals(actualSearchErrorMessageColor, expectedSearchErrorMessageColor);
}
@Test
public void testOneIconHighlightedByDefault_OnDifferentWeatherPopUp() {
final String expectedIconColor = "#ececed";
MainPage mainPage = openBaseURL();
int activeIcon =
mainPage
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.countActiveIconsInDifferentWeatherContainer();
final String activeIconColor = mainPage.getActiveIconBackgroundColorInHEX();
Assert.assertEquals(activeIcon, 1);
Assert.assertEquals(activeIconColor, expectedIconColor);
}
@Test
public void testDayListTempInC_WhenSwitchingToMetric() {
final List<String> expectedResult = List.of("°C", "°C", "°C", "°C", "°C", "°C", "°C", "°C");
MainPage mainPage =
openBaseURL()
.switchToMetric()
.waitForGreyContainerDisappeared();
Assert.assertEquals(mainPage.getTempsAndUnitsList(), expectedResult);
}
@Test
public void testDayListTempInF_WhenSwitchingToImperial() {
final List<String> expectedResult = List.of("°F", "°F", "°F", "°F", "°F", "°F", "°F", "°F");
MainPage mainPage =
openBaseURL()
.switchToImperial()
.waitForGreyContainerDisappeared();
Assert.assertEquals(mainPage.getTempsAndUnitsList(), expectedResult);
}
@Test
public void testDifferentWeatherButtonOpensDifferentWeatherContainer() {
final String expectedHeader = "Different weather";
String actualHeader =
openBaseURL()
.clickDifferentWeatherButton()
.getHeaderForDifferentWeatherContainer();
Assert.assertEquals(actualHeader, expectedHeader);
}
@Test
public void testTextInCookiesAgreement() {
final String expectedTextPanel =
"We use cookies which are essential for the site to work. We also use non-essential "
+ "cookies to help us improve our services. Any data collected is anonymised. "
+ "You can allow all cookies or manage them individually.";
String actualTextPanel =
openBaseURL()
.waitForFooterPanelToBeVisible()
.waitForElementToBeVisible()
.getBottomPanelText();
Assert.assertEquals(actualTextPanel, expectedTextPanel);
}
@Test
public void testTemperatureValueIncreasedByOne_WhenClickingUp() {
MainPage mainPage = openBaseURL();
int temperatureValueInContainer = mainPage
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.clickMoreOptionsDropDown()
.getTemperatureValueInDifferentWeatherContainer();
mainPage.clickUpKeyInTemperatureInput();
int increasedTemperatureValueInContainer = mainPage.getTemperatureValueInDifferentWeatherContainer();
Assert.assertEquals(increasedTemperatureValueInContainer - temperatureValueInContainer, 1);
}
@Test
public void testLocationButtonIsDisplayedAndClickable() {
final String expectedNotificationMessage = "Location unavailable. Displaying default location: London";
MainPage mainPage = openBaseURL();
Assert.assertTrue(mainPage.isLocationButtonDisplayed());
String actualNotificationMessage =
mainPage
.clickLocationButton()
.getNotificationMessage();
Assert.assertEquals(actualNotificationMessage, expectedNotificationMessage);
}
@Test
public void testAPIIconsAreDisplayed() {
final int expectedAPIIconsQuantity = 5;
final List<String> expectedAPIIconsNames = List.of(
"current\nweather\n(current)",
"hourly\nforecast\n(4 days)",
"daily\nforecast\n(16 days)",
"climatic\nforecast\n(30 days)",
"historical\nweather\n(1 month, 1 year)"
);
MainPage mainPage =
openBaseURL()
.scrollByCurrentWeatherIcon();
Assert.assertEquals(mainPage.getDisplayedAPIIcons(), mainPage.getApiIcons());
Assert.assertEquals(mainPage.getAPIIconsQuantity(), expectedAPIIconsQuantity);
Assert.assertEquals(mainPage.getAPIIconsNames(), expectedAPIIconsNames);
}
@Test
public void testMainPageHeaders() {
final String expectedH1Header = "OpenWeather";
final String expectedH2Header = "Weather forecasts, nowcasts and history in a fast and elegant way";
MainPage mainPage = openBaseURL();
Assert.assertEquals(mainPage.getH1Header(), expectedH1Header);
Assert.assertEquals(mainPage.getH2Header(), expectedH2Header);
}
@Test
public void testDataSourceOptions() {
final List<String> expectedDataSourceOptionsTexts = List.of(
"Personal feelings",
"Own weather station or devices",
"Local weather provider",
"Global weather provider",
"Other"
);
List<String> actualDataSourceOptionsTexts =
openBaseURL()
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.clickMoreOptionsDropDown()
.clickDataSourceDropDown()
.getDataSourceOptionsTexts();
Assert.assertEquals(actualDataSourceOptionsTexts, expectedDataSourceOptionsTexts);
}
@Test
public void testChosenDataSourceOptionIsSavedAfterClickingLessOptions() {
MainPage mainPage = openBaseURL();
String dataSourceDropDownTextBefore =
mainPage
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.clickMoreOptionsDropDown()
.clickDataSourceDropDown()
.clickFirstDataSourceOption()
.getDataSourceDropDownText();
String dataSourceDropDownTextAfter =
mainPage
.clickLessOptionsDropDown()
.clickMoreOptionsDropDown()
.getDataSourceDropDownText();
Assert.assertEquals(dataSourceDropDownTextAfter, dataSourceDropDownTextBefore);
}
@Test
public void testEmailAndAdditionalInfoIsNotSavedAfterClickingOutOfContainer() {
MainPage mainPage = openBaseURL();
String emailTextBefore =
mainPage
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.clickMoreOptionsDropDown()
.inputTextInEmailTextBox()
.getEmailTextBoxText();
String additionalInfoTextBefore =
mainPage
.inputTextInAdditionalInfoTextArea()
.getAdditionalInfoText();
String emailTextAfter =
mainPage
.clickOutOfDifferentWeatherContainer()
.clickDifferentWeatherButton()
.waitUntilDifferentWeatherPopUpIsVisible()
.clickMoreOptionsDropDown()
.getEmailTextBoxText();
String additionalInfoTextAfter =
mainPage
.getAdditionalInfoText();
Assert.assertNotEquals(emailTextAfter, emailTextBefore);
Assert.assertNotEquals(additionalInfoTextAfter, additionalInfoTextBefore);
}
@Test
public void testCorrect8DaysForecastCalendarSequence() {
List<String> listOfEightDaysData = openBaseURL().getListOfEightDaysDataText();
String expectedResult = new MainPage(getDriver()).getEightDaysForecastCalendarSequenceText();
String actualResult = listOfEightDaysData.toString().substring(1, listOfEightDaysData.toString().length() - 1);
Assert.assertEquals(actualResult, expectedResult);
}
@Test
public void testCurrentWeatherAPIIconNavigatesToCorrespondingPage() {
final String basePageTitle = "Сurrent weather and forecast - OpenWeatherMap";
final String expectedUrl = "https://openweathermap.org/current";
final String expectedTitle = "Current weather data - OpenWeatherMap";
CurrentWeatherPage currentWeatherPage =
openBaseURL()
.scrollByOrangeBackground()
.clickCurrentWeatherIcon();
Assert.assertNotEquals(currentWeatherPage.getTitle(), basePageTitle);
Assert.assertEquals(currentWeatherPage.getCurrentURL(), expectedUrl);
Assert.assertEquals(currentWeatherPage.getTitle(), expectedTitle);
}
@Test(dataProvider = "ApiIconsMainPage", dataProviderClass = TestData.class)
public void testAPIIconsNavigateToCorrespondingPages(
int index, String iconName, String iconDescription, String href, String expectedURL, String expectedTitle) {
MainPage mainPage = openBaseURL();
final String oldURL = mainPage.getCurrentURL();
final String oldTitle = mainPage.getTitle();
mainPage
.scrollByOrangeBackground()
.clickApiIcon(index);
String actualURL = getDriver().getCurrentUrl();
String actualTitle = getDriver().getTitle();
Assert.assertNotEquals(oldURL, actualURL);
Assert.assertNotEquals(oldTitle, actualTitle);
Assert.assertEquals(actualURL, expectedURL);
Assert.assertEquals(actualTitle, expectedTitle);
}
}