import unittest,ddt
from day6.util.business_util import *
from day6.unittest import *
from selenium.webdriver.support.select import Select
@ddt.ddt
class TestReg(unittest.TestCase):
# 设置预置条件
def setUp(self):
url = 'http://127.0.0.1/index.php?m=member&c=public&a=register'
self.dr = pretest(url)
def tearDown(self):
# 判断如果测试用例运行出错时,做截图处理,截图文件的名称为测试方法名+时间戳.png
for test_method_name, error in self._outcome.errors:
if error:
time_str = time.strftime('%Y%m%d_%H%M%S')
file_name = '../screenshot/' + self._testMethodName + '_' + time_str + '.png'
self.dr.get_screenshot_as_file(file_name)
self.dr.quit()
# 测试注册成功
def test_reg_success(self):
usr, pwd, mobile, email = creat_user_data()
reg(self.dr,usr,pwd,pwd,email,mobile)
self.reg_success_assert('会员中心',usr+'1')
# 测试注册失败
@ddt.data(['a',123456,123456,'13323232121@qq.com',13323232121],['abc123q',1,123456,'13323232121@qq.com',13323232121],['abc123q',123456,1,'13323232121@qq.com',13323232121],['abc123q',123456,123456,'13',13323232121],['abc123q',123456,123456,'13323232121@qq.com',13])
@ddt.unpack
def test_reg_failed(self,usr,pwd,pwd2,email,mobile):
reg(self.dr, usr, pwd, pwd2, email, mobile)
self.reg_failed_assert('会员注册','新会员','.cart-address')
# 测试登录的超链接
@unittest.skipIf(test_state == 'smoke_test','暂时不测试!')
def test_login_link(self):
# 点击 登录 超链接
click_a_hyper_link(self.dr,'登录')
# 断言 进入 登录 页面
assert_in_a_page(self.dr,'登录')
# 测试网站服务协议超链接
@unittest.skipIf(test_state == 'smoke_test', '暂时不测试!')
def test_service_commit_link(self):
# 点击 网站服务协议 超链接
click_a_hyper_link(self.dr,'服务协议')
# 断言 服务 弹框的三部分内容
# 第一部分,标题对
assert_content_with_specific_text(self.dr,'用户协议', '[i="title"]')
# 第三部分,关闭 内容
assert_content_with_specific_text(self.dr,'关闭', '[i-id="cancel"]')
# 第二部分,内容不能为空
assert_content_not_none(self.dr,'#xy>textarea')
# 帮助方法:
# 断言注册成功
def reg_success_assert(self, text,usr):
# 断言
assert_in_a_page(self.dr,text)
assert_content_with_specific_text(self.dr,usr, '.fr>li:nth-child(1)>a')
# 断言注册失败
def reg_failed_assert(self,text1,text2,locate_value):
# 断言
assert_in_a_page(self.dr,text1)
assert_content_with_specific_text(self.dr,text2,locate_value)
if __name__ == '__main__':
unittest.main()
TestReg
最新推荐文章于 2024-11-02 16:28:26 发布