我在一个
for
循环以迭代
list
所以我不必再写同样的测试了。
XS = [320, 568]
SM = [568, 320]
MD = [768, 1024]
LG = [1024, 768]
XL = [1200, 750]
WINDOW_SIZES = [XS, SM, MD, LG, XL]
# Loops through all of the sizes.
for window in WINDOW_SIZES:
# Set the window size [320,568], etc...
driver.set_window_size(window[0],window[1])
# Load the page you want to test.
driver.get('mypage')
# rest of test assertions
我还做了一个方法,使这一点更容易:
def get_page(self, url_extention, window=XS):
return (
driver.set_window_size(window[0], window[1]),
driver.get(self.live_server_url + url_extention)
)
在测试中我可以运行
self.get_page('mysite', window=window) # or MD if that is all I want to test
我通常从所有这些开始,然后(类似于bootstrap)随着窗口大小的变化而向上移动。所以为了
MD
向上:
# Tests small sizes.
def test_mypage(self):
self.get_page('mysite', window=window)
self.assert('Assertions for all sizes')
# Tests larger sizes.
def test_mypage_MD(self):
self.get_page('mysite', window=[MD,LG,XL])
self.assert('The things that are different from the previous test')