首页 > 代码库 > selenium之测试角色管理页面举例

selenium之测试角色管理页面举例

 

# 测试角色权限管理页面功能
# author:xr
# date:2017-07-20
from selenium import webdriver
from login_page import LoginPage
import random, time

login_obj = LoginPage()
driver = webdriver.Chrome()
time.sleep(2)
driver = login_obj.login(driver)  # 登录
driver.find_element_by_id(‘4‘).click()  # 进入监控管理
time.sleep(1)
# 进入角色管理
driver.find_element_by_xpath(‘//a[@url="manager/role/role_list.do"]‘).click()
time.sleep(2)

# 定义变量
random_num_to_str = str(random.randint(1000, 9999))  # 随机数,保证不重复
role_name = ‘role_‘ + random_num_to_str  # 角色名,限制10个字符
spec_context = ‘spec_‘ + random_num_to_str  # 备注信息
modify_spec_context = spec_context + ‘_modify‘  # 修改后的备注信息


def create_role():
    ‘‘‘新增角色‘‘‘
    driver.find_element_by_id(‘addRow‘).click()
    driver.find_element_by_id(‘role_name‘).send_keys(role_name)
    driver.find_element_by_id(‘spec‘).send_keys(spec_context)
    time.sleep(3)
    driver.find_element_by_id(‘userSave‘).click()
    time.sleep(3)


def query_role_by_name():
    ‘‘‘查询角色‘‘‘
    # role_name = ‘role_9483‘
    driver.find_element_by_id(‘searchKey‘).send_keys(role_name)
    driver.find_element_by_id(‘search‘).click()
    time.sleep(3)


def edit_role():
    ‘‘‘编辑角色‘‘‘
    driver.find_element_by_xpath("//button[@title=‘编辑‘]").click()  # 查找title=‘编辑‘的button
    driver.find_element_by_id(‘spec‘).clear()
    driver.find_element_by_id(‘spec‘).send_keys(modify_spec_context)
    time.sleep(2)
    driver.find_element_by_id(‘userSave‘).click()
    time.sleep(3)


def bind_menu():
    ‘‘‘菜单绑定‘‘‘
    driver.find_element_by_xpath("//a[@title=‘菜单绑定‘]").click()
    driver.find_element_by_xpath("//div[@class=‘checkBoxUp‘]/div[1]/i").click()  # 全选菜单
    time.sleep(3)
    driver.find_element_by_id(‘userSave‘).click()
    time.sleep(3)


def del_role():
    ‘‘‘删除角色‘‘‘
    driver.find_element_by_xpath("//a[@title=‘删除‘]").click()
    time.sleep(1)
    driver.find_element_by_class_name("aui_state_highlight").click()
    time.sleep(3)


create_role()
query_role_by_name()
edit_role()
bind_menu()
del_role()

# 关闭浏览器
login_obj.quit()

 

selenium之测试角色管理页面举例