def test_captcha_with_refresh_page(sb, open): captcha_1 = LoginPage.get_captcha_from_redis(sb) sb.refresh_page() sb.sleep(2) captcha_2 = LoginPage.get_captcha_from_redis(sb) assert (captcha_2 != '') assert (captcha_1 != captcha_2)
def test_refresh_captcha(sb, open): captcha_1 = LoginPage.get_captcha_from_redis(sb) CAPTCHA_REFRESH_BUTTON = 'div.verify-code > div.refresh > i' sb.click(CAPTCHA_REFRESH_BUTTON) sb.sleep(2) captcha_2 = LoginPage.get_captcha_from_redis(sb) assert (captcha_2 != '') assert (captcha_1 != captcha_2)
def test_first_login_reset_password(sb, login, setup_user): # 登陆系统创建新用户,并退出当前用户 MenuBar.click_personal_info_menu_item(sb, '退出系统') # 登陆新用户,并修改密码 LoginPage.login(sb, setup_user['name'], '888888') PersonInfoPage.reset_password(sb, '888888', 'Guard123', 'Guard123') sb.sleep(5) # 重新登陆系统,验证密码修改成功 LoginPage.login(sb, setup_user['name'], 'Guard123') sb.assert_element_visible('.avatar-name')
def test_login_with_wrong_password_five_times(sb, login, setup_user): ALERT_MESSAGE_LIST = [ '用户名或密码有误,请重新输入,您还有 4 次机会', '用户名或密码有误,请重新输入,您还有 3 次机会', '用户名或密码有误,请重新输入,您还有 2 次机会', '用户名或密码有误,请重新输入,您还有 1 次机会', '多次输入密码有误,账户已被锁定,请联系IT部门' ] MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(5): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) LoginPage.assert_alert_message(sb, ALERT_MESSAGE_LIST[i]) sb.sleep(2)
def login_web(start_driver_and_quit): # 成功登录网站 start_driver_and_quit.get( f'http://{get_run_env()["host"]}/login' ) # start_driver_and_quit.get("http://10.151.3.96/login") LoginPage(start_driver_and_quit).login( f'{get_run_env()["username"]}', f'{get_run_env()["password"]}' ) # LoginPage(start_driver_and_quit).login("zhuwenqin", "888888") yield start_driver_and_quit
def test_login_with_reset_locked_account(sb, login, setup_user): #5次登录错误,账户被锁定 MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(5): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) #管理员登录,重置密码 LoginPage.login(sb, sb_config.username, sb_config.password) sb.sleep(2) MenuBar.click_menu_item_by_text(sb, '配置', '用户管理') default_password = UserPage.reset_user_password(sb, setup_user['name']) MenuBar.click_personal_info_menu_item(sb, '退出系统') sb.sleep(2) # 重新登录,并修改密码 LoginPage.login(sb, setup_user['name'], str(default_password).strip()) PersonInfoPage.reset_password(sb, str(default_password).strip(), 'Guard123', 'Guard123') sb.sleep(5) # 重新登陆系统,验证密码修改成功 LoginPage.login(sb, setup_user['name'], 'Guard123') sb.assert_element_visible('.avatar-name')
def test_locked_account_login_in_thirty_minutes(sb, login, setup_user): MenuBar.click_personal_info_menu_item(sb, '退出系统') for i in range(6): LoginPage.login(sb, setup_user['name'], '123456') sb.sleep(1) LoginPage.assert_alert_message(sb, "多次输入密码有误,账户已被锁定,请联系IT部门")
def login_with_wrong_username_password(sb, open, request): username = request.param['username'] password = request.param['password'] LoginPage.login(sb, username, password)
def test_login_with_wrong_password(sb): LoginPage.login(sb, sb_config.username, '123456') LoginPage.assert_alert_message(sb, '用户名或密码有误,请重新输入,您还有 4 次机会')
def test_login_with_wrong_username(sb): LoginPage.login(sb, 'user_not_exist', '888888') LoginPage.assert_alert_message(sb, '用户名或密码错误,请重新输入')
def test_login_with_wrong_captcha(sb): LoginPage.login(sb, sb_config.username, sb_config.password, 'captcha') LoginPage.assert_alert_message(sb, '验证码错误')
def test_login(sb): LoginPage.login(sb, sb_config.username, sb_config.password) sb.assert_element_visible('.avatar-name')
def login(sb): """ 登录命令行中指定用户 """ LoginPage.login(sb, sb_config.username, sb_config.password)
TIME_END = ( By.XPATH, f'//div[contains(@class, "el-date-range-picker") and contains(@style, "position")]//div[contains(@class,"is-left")]//td//span[contains(text(),{today_text})]' ) BasePage(self.driver).mouse_move_ele_and_click(TIME_CONTROL, TIME_END) def assert_timezone_section(self): # 判断选定的时间条件下的时间段是否成功添加 CHECK_CON_RESULT = ( By.XPATH, '//div[@class="el-tab-pane" and @style=""]//div[contains(@class, "el-row")]//span[contains(text(), ":")]' ) return BasePage(self.driver).get_text(CHECK_CON_RESULT) if __name__ == '__main__': from selenium import webdriver from guard.pages.components.menubar import MenubarPage from guard.pages.login import LoginPage driver = webdriver.Chrome() driver.get("http://10.151.3.96/login") LoginPage(driver).login("zhuwenqin", "888888") MenubarPage(driver).click_nav_item("配置", "时间条件") TimezonePage(driver).add_timezone_name("test_时间条件") # TimezonePage(driver).create_holidays("添加假期", "假期名称1") # TimezonePage(driver).create_workday("添加特殊工作日", "工作日名称1") # TimezonePage(driver).add_timezone_name("timezone1") # TimezonePage(driver).add_timezone_name("timezone2") # TimezonePage(driver).delete_or_rename_timezone_name("timezone1", "重命名") # TimezonePage(driver).delete_or_rename_timezone_name("timezone2", "删除")
def setUp(self): super(SmokeTest, self).setUp() LoginPage.login(self, sb_config.username, sb_config.password)
def test_login_success(login): LoginPage(login).login(*LoginData.success_login_data) # 断言 - 只要判断首页的某个指定元素存在,说明登录成功并进行页面跳转 assert LoginPage(login).is_login_success()