我是一个设置python selenium框架的新手,我想知道我是否应该更整洁地收集和验证CSS属性?
我目前在基页中设置了验证css函数,这些方法在下面的代码中定义了各个css属性(参见image_thumb& image_height):
class BrokenImagePage(BasePage):
_broken_image = {"by": By.XPATH, "value": "//img[1]"}
_placeholder_image = {"by": By.XPATH, "value": "//img[3]"}
_title = {"by" : By.XPATH, "value": "//div[@class='example']/h3"}
def __init__(self, driver):
self.driver = driver
self._visit("/broken_images")
assert self._is_displayed(self._title)
def image_present (self):
return self._is_displayed(self._broken_image)
def image_thumb (self):
return self._wait_for_is_displayed(self._placeholder_image, 5)
def image_height (self):
return self._verify_css_value(self._placeholder_image, 'height')
def image_width (self):
return self._verify_css_value(self._placeholder_image, 'width')
然后我断言我的测试中的属性如此:
def test_image_css(self, images):
assert images.image_height() == '90px'
assert images.image_width() == '120px'
这对我来说似乎并不高效。我可以在一个方法中收集所有属性并以更好的方式对其进行断言吗?