示例#1
0
 def RloeAdd(self):
     """角色新增"""
     log.info("------新增角色------")
     dr = Student(self.driver)
     dr.click("css", "body > div.topTools > div.actionBar > div > a")  # 新增
     dr.send_ke("id", "_easyui_textbox_input3", self.accounts)  # 角色名称
     dr.send_ke("name", "roledesc", "自动化测试添加角色")
     dr.click("link_text", "提交")
    def setUpClass(cls):
        log.info("------角色功能分配模块测试用例------")
        # 只需要修改download.default_directory:路径,谷歌默认下载路径,而且不弹窗。1弹框,0不弹窗
        options = webdriver.ChromeOptions()
        prefs = {'profile.default_content_settings.popups': 0, 'download.default_directory': 'd:\\GoogleFile'}
        options.add_experimental_option('prefs', prefs)
        cls.driver = webdriver.Chrome(executable_path='D:\\python36\\chromedriver.exe', chrome_options=options)  # 谷歌

        # 无界面执行自动化
        # cls.driver = webdriver.PhantomJS()
        cls.driver.get(URL)
        global dr
        title1 = cls.driver.title
        dr = Student(cls.driver)   # 实例化二次开发定位方法
        login = Login_HR           # 实例化登录方法
        try:
            assert title1 in '登录'
            log.info("------进入网站------")
        except:
            print('进入网站失败,请检查服务是否启动')
        login(cls.driver).login(username,password)   # 调用登录方法
        cls.driver.maximize_window()

        # 进入页面操作
        dr.click("xpath", "//*[@id='_easyui_tree_7']/span[3]")   # 展开用户角色管理 列表
        dr.click("xpath", "//*[@id='_easyui_tree_10']/span[4]/a/span")   # 点击用户信息管理
 def DataQuert(self):
     """用户数据权限-查询"""
     dr = Student(self.driver)
     time.sleep(1)
     log.info("------搜索用户账户为:%s------" % self.accounts)
     dr.send_ke("id", "_easyui_textbox_input2", self.accounts)  #根据账户查询
     dr.click("link_text", "查询")
示例#4
0
 def RloeQuert(self):
     """角色查询"""
     dr = Student(self.driver)
     time.sleep(1)
     log.info("------查询角色为:%s------" % self.accounts)
     dr.send_ke("id", "_easyui_textbox_input1", self.accounts)  #根据账户查询
     dr.click("link_text", "查询")
 def UserExportOptions(self):
     '''导出所选项'''
     dr = Student(self.driver)
     dr.click("link_text", "重置")  #重置查询条件初始化
     try:
         dr.click(
             "xpath",
             "//*[@id='tt']/div[1]/div/div[1]/div[2]/div[1]/div/table/tbody/tr/td[1]/div/input"
         )
         self.driver.find_element_by_xpath(
             "//*[@id='tt']/div[1]/div/div[1]/div[2]/div[1]/div/table/tbody/tr/td[1]/div/input"
         ).is_selected()  #判断元素是否选中
         dr.click(
             "css",
             "body > div.topTools > div.actionBar > div > a:nth-child(1)")
     except Exception as e:
         print('Test fail{0}', format(e))
 def DataAss(self):
     dr = Student(self.driver)
     dr.click("xpath", "//*[@id='dept']/li/div/span[3]")  #选择一级组织分配全部
     dr.click("xpath", "/html/body/div[2]/div/div/div/a")  #分配
     dr.click("link_text", "确定")
        time.sleep(1)
        log.info("------搜索用户账户为:%s------" % self.accounts)
        dr.send_ke("id", "_easyui_textbox_input2", self.accounts)  #根据账户查询
        dr.click("link_text", "查询")

    def DataAss(self):
        dr = Student(self.driver)
        dr.click("xpath", "//*[@id='dept']/li/div/span[3]")  #选择一级组织分配全部
        dr.click("xpath", "/html/body/div[2]/div/div/div/a")  #分配
        dr.click("link_text", "确定")


if __name__ == '__main__':
    # 单元测试
    options = webdriver.ChromeOptions()
    prefs = {
        'profile.default_content_settings.popups': 0,
        'download.default_directory': 'd:\\GoogleFile'
    }
    options.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(executable_path='D:\\python36\\chromedriver.exe',
                              chrome_options=options)
    driver.get("http://192.168.0.16:8080/HRAS/login.jsp")
    Login_HR(driver).login("laozi", "a123456")
    dr = Student(driver)
    dr.click("xpath", "//*[@id='_easyui_tree_6']/span[3]")
    dr.click("xpath", "//*[@id='_easyui_tree_9']/span[4]/a/span")
    driver.switch_to.frame("223")
    # 从这里开始调用上面写的方法
    RloeAssig(driver, "Diploma").RloeQuert()
 def UserAss(self):
     dr = Student(self.driver)
 def UserExportWhole(self):
     """导出全部"""
     dr = Student(self.driver)
     dr.click("xpath", "/html/body/div[1]/div[1]/div/a[2]")
     time.sleep(1)
示例#10
0
 def UserAdd(self):
     """用户新增"""
     log.info("------新增用户------")
     dr = Student(self.driver)
     dr.click("xpath", "/html/body/div[1]/div[1]/div/a[3]")  # 新增
     dr.send_ke("id", "_easyui_textbox_input11", self.accounts)  # 用户账户
     # 去掉元素的readonly属性
     js = 'document.getElementById("_easyui_textbox_input14").removeAttribute("readonly");'
     self.driver.execute_script(js)
     now = datetime.date.today() + datetime.timedelta(days=365)
     now = str(now)
     dr.send_ke("id", "_easyui_textbox_input14", now)
     js_V = 'document.getElementById("_easyui_textbox_input15").removeAttribute("readonly");'
     self.driver.execute_script(js_V)
     now_Y = datetime.date.today() + datetime.timedelta(days=365)
     now_Y = str(now_Y)
     dr.send_ke("id", "_easyui_textbox_input15", now_Y)
     dr.send_ke("id", "_easyui_textbox_input12", "普通用户")
     time.sleep(0.5)
     self.driver.find_element_by_id("_easyui_textbox_input12").send_keys(
         Keys.ENTER)
     dr.click(
         "xpath",
         "//*[@id='FormUpdate']/div/div/table/tbody/tr[6]/td[2]/span[1]/span/a"
     )
     names = dr.elements("css", "body > div:nth-child(10) > div >div")
     name = random.randint(1, len(names))
     dr.click("xpath", "//body/div[9]/div/div[%d] " % name)
     Job = dr.element("id", "staffnoShow").text
     log.info("------绑定的员工工号为%s------" % Job)
     dr.send_ke("name", "remark", "自动化测试添加")
     dr.click("link_text", "提交")
示例#11
0
    def RloeQuert(self):
        """角色功能查询"""
        dr = Student(self.driver)
        time.sleep(1)
        log.info("------搜索角色功能为:%s------" % self.accounts)
        dr.send_ke("id", "kw", self.accounts)  #根据账户查询
        time.sleep(0.1)
        role = dr.elements("xpath", "//*[@id='append']/div")
        log.info("------共搜索出%s个角色名称------" % len(role))
        dr.click("xpath", "//*[@id='append']/div[1]")
        system = dr.element("xpath", '//*[@id="functionTr"]/li[1]/div/span[3]'
                            ).is_selected()  #判断系统管理是否被选中
        if system == True:
            print("已分系统管理配权限")
            dr.click("xpath",
                     '//*[@id="functionTr"]/li[1]/div/span[3]')  # 反选取消选中
            dr.click("xpath",
                     '//*[@id="functionTr"]/li[1]/div/span[3]')  # 重新选中
        elif system == False:
            dr.click("xpath", '//*[@id="functionTr"]/li[1]/div/span[3]')

        hr = dr.element("xpath",
                        '//*[@id="functionTr"]/li[2]/div/span[3]').is_selected(
                        )  # 判断人事系统是否被选中
        if hr == True:
            print("已分配人事系统权限")
            dr.click("xpath",
                     "//*[@id='functionTr']/li[2]/div/span[3]")  # 反选取消选中
            dr.click("xpath",
                     "//*[@id='functionTr']/li[2]/div/span[3]")  # 重新选中
        elif system == False:
            dr.click("xpath", '//*[@id="functionTr"]/li[2]/div/span[3]')
        dr.click("xpath", "/html/body/div[2]/div[2]/a/span/span[1]")  #保存