TA的每日心情 | 郁闷 2017-3-1 13:43 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
1:断言:
def test_1(self):
driver = self.driver
driver.get(self.base_url + "/login")
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("1")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("1")
driver.find_element_by_id("login-btn01").click()
for i in range(60):
try:
if u"验证失败!请检查您的登录信息, 并重试一次." == driver.find_element_by_id("loginErrorInfo").text: break
except: pass
time.sleep(1)
else: self.fail("time out")
2: 对比图片:
from PIL import Image
def make_regalur_image(img, size = (256, 256)):
return img.resize(size).convert('RGB')
def split_image(img, part_size = (64, 64)):
w, h = img.size
pw, ph = part_size
assert w % pw == h % ph == 0
return [img.crop((i, j, i+pw, j+ph)).copy() \
for i in xrange(0, w, pw) \
for j in xrange(0, h, ph)]
def hist_similar(lh, rh):
assert len(lh) == len(rh)
return sum(1 - (0 if l == r else float(abs(l - r))/max(l, r)) for l, r in zip(lh, rh))/len(lh)
def calc_similar(li, ri):
# return hist_similar(li.histogram(), ri.histogram())
return sum(hist_similar(l.histogram(), r.histogram()) for l, r in zip(split_image(li), split_image(ri))) / 16.0
def calc_similar_by_path(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
return calc_similar(li, ri)
def make_doc_data(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
li.save(lf + '_regalur.png')
ri.save(rf + '_regalur.png')
fd = open('stat.csv', 'w')
fd.write('\n'.join(l + ',' + r for l, r in zip(map(str, li.histogram()), map(str, ri.histogram()))))
# print >>fd, '\n'
# fd.write(','.join(map(str, ri.histogram())))
fd.close()
import ImageDraw
li = li.convert('RGB')
draw = ImageDraw.Draw(li)
for i in xrange(0, 256, 64):
draw.line((0, i, 256, i), fill = '#ff0000')
draw.line((i, 0, i, 256), fill = '#ff0000')
li.save(lf + '_lines.png')
if __name__ == '__main__':
for i in xrange(1, 6):
print i
img1 = 'C:\\work\\dart\\src\\test\\e2e\\spec\\test\\result\\login\\'+str(i)+'.png'
print img1
img2 = 'C:\\work\\dart\\src\\test\\e2e\\spec\\test\\old\\login\\'+str(i)+'.png'
print img2
print 'test_case_%d: %.3f%%'%(i,calc_similar_by_path(img1, img2)*100)
# make_doc_data('test/TEST4/1.JPG', 'test/TEST4/2.JPG')
|
评分
-
查看全部评分
|