Ejemplo n.º 1
0
class LoginTest(unittest.TestCase):
    u'''登录测试'''
    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Firefox()
        cls.username = "******"
        cls.password = "******"
        cls.expect_user_id = "185****5162"
        cls.key = "verify_code"
        cls.sql = "SELECT * FROM verify_code WHERE phone = '%s' ORDER BY create_date DESC" % cls.username

    def test_01(self):
        u'''手机号快捷登录测试'''
        self.login_page = LoginPage(self.driver)
        self.login_page.open_login_page()
        self.login_page.input_phone(self.username)
        self.login_page.get_verify_code()
        sleep(1)
        db = DatabaseOperation()
        verfy_code = db.get_data(self.key, self.sql)
        self.login_page.input_verify_code('%s' % verfy_code)
        self.login_page.click_btn_login()
        # 等待时间后续优化
        sleep(3)
        user_id = self.login_page.show_user_id()
        # 判断登录是否成功
        self.assertEqual(user_id, self.expect_user_id, msg='登录失败')
        self.login_page.click_btn_logout()
        sleep(3)
        # 登出后,"退出登录"变为"立即登录"
        text_change = self.login_page.show_text_change()
        # 判断登出是否成功
        self.assertEqual(text_change, "立即登录", msg="登出失败")

    def test_02(self):
        u'''密码登录测试'''
        self.login_page = LoginPage(self.driver)
        self.login_page.open_login_page()
        self.login_page.choose_tab_password()
        self.login_page.input_username(self.username)
        self.login_page.input_password(self.password)
        self.login_page.click_btn_login_pwd()
        # 等待时间后续优化
        sleep(3)
        user_id = self.login_page.show_user_id()
        # 判断登录是否成功
        self.assertEqual(user_id, self.expect_user_id, msg='登录失败')
        self.login_page.click_btn_logout()
        sleep(3)
        # 登出后,"退出登录"变为"立即登录"
        text_change = self.login_page.show_text_change()
        # 判断登出是否成功
        self.assertEqual(text_change, "立即登录", msg="登出失败")

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
 def setUpClass(cls):
     cls.driver = webdriver.Firefox(profile)
     login_page = LoginPage(cls.driver)
     login_page.open_login_page()
     login_page.choose_tab_password()
     login_page.input_username("18503035162")
     login_page.input_password("a123456")
     login_page.click_btn_login_pwd()
     sleep(3)