Skip to content

Commit ecddae1

Browse files
Merge pull request #544 from Brain-up/issue_402
Issue_402_GROUPS_PAGE_tests
2 parents 56f66fd + fc1711b commit ecddae1

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pages/groups_page.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import time
33
import allure
44
import requests
5+
from selenium.webdriver.support.wait import WebDriverWait as Wait
6+
57
from pages.base_page import BasePage
68
from locators.groups_page_locators import GroupsPageLocators, HeaderLocators
79
from test_data.links import MainPageLinks as Links
@@ -223,15 +225,15 @@ def get_images_sizes(self):
223225

224226
@allure.step("Check changes of images sizes after resizing")
225227
def check_size_changes_of_images(self):
226-
time.sleep(2)
227228
images = self.get_list_of_images()
228-
images_sizes_before = [image.size for image in images]
229+
before = [img.size for img in images]
229230
self.driver.set_window_size(400, 700)
230-
time.sleep(2)
231-
images_sizes_after = [image.size for image in images]
232-
changed, lost, unchanged = [], [], []
233-
for i in range(len(images)):
234-
changed.append(i) if images_sizes_before[i] != images_sizes_after[i] else unchanged.append(i)
235-
lost.append(i) if images_sizes_after[i] == {'height': 0, 'width': 0} else None
236-
# print('All images have changed sizes' if len(changed) == len(images) else 'Not all images have changed sizes')
237-
return changed
231+
232+
Wait(self.driver, 5).until(lambda d: any(before[i] != img.size for i, img in enumerate(images)))
233+
234+
after = [img.size for img in images]
235+
return {
236+
'changed': [i for i, (b, a) in enumerate(zip(before, after)) if b != a and a != {'height': 0, 'width': 0}],
237+
'unchanged': [i for i, (b, a) in enumerate(zip(before, after)) if b == a],
238+
'lost': [i for i, a in enumerate(after) if a == {'height': 0, 'width': 0}]
239+
}

tests/groups_page_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ def test_gp_04_03_verify_images_alt_en(self, driver, groups_en_page_open):
191191
"The 'alt' attribute value of some images is empty or mismatches valid values on the 'en' local"
192192

193193
@allure.title("Verify sizes of images in links on the page")
194-
def test_gp_04_04_verify_images_sizes(self, driver, groups_ru_page_open):
194+
def test_gp_04_04_verify_images_sizes(self, driver, groups_en_page_open):
195195
page = gPage(driver)
196196
images_size = page.get_images_sizes()
197-
images_size_changed = page.check_size_changes_of_images()
197+
result = page.check_size_changes_of_images()
198198
assert images_size != 0, "Images in links have not sizes"
199-
assert len(images_size_changed) == len(gPD.images_src), "Not all images in links have changed sizes"
199+
assert len(result['changed']) > 0, "Images have not been resized"
200+
assert not result['lost'], f"Lost images: {result['lost']}"

0 commit comments

Comments
 (0)