【实际项目】清华大学深圳研究生院_sigs教职员工入职系统

内网生产环境后台

https://hrwelcome.sigs.tsinghua.edu.cn/dashboard/home?org=

内网生产环境前端

https://hrwelcome.sigs.tsinghua.edu.cn/fresh-en/user/home

pyhton脚本导包

#coding=utf8
__author__ = "Marlon"
'''
修改的人:Marlon
修改日期:2021/9/16
用例模块:申请方办公自动化
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
注意事项:执行脚本时务必将IDE编辑器放到笔记本电脑的主屏幕
'''

# 导包固定搭配
from time import sleep
# 引入 airtest_selenium 类
from airtest.core.api import * from selenium import webdriver from airtest_selenium.proxy import WebChrome # 引入 ActionChains和Keys 类 from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.select import Select from selenium.webdriver.common.action_chains import ActionChains # 引入键鼠操作 from pynput import keyboard from pynput.keyboard import Key from pynput import mouse # 导入单元测试框架 import unittest from parameterized import parameterized

 

使用禅道管理Bug的声明周期

 禅道登录自动化脚本

#coding=utf8
__author__ = "Marlon"
'''
修改的人:Marlon
修改日期:2021/9/16
用例模块:申请方办公自动化
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
注意事项:执行脚本时务必将IDE编辑器放到笔记本电脑的主屏幕
'''

# 导包
from time import sleep
# 引入 airtest_selenium 类
# from airtest.core.api import *
from selenium import webdriver
from airtest_selenium.proxy import WebChrome
# 引入 ActionChains和Keys 类
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
# 引入键鼠操作
from pynput import keyboard
from pynput.keyboard import Key
from pynput import mouse
# 导入单元测试框架
import unittest
from parameterized import parameterized





def setUpModule():
    print("test module start >>>>>>>>>>>>>>")


def tearDownModule():
    print("test module end >>>>>>>>>>>>>>")

class ZentaoLoginTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.base_url = "https://chandao.applysquare.net/zentao/bug-browse-77-0-assigntome.html"
        #初始化浏览器
        cls.driver = WebChrome()
        cls.driver.implicitly_wait(10)
        cls.driver.maximize_window()
    @classmethod
    def tearDownClass(cls):
        print("tearDownClass start >>>>>>>>>>>>>>")
        #退出浏览器
        cls.driver.quit()

    # parameterized参数化
    @parameterized.expand([
        ("kangyupeng", "zentaoKYH0403"),
    ])
    def test_case01_login(self,username,passwd):
        print("test_case01 start >>>>>>>>>>>>>>")
        #发送get请求
        self.driver.get(self.base_url)

        self.driver.find_element_by_xpath('//*[@id="account"]').send_keys(username)
        self.driver.find_element_by_xpath('//*[@id="loginPanel"]/div/div[2]/form/table/tbody/tr[2]/td/input').send_keys(passwd)
        self.driver.find_element_by_xpath('//*[@id="submit"]').click()





if __name__ == '__main__':
    unittest.main(verbosity=2)
View Code

 

基本人员新建

# -*- encoding=utf8 -*-
__author__ = "Marlon"

'''
修改的人:Marlon
修改日期:2021/9/7
用例模块:新建基本人员-教职员添加合同
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
'''

# 导包
from time import sleep
from airtest.core.api import *

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from airtest_selenium.proxy import WebChrome


# 基本人员信息,字典
insert_input_dict = {
    #
    "//input[@placeholder='请输入姓氏']" : '教师',
    #
    "//input[@placeholder='请输入名']" : '全球办_台湾',
    # FirstName     
    "//input[@placeholder='First Name']" : '',
    # MiddleName  
    "//input[@placeholder='Middle Name']" : '',
    # LastName
    "//input[@placeholder='Last Name']" : '',
}
# 带下拉列表的输入框,字典
insert_dropdownlist_dict = {
    # 国籍
    "//input[@id='country_id']" : '台湾',
    # 性别    
    "//input[@id='sex']" : '',
}


driver = WebChrome()
driver.implicitly_wait(15)

auto_setup(__file__)

# 定义变量
username = "root@flora.local"
password = "flora#23456"
# 测试地址
url ="https://hrwelcome.sigs.tsinghua.edu.cn/dashboard/home?org="
# 定义方法
def init(url):
    # driver.maximize_window()
    sleep(1)
    driver.get(url)
# 登陆    
def login(username, password):
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").click()
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").send_keys(username)
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys(password)
    sleep(0.1)
    driver.find_element_by_xpath("//button[@type='submit']").click()
# 功能列表选择
def select_click(xpath,name='入职系统后台管理'):
    sleep(1) #等待页面元素加载
    driver.find_element_by_xpath(xpath).click()
# 文本框输入
def input_info(xpath : 'Delete Element Xpath', s : 'Delete Field Name', isClear=False):
    element = driver.find_element_by_xpath(xpath)
    driver.execute_script("arguments[0].scrollIntoView();", element)
    driver.find_element_by_xpath(xpath).click()
    if isClear:
        driver.find_element_by_xpath(xpath).clear()
    driver.find_element_by_xpath(xpath).send_keys(s)
# 下拉框输入
def input_info_radio(xpath : 'Insert Element Xpath', select_key : 'select Field Name'):
    element = driver.find_element_by_xpath(xpath)
    driver.execute_script("arguments[0].scrollIntoView()", element)
    ActionChains(driver).click(driver.find_element_by_xpath(xpath)).send_keys(select_key).perform()
    sleep(1)
    ActionChains(driver).send_keys(Keys.ENTER).perform()
# 新建基本人员
def insert_basic_person(insert_input_dict:'文本框输入', insert_dropdownlist_dict:'下拉框输入'):
    #基本人员的新建按钮
    driver.find_element_by_xpath("//*[@class='ant-btn ant-btn-primary ant-btn-two-chinese-chars']").click()
    for key,value in insert_input_dict.items():
        input_info(key, value)
    sleep(1)
    for key,value in insert_dropdownlist_dict.items():
        input_info_radio(key, value)
    #保存提交表单
    driver.find_element_by_xpath("//button[@type='submit']").click()
    #等待页面加载
    sleep(2)
    



if __name__ == '__main__':
    #初始化
    init(url)
    #登录账号
    login(username, password)
    #功能列表
    select_click(xpath="/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div[2]/div/div[2]",name='入职系统后台管理')
    #新建-基本人员
    insert_basic_person(insert_input_dict,insert_dropdownlist_dict)
    #退出浏览器
    driver.quit()
    
View Code

基本人员新建证件信息

# -*- encoding=utf8 -*-
__author__ = "Marlon"

'''
修改的人:Marlon
修改日期:2021/9/7
用例模块:基本人员_添加证件信息
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
'''

# 导包
from time import sleep
from airtest.core.api import *

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from airtest_selenium.proxy import WebChrome



driver = WebChrome()
driver.implicitly_wait(15)

auto_setup(__file__)


# 定义添加证件信息的人员姓名
person = '教师材料研究员'
# 定义变量
username = "root@flora.local"
password = "flora#23456"
# 测试地址
url ="https://hrwelcome.sigs.tsinghua.edu.cn/dashboard/home?org="
# 后台管理xpath的字典
manage_list_dict = {
    # 后台管理模块
    "入职系统后台管理" : "/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div[2]/div/div[2]",
    # 性别    
    "//input[@id='sex']" : '',
}
idcard_kind =['身份证', '军官证', '护照','其他']
# 测试账号姓名
['教师全球办_台湾','教师全球办_新加坡','教师医院管理研究院','教师人文社会科学部','教师环境与生态研究院','教师海洋工程研究院','教师生物医药与健康工程研究院',
    '教师物流与交通学部','教师信息科学与技术学部','教师未来人居研究院','教师材料研究员'
]

# 定义方法
def init(url):
    # driver.maximize_window()
    sleep(1)
    driver.get(url)
# 登陆    
def login(username, password):
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").click()
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").send_keys(username)
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys(password)
    sleep(0.1)
    driver.find_element_by_xpath("//button[@type='submit']").click()
# 功能列表选择
def select_click(xpath,name='入职系统后台管理'):
    sleep(1) #等待页面元素加载
    driver.find_element_by_xpath(xpath).click()
# 新建一个证件
def new_idcard(cardnum,area):
    driver.find_element_by_xpath("//*[@id=\"identity_type_id\"]").send_keys(idcard_kind[0])
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id=\"identity_type_id\"]").send_keys(Keys.ENTER)
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id=\"identity_id\"]").send_keys(cardnum)
    #点击切换
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/form/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div[4]/div/div[2]/div/div/button").click()
    #国家或地区
    driver.find_element_by_xpath("//*[@id=\"certificate_authority\"]").send_keys(area)
    #保存
    driver.find_element_by_xpath("//button[@type='submit']").click()

# 添加证件信息
def add_idcard(person,cardnum='1101234567892021',area='中国'):
    driver.find_element_by_class_name("ant-input").click()
    driver.find_element_by_class_name("ant-input").send_keys(person)
    sleep(0.5)
    driver.find_element_by_class_name("ant-input").send_keys(Keys.ENTER)
    sleep(2) # 等待延迟加载的页面元素
    # 点击操作编辑按钮
    # driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div[3]/form/div/div/div/div/div/div[2]/table/tbody/tr[2]/td[8]/div/span[1]/span/div/button/span").click()
    # 点击数据行位置
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div[3]/form/div/div/div/div/div/div[2]/table/tbody/tr[2]/td[3]").click()
    # 点击新建按钮
    driver.find_element_by_xpath("//*[@id=\"rc-tabs-0-panel-base_info.person_info\"]/div/div[2]/div[2]/div/div/div/div[1]/div/div[1]/div[2]/span[1]/button").click()
    # 调用函数
    new_idcard(cardnum,area)
    # 等待加载
    sleep(2)

if __name__ == '__main__':
    init(url)
    login(username,password)
    #功能列表
    select_click(xpath=manage_list_dict['入职系统后台管理'])
    #添加用户的证件信息
    add_idcard(person)
    #退出浏览器
    # driver.quit()
View Code

基本人员_添加电话联系方式

# -*- encoding=utf8 -*-
__author__ = "Marlon"

'''
修改的人:Marlon
修改日期:2021/9/7
用例模块:基本人员_添加电话联系方式
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
'''

# 导包
from time import sleep
from airtest.core.api import *

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from airtest_selenium.proxy import WebChrome



driver = WebChrome()
driver.implicitly_wait(15)

auto_setup(__file__)


# 定义添加证件信息的人员姓名
person = '教师全球办_台湾'
# 定义变量
username = "root@flora.local"
password = "flora#23456"
# 测试地址
url ="https://hrwelcome.sigs.tsinghua.edu.cn/dashboard/home?org="
# 后台管理xpath的字典
manage_list_dict = {
    # 后台管理模块
    "入职系统后台管理" : "/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div[2]/div/div[2]",
    # 性别    
    "//input[@id='sex']" : '',
}

# 测试账号姓名
['教师全球办_台湾','教师全球办_新加坡','教师医院管理研究院','教师人文社会科学部','教师环境与生态研究院','教师海洋工程研究院','教师生物医药与健康工程研究院',
    '教师物流与交通学部','教师信息科学与技术学部','教师未来人居研究院','教师材料研究员'
]

# 定义方法
def init(url):
    # driver.maximize_window()
    sleep(1)
    driver.get(url)
# 登陆    
def login(username, password):
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").click()
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").send_keys(username)
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys(password)
    sleep(0.1)
    driver.find_element_by_xpath("//button[@type='submit']").click()
# 功能列表选择
def select_click(xpath,name='入职系统后台管理'):
    sleep(1) #等待页面元素加载
    driver.find_element_by_xpath(xpath).click()
# 新建一个证件
def new_phonenum(phonenum):
    driver.find_element_by_xpath("//*[@id=\"phone\"]").click()
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id=\"phone\"]").send_keys(phonenum)
    sleep(0.5)
    #点击切换
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/form/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/div/button").click()
    #保存
    driver.find_element_by_xpath("//button[@type='submit']").click()

# 添加证件信息
def add_phonenum(person,phonenum='18612345678'):
    driver.find_element_by_class_name("ant-input").click()
    driver.find_element_by_class_name("ant-input").send_keys(person)
    sleep(0.5)
    driver.find_element_by_class_name("ant-input").send_keys(Keys.ENTER)
    sleep(2) # 等待延迟加载的页面元素
    # 点击操作编辑按钮
    # driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div[3]/form/div/div/div/div/div/div[2]/table/tbody/tr[2]/td[8]/div/span[1]/span/div/button/span").click()
    # 点击数据行位置
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div[3]/form/div/div/div/div/div/div[2]/table/tbody/tr[2]/td[3]").click()
    # 页面向下滚动(或者最大化窗口)
    driver.maximize_window()
    sleep(1)
    # 点击新建按钮(电话联系方式)
    driver.find_element_by_xpath("//*[@id=\"rc-tabs-0-panel-base_info.person_info\"]/div/div[4]/div[2]/div/div/div/div[1]/div/div[1]/div[2]/span[1]/button").click()
    # 调用函数
    new_phonenum(phonenum)
    # 等待加载
    sleep(2)

if __name__ == '__main__':
    init(url)
    login(username,password)
    #功能列表
    select_click(xpath=manage_list_dict['入职系统后台管理'])
    #添加用户的证件信息
    add_phonenum(person)
    #退出浏览器
    driver.quit()
View Code

基础管理_用户管理_新建后台管理账号

# -*- encoding=utf8 -*-
__author__ = "Marlon"

'''
修改的人:Marlon
修改日期:2021/9/7
用例模块:基础管理_用户管理_新建后台管理账号
测试环境:MacBook Pro (Retina, 13-inch, Early 2015)
'''

# 导包
from time import sleep
from airtest.core.api import *

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from airtest_selenium.proxy import WebChrome


driver = WebChrome()
driver.implicitly_wait(15)

auto_setup(__file__)



# 基本部门信息,字典
# 人事办-调档
dict_personnel_office_diaodang = {
    # Name
    "//*[@id=\"name\"]" : '人事办-调档',
    # Email
    "//*[@id=\"email\"]" : 'diaodang@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 人事办-超管
dict_personnel_office_chaoguan = {
    # Name
    "//*[@id=\"name\"]" : '人事办-超管',
    # Email
    "//*[@id=\"email\"]" : 'chaoguan@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
dict_materials = {
    # Name
    "//*[@id=\"name\"]" : '材料研究院',
    # Email
    "//*[@id=\"email\"]" : 'materials@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
dict_future_habitat = {
    # Name
    "//*[@id=\"name\"]" : '未来人居研究院',
    # Email
    "//*[@id=\"email\"]" : 'future_habitat@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 信息科学与技术学部
dict_information = {
    # Name
    "//*[@id=\"name\"]" : '信息科学与技术学部',
    # Email
    "//*[@id=\"email\"]" : 'information@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 生物医药与健康工程研究院
dict_biomedicine = {
    # Name
    "//*[@id=\"name\"]" : '生物医药与健康工程研究院',
    # Email
    "//*[@id=\"email\"]" : 'biomedicine@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 海洋工程研究院
dict_ocean = {
    # Name
    "//*[@id=\"name\"]" : '海洋工程研究院',
    # Email
    "//*[@id=\"email\"]" : 'ocean@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 环境与生态研究院
dict_environment = {
    # Name
    "//*[@id=\"name\"]" : '环境与生态研究院',
    # Email
    "//*[@id=\"email\"]" : 'environment@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 人文社会科学部
dict_society = {
    # Name
    "//*[@id=\"name\"]" : '人文社会科学部',
    # Email
    "//*[@id=\"email\"]" : 'society@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 医院管理研究院
dict_hospital = {
    # Name
    "//*[@id=\"name\"]" : '医院管理研究院',
    # Email
    "//*[@id=\"email\"]" : 'hospital@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# TBSI
dict_tbsi = {
    # Name
    "//*[@id=\"name\"]" : 'TBSI',
    # Email
    "//*[@id=\"email\"]" : 'tbsi@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}
# 全球办
dict_global = {
    # Name
    "//*[@id=\"name\"]" : '全球办',
    # Email
    "//*[@id=\"email\"]" : 'global@qh.cn',
    # Set Password
    "//*[@id=\"new_password\"]" : 'passth123',
}


input_dict = dict_personnel_office_chaoguan
# 定义变量
username = "root@flora.local"
password = "flora#23456"
# 测试地址
url ="https://hrwelcome.sigs.tsinghua.edu.cn/dashboard/home?org="
# 后台管理xpath的字典
manage_list_dict = {
    # 后台管理模块
    "入职系统后台管理" : "/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div[2]/div/div[2]",
    # 基础管理模块    
    "基础管理" : "/html/body/div[2]/div/div[2]/div/div[2]/div[2]/div/div/div/div[2]/div[1]/div/div[2]",
}
# 测试账号姓名
['材料研究院','教师全球办_新加坡','教师医院管理研究院','教师人文社会科学部','教师环境与生态研究院','教师海洋工程研究院','教师生物医药与健康工程研究院',
    '教师物流与交通学部','教师信息科学与技术学部','教师未来人居研究院','教师材料研究员'
]

# 定义方法
def init(url):
    # driver.maximize_window()
    sleep(1)
    driver.get(url)
# 登陆    
def login(username, password):
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").click()
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入邮箱']").send_keys(username)
    sleep(0.1)
    driver.find_element_by_xpath("//input[@placeholder='请输入密码']").send_keys(password)
    sleep(0.1)
    driver.find_element_by_xpath("//button[@type='submit']").click()
# 功能列表选择
def select_click(xpath,name='基础管理'):
    sleep(1) #等待页面元素加载
    driver.find_element_by_xpath(xpath).click()
# 文本框输入
def input_info(xpath : 'find Element Xpath', s : 'fillin  Field Name', isClear=False):
    element = driver.find_element_by_xpath(xpath)
    driver.execute_script("arguments[0].scrollIntoView();", element)
    driver.find_element_by_xpath(xpath).click()
    if isClear:
        driver.find_element_by_xpath(xpath).clear()
    driver.find_element_by_xpath(xpath).send_keys(s)

# 新建一个证件
def new_idcard(cardnum,area):
    driver.find_element_by_xpath("//*[@id=\"identity_type_id\"]").send_keys(idcard_kind[0])
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id=\"identity_type_id\"]").send_keys(Keys.ENTER)
    sleep(0.5)
    driver.find_element_by_xpath("//*[@id=\"identity_id\"]").send_keys(cardnum)
    #点击切换
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/form/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div[4]/div/div[2]/div/div/button").click()
    #国家或地区
    driver.find_element_by_xpath("//*[@id=\"certificate_authority\"]").send_keys(area)
    #保存
    driver.find_element_by_xpath("//button[@type='submit']").click()

# 添加证件信息
def add_department(department_dict):
    # 点击新建按钮
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/div[1]/div[1]/div[2]/div[2]/button").click()
    sleep(1) # 等待延迟加载的页面元素
    for key,value in department_dict.items():
        input_info(key, value)
    sleep(1) # 等待延迟加载的页面元素
    # 点击保存按钮
    driver.find_element_by_xpath("//*[@id=\"root\"]/section/section/section/main/div/div[1]/div/form/div/div[3]/div/button[2]").click()
    # 等待加载
    sleep(2)



if __name__ == '__main__':
    #初始化和登录
    init(url)
    login(username,password)
    #功能列表选择
    select_click(xpath=manage_list_dict['基础管理'])
    #新建后台管理部门账号
    add_department(input_dict)
    #退出浏览器
    driver.quit()
View Code

 

 

测试用图片

posted @ 2021-09-02 09:32  Marlon康  阅读(137)  评论(0编辑  收藏  举报