class LoginTest(MyTest): """登录测试""" def setUp(self): # super(LoginTest, self).setUp() self.driver = AppiumDriver().start_appium('4723', 0) # 如果有系统更新的话,直接取消更新 self.cancle_dialog = CancleDialog(self.driver) self.cancle_dialog.cancle_update() # 用户名密码登陆的实例 self.lp = LoginPage(self.driver) # 三方登陆的实例 self.tp = ThirdLogin(self.driver) def user_login_verify(self, phone='', password=''): self.lp.user_login(phone, password) def test_login1(self): """用户名、密码为空""" self.user_login_verify() try: self.assertEqual(self.lp.get_message(), u'请输入正确的手机号码', '手机号输入格式错误的提示不正确') except AssertionError, msg: screenshot() print msg finally:
def setUp(self): # super(LoginTest, self).setUp() self.driver = AppiumDriver().start_appium('4723', 0) # 如果有系统更新的话,直接取消更新 self.cancle_dialog = CancleDialog(self.driver) self.cancle_dialog.cancle_update() # 用户名密码登陆的实例 self.lp = LoginPage(self.driver) # 三方登陆的实例 self.tp = ThirdLogin(self.driver)
def test_create_post(self): username = '******' password = '******' login_page = LoginPage(self.dr) dashboard_page = login_page.login_success(username, password) post_detail_page = dashboard_page.click_create_new_post() title = content = time.strftime("%Y%m%d%H%M%S") post_detail_page.update_post_title(title) post_detail_page.update_post_content(content) post_detail_page.publish_post() post_page = PostPage(self.dr) post_page.click_all_post() self.assertTrue(title, post_page.first_post().text)
def test_login_pawd_null(self): '''密码为空登录''' po = LoginPage(self.driver) po.open() po.login_action("testaaa", "") sleep(2) self.assertEqual(po.login_error_hint(), '请输入密码')
def test_login_user_pawd_null(self): '''用户名、密码为空登录''' po = LoginPage(self.driver) po.open() po.login_action("", "") sleep(2) self.assertEqual(po.login_error_hint(), '请输入帐号')
def test_login_pawd_null(self): '''密码为空登录''' po = LoginPage(self.driver) po.open() po.login_action("testaaa","") sleep(2) self.assertEqual(po.login_error_hint(), '登录失败,请检查您的用户名或密码是否填写正确。')
def test_login_user_pawd_error(self): '''用户名、密码为错误''' po = LoginPage(self.driver) po.open() character = random.choice('zyxwvutsrqponmlkjihgfedcba') username = "******" + character po.login_action(username, "@#$%") sleep(2) self.assertEqual(po.login_error_hint(), '帐号或密码错误')
def test_login_user_pawd_error(self): '''用户名、密码为错误''' po = LoginPage(self.driver) po.open() character = random.choice('登录失败,请检查您的用户名或密码是否填写正确。') username = "******" + character po.login_action(username,"@#$%") sleep(2) self.assertEqual(po.login_error_hint(), '登录失败,请检查您的用户名或密码是否填写正确。')
def test_login_success(self): '''用户名、密码正确,登录成功''' po = LoginPage(self.driver) po.open() user = "******" po.login_action(user, "password") sleep(2) po2 = MailPage(self.driver) self.assertEqual(po2.login_success_user(), user + "@163.com")
def test_login_success(self): '''用户名、密码正确,登录成功''' po = LoginPage(self.driver) po.open() user = "******" po.login_action(user,"123456") sleep(2) po2 = homePage(self.driver) self.assertEqual(po2.login_success_user(),'何美建')
class LoginHandle(object): def __init__(self, driver): self.driver = driver self.login_p = LoginPage(self.driver) def send_username(self, username): self.login_p.get_username_element().clear() self.login_p.get_username_element().send_keys(username) def send_password(self, password): self.login_p.get_password_element().clear() self.login_p.get_password_element().send_keys(password) def click_submit_btn(self): self.login_p.get_submit_element().click() # if __name__ == '__main__': # driver = webdriver.Chrome() # lh = LoginHandle(driver) # driver.get('http://127.0.0.1/zentao/user-login.html') # lh.send_username('admin') # lh.send_password('Aa1234') # lh.click_submit_btn()
class LoginHandle(object): """打开页面后自动输入相应信息""" def __init__(self, driver): self.driver = driver self.login_p = LoginPage(self.driver) # 输入用户名 def send_user_name(self, username): logger.file("输入的用户名是:" + username) screenshot_file_path = screenshot_file() self.login_p.get_username_element().send_keys(username) logger.console("".format(screenshot_file_path)) self.driver.save_screenshot(screenshot_file_path) # 输入密码 def send_user_password(self, password): logger.file("输入的密码是:" + password) self.login_p.get_password_element().send_keys(password) # 获取文字信息 def get_login_error(self, info): try: # 容错处理 text_error = self.login_p.get_login_error_element() except: text_error = None return text_error # 点击登录按钮 def click_submit_btn(self): self.login_p.get_submit_element().click() # 获取登录按钮文字 def get_submit_btn_text(self): """如获取不到信息,表明页面已成功跳转""" return self.login_p.get_submit_element().text # 点击用户账号登录,转用户账号登录 def click_login_qrcodebtn(self): return self.login_p.get_login_qrcodebtn_element().click()
def __init__(self, driver): self.driver = driver self.login_p = LoginPage(self.driver)
def test_login_success(self): username = '******' password = '******' login_page = LoginPage(self.dr) dashboard_page = login_page.login_success(username, password) self.assertTrue("mini2019" in dashboard_page.greeting_link().text)