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)
Beispiel #3
0
class TestLogin(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.url = 'https://www.haixinglian.com/passport-signin.html'
        #self.username = '******'
        #self.password = '******'
        self.excel = excel_data.Excel()
        self.login_page = LoginPage(self.driver, self.url, u'海星链')

    def test_login_search(self):
        u'''正常登录'''
        try:
            keyword_list = self.excel.get_list(
                test_data_path + 'login_data.xlsx', 'Sheet1')
            for i in range(0, len(keyword_list)):
                username = keyword_list[i]["用户名"]
                password = keyword_list[i]["密码"]
                if type(username) != str:
                    username = int(username)
                    username = str(username)
                if type(password) != str:
                    password = str(password)
                self.login_page.open()
                self.login_page.input_username(username)
                self.login_page.input_password(password)
                self.login_page.click_login()
                sleep(2)
                self.assertIn(username,
                              self.driver.find_element_by_id('uname_110').text)
                self.driver.find_element_by_xpath(
                    '//*[@id="member_110"]/a[3]').click()
        except Exception as e:
            self.login_page.img_screenshot(u'登陆异常')
            raise e

    def test_jump_forget(self):
        u'''跳转到找回密码页'''
        try:
            for i in range(2):
                self.login_page.open()
                self.login_page.click_forget_password()
                self.assertIn(
                    u'找回密码',
                    self.driver.find_element_by_xpath(
                        '/html/body/div[2]/div/h1').text)
        except Exception as e:
            self.login_page.img_screenshot(u'跳转到找回密码页失败')
            raise e

    def test_jump_register1(self):
        u'''跳转到注册页'''
        try:
            self.login_page.open()
            self.login_page.click_register1()
            self.assertIn(
                u'采购商认证页',
                self.driver.find_element_by_xpath(
                    '/html/body/div[1]/div/div/div[2]/div[1]/span[1]').text)
        except Exception as e:
            self.login_page.img_screenshot(u'登陆_跳转到注册页失败')
            raise e

    def test_jump_register2(self):
        u'''跳转到注册页'''
        try:
            self.login_page.open()
            self.login_page.click_register2()
            self.assertIn(
                u'采购商认证页',
                self.driver.find_element_by_xpath(
                    '/html/body/div[1]/div/div/div[2]/div[1]/span[1]').text)
        except Exception as e:
            self.login_page.img_screenshot(u'登陆_跳转到注册页失败')
            raise e

    def test_jump_offline(self):
        u'''跳转到线下体验'''
        try:
            self.login_page.open()
            sleep(3)
            self.login_page.click_offline()
            #driver.find_element_by_xpath('//*[@id="header"]/div/div/div[2]/span[2]/a').click()
            self.assertIn(
                'Ture',
                self.driver.find_element_by_xpath(
                    '//*[@id="nav"]/div/div/div[2]/div/a[4]').is_selected())
        except Exception as e:
            self.login_page.img_screenshot(u'跳转线下体验失败')

    def test_jump_WeChat(self):
        u'''跳转到微信'''
        try:
            self.login_page.open()
            self.login_page.click_WeChat_login()
            #print(self.driver.title)
            self.assertIn('Log In to WeChat', self.driver.title)
        except Exception as e:
            self.login_page.img_screenshot(u'登陆_跳转到微信失败')
            raise e

    def test_jump_QQ(self):
        u'''跳转到QQ'''
        try:
            self.login_page.open()
            self.login_page.click_QQ_login()
            self.assertIn('QQ帐号安全登录', self.driver.title)
        except Exception as e:
            self.login_page.img_screenshot(u'登陆_跳转到QQ失败')
            raise e

    def tearDown(self):
        self.driver.close()