Esempio n. 1
0
def setvalue(inputform:form,dic:dict,begin:str,end:str):
    '''
    通过输入数据XML自动生成表单的赋值语句
    :param inputform: 脚本需要的输入值序列
    :param dic: 脚本需要的字典
    :param begin: 起点
    :param end: 结束点
    :return:
    '''
    flag = False
    for (key,value) in dic.items():
        #print(key, value)
        name = key.split('#')[0].split('_')[0]
        type =''  #输入框的类型,R只读,D默认值
        if len(key.split('#'))==2:
            type = key.split('#')[1]
        if key==begin or flag :

            flag = True
            if 'R' in type:
                infostr = '检查输入框:{0},是否只读'.format(name)
                logger.info(infostr)

                if not readonly(inputform[name]):
                    errorstr = '输入框:{0},只读检查失败'.format(name)
                    logger.error(errorstr)
                    raise ClassSelenium.SeleniumExceptions(errorstr)

            # 数据检查,如果输入框类型是含有默认值,输入数据不能为空_begin
            if 'D' in type:
                    if value:
                        infostr = '检查输入框{0}默认值是否为{1}'.format(name,value)
                        logger.info(infostr)
                        inputform.checkvalue(name,value)

                    else:
                        errorstr = '输入框{0}含有默认值,不允许输入数据值为空'.format(key)
                        logger.error(errorstr)
                        raise ClassSelenium.SeleniumExceptions(errorstr)
                        # 数据检查,如果输入框类型是含有默认值,输入数据不能为空_end
            elif value:
                if '=' in value:  #输入值是字典类型,用于小手
                    tempdict = {}
                    temps = value.spit(',')
                    for temp in temps:
                        tempdict[temp.split('=')[0]]=temp.split('=')[1]
                        inputform.setvalue(name,tempdict)
                elif ',' in value:     #输入值是多选值
                    logger.debug(r"inputform.setvalue('{0}','{1}'.split(','))".format(name,value))
                    inputform.setvalue(name, value.split(','))
                #print('inputform.setvalue({0},{1})'.format(key,value))
                else:   #输入值是正常字符串
                    logger.debug(r'inputform.setvalue("{0}","{1}")'.format(name,value))
                    inputform.setvalue(name,value)
        if key == end:
            return
Esempio n. 2
0
def SelectListData(driver,k,v,action='Click'):
    '''
    通过传入的driver自动获取当前表格,通过k:列名 v:列中字段值,锁定所需的行,然后勾选
    :param driver:
    :param k:
    :param v:
    :return:
    '''
    i=1
    j=1
    finstr = '开始查找表格数据,列名:{0},列值{1},action:{2}'.format(k,v,action)
    logger.info(finstr)
    elements=None
    try:
        elements=driver.getelementbyattribute('css selector:.hc-datagrid-header>table>tbody>tr>td',getall = True)
    except:
        elements = driver.getelementbyattribute('css selector:.hc-datagrid-body>table>thead>tr>td', getall=True)
    notfindflag = 1
    for m in elements:
        xt = m.gettext()  # 获取表头值�
        if xt == k:
            notfindflag=0
            break
        i = i + 1
    if notfindflag:
            finstr = '未找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action)
            logger.error(finstr)
            raise ClassSelenium.SeleniumExceptions(finstr)
    element1s=driver.getelementbyattribute('css selector:.hc-datagrid-body>table>tbody>tr',getall=True)

    notfindflag = 1
    for n in  element1s:
        try:
            ts=n.getelementbyattribute('css selector:td:nth-child('+str(i)+')',getall = True)
        except:
            if element1s[0].getelementbyattribute('xpath:td', getall=True)[0].gettext() == '暂无数据':
                finstr = '查询表格数据为空,列名:{0},列值{1},action:{2}'.format(k, v, action)
                logger.error(finstr)
                raise ClassSelenium.SeleniumExceptions(finstr)
        xs=ts[0].gettext()   # 获取cell值�
        
        if xs==v:
            notfindflag =0
            if action =='Select':
                ts = n.getelementbyattribute('css selector:td:nth-child('+str(1)+')').Click()
            else:
                ts[0].Click()
            finstr = '找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action)
            logger.info(finstr)
            break
        j=j+1
    if notfindflag:
        finstr = '未找到表格数据,列名:{0},列值{1},action:{2}'.format(k, v, action)
        logger.error(finstr)
        raise ClassSelenium.SeleniumExceptions(finstr)
Esempio n. 3
0
    def setvalue(self,name,value):
        '''
        表单输入框的label值,输入到输入框的值
        :param name:
        :param value:
        :return:
        '''
        
        try:
            hand = self.loanform.getelementbyattribute('xpath:descendant::label[@title="{0}"]/following-sibling::div/div/i[@class="fa fa-hand-pointer-o u-autoitem-down"]'.format(name))
        except:
            pass
        else:
            hand.Click()
            tempaddwin = self.driver.getelementbyattribute(r'xpath://body/div[@style="display: block;"][last()]/div[2]')
            handobject = choosehand(self.driver,tempaddwin)
            handobject.fastserach(value)
            return

        self._getinput(name)
        cureletype = self._geteletype()
        if cureletype=='str':
            self._settextvalue(value)
        elif cureletype=='calendar':
            self._setcalendarvalue(value)
        elif cureletype=='singtree':
            self._setsingtreevalue(value)
        elif cureletype=='select':
            self._setselevalue(value)
        elif cureletype == 'unknow':
            errorcureletype = '获取表单输入框{0}属性的时候失败,输入框为未知类型'
            logger.error(errorcureletype)
            raise ClassSelenium.SeleniumExceptions(errorcureletype)
Esempio n. 4
0
 def _setsingtreevalue(self,value):
     self.curinputele.Click()
     self.curinputele.sendkeys(value[:1])
     #temp = self.hidediv.getelementbyattribute('tag name:div,style:[\s\S]*display: block;[\s\S]*')
     temp =  self.driver.getelementbyattribute('xpath://div[@class="h_screen"]/following-sibling::div/div[1],style:[\s\S]*display: block;')
     listele = self.driver.getelementbyattribute(r'xpath:.//span[text()="{0}"]'.format(value))
     listele.Click()
     title = self.curinputele.getattribute('title')
     if title!=value:
         raise ClassSelenium.SeleniumExceptions('单选属性选择控件选择值:{0} 不成功'.format(value))
Esempio n. 5
0
 def checkvalue(self,name,value):
     self._getinput(name)
     cureletype = self._geteletype()
     if cureletype=='calendar':
         title = self.curinputele.getelementbyattribute('xpath:preceding-sibling::input',getall=True)[0].getattribute('value')
     else:
         title = self.curinputele.getattribute('title')
     if value not in title:
         errorcureletype = '检查输入框默认值有误,输入框:{0},默认值{1},实际值:{2}'.format(name,value,title)
         logger.error(errorcureletype)
         raise ClassSelenium.SeleniumExceptions(errorcureletype)
Esempio n. 6
0
 def _setcalendarvalue(self,value):
     self.curinputele.Click()
     self.curinputele.clear()
     xpathstr = 'xpath://div[@class="h_screen"]/following-sibling::div,style:[\s\S]*display: block;[\s\S]*,class:[\s\S]*datetimepicker[\s\S]*'
     temp = self.driver.getelementbyattribute(xpathstr)
     self.curinputele.sendkeys(value)
     self.curinputele.Click()
     temp.getelementbyattribute('css selector:.day.active').Click()
     inputdate = self.curinputele.getelementbyattribute('xpath:preceding-sibling::input',getall =True)[0]
     title = inputdate.getattribute('value')
     if title != value:
         raise ClassSelenium.SeleniumExceptions('文本控件输入值:{0} 不成功'.format(value))
     self.loanform.Click()
Esempio n. 7
0
 def _setselevalue(self,value):
     self.curinputele.Click()
     #temp = self.hidediv.getelementbyattribute('tag name:div,style:[\s\S]*display: block;[\s\S]*')
     temp = self.driver.getelementbyattribute('xpath:.//div[@id="hc_hide_div"]/div,style:[\s\S]*display: block;[\s\S]*')
     if  temp.getattribute('multiple_line') == 'true':   # 如果是多选框执行多选框赋值函数
         self._setmulselevalue(value)
     else:
         #tempstr = 'xpath:ul/li[@title ="{0}"]'.format(value)
         value=value.strip()
         tempstr = 'xpath:ul/li/label'
         listeles = temp.getelementbyattribute(tempstr, getall=True)
         for listele in listeles:
             if value in listele.gettext():
                 listele.Click()
                 break
         title = self.curinputele.getattribute('title').strip()
         if title!=value:
             raise ClassSelenium.SeleniumExceptions('单选框值:{0} 选择不成功'.format(value))
Esempio n. 8
0
    def _getinput(self,name):
#         tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/input[@title]'.format(value)
        #增加对textarea 类型的支持
        try:
            tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/input'.format(name)
            inputlist = self.loanform.getelementbyattribute(tempstr,getall='True')
        except:
            tempstr = 'xpath:descendant::label[@title="{0}"]/following-sibling::*/descendant::*/textarea'.format(name)
            inputlist = self.loanform.getelementbyattribute(tempstr, getall='True')

        if(len(inputlist) == 1):
            self.curinputele = inputlist[0]
        elif(len(inputlist) == 2):
            self.curinputele = inputlist[1]
        elif(len(inputlist) == 3):
            self.curinputele = inputlist[1]
        else:
            raise ClassSelenium.SeleniumExceptions("Form有新的输入框类型出现,需要添加功能")
        return self.curinputele
Esempio n. 9
0
    def search(self,*kw,**kkw):
        """
        通过输入条件,查询对手方,如果不输入默认为None
        :param l_rival_id: 对手方序号
        :param vc_all_name: 对手方名称
        :param vc_rival_type: 对手方类型
        :return: 空
        """
        if kw:
            if len(self.names)<len(kw):
                raise ClassSelenium.SeleniumExceptions('输入框和参数数值对应不正确')
            i = 0
            for j in kw:
                self.sform.setvalue(self.names[0],j)
                i +=1

        elif kkw:
            for (name,value) in kkw.items():
                self.sform.setvalue(name,value)
        self.sform.button('查询')
Esempio n. 10
0
def oprightcopy():
    SelectListData(driver,'归属部门','webUI')
    buttonmenu.getelementbyattribute('link text:用户权限复制').Click()
    addwin=driver.getelementbyattribute(r'xpath://*****:*****@style="display: block;"]/div[2]')
    addwin.getelementbyattribute('tag name:a,title:关闭').Click()
    buttonmenu.getelementbyattribute('link text:用户权限复制').Click()
    # 角色分配窗体
    v1 = addwin.getelementbyattribute(r'xpath:descendant::label[@title="用户编号"]/following-sibling::*/descendant::*/input[last()]')
    v2 = addwin.getelementbyattribute(r'xpath:descendant::label[@title="用户名称"]/following-sibling::*/descendant::*/input[last()]')
    addwin.getelementbyattribute('tag name:button,text:清空').Click()
    if  notemptycheck(v1,v2):
        raise ClassSelenium.SeleniumExceptions("角色分配清空操作失败")
    v1.sendkeys('0001')
    #v2.sendkeys('3')
    addwin.getelementbyattribute('tag name:button,text:查询').Click()
    SelectListData(addwin,'用户编号','0001')
    addwin.getelementbyattribute('tag name:button,text:权限复制').Click()
    msgfloat(driver,'确认','请您确认是否提交','取消','用户权限复制')
    addwin.getelementbyattribute('tag name:button,text:权限复制').Click()
    msgfloat(driver,'确认','请您确认是否提交','确定','用户权限复制')
    htips(driver,'操作成功')
Esempio n. 11
0
    def add(self):
        self.window.getelementbyattribute('link text:新增').Click()
        time.sleep(1)
        #addwin = driver.getelementbyattribute(r"xpath:.//*[@id='addWin']",getall =True)[-1]

        addwin = driver.getelementbyattribute(
            r'xpath://*****:*****@style="display: block;"][last()]/div[2]')
        #print(len(a))
        self.subform = form(driver, addwin)
        #addwin.getelementbyattribute('tag name:button,text:确定').Click()
        if not readonly(self.subform['对手方']):
            raise ClassSelenium.SeleniumExceptions('对手方字段非只读')

        self.subform.setvalue('股东名称', 'webUI')
        self.subform.setvalue('股东类别', '1:个人')
        self.subform.setvalue('关联关系', '1:大股东')
        self.subform.setvalue('证件类型', '11:户口簿')
        self.subform.setvalue('证件号码', '1231231213')
        self.subform.setvalue('持股比例(%)', '12')
        self.subform.button('确定')
        # 弹出提示信息begin
        msgfloat(driver, '提示', '操作成功', '确定', '股东信息新增')
Esempio n. 12
0
    def modify(self):
        SelectListData(self.driver, InputData.get("表格列名"),
                       InputData.get("表格列值"))
        self.downwindow.getelementbyattribute('link text:修改').Click()
        addwin = driver.getelementbyattribute(
            r'xpath://body/div[@style="display: block;"]/div[2]')
        driver.getelementbyattribute('tag name:button,text:取消').Click()
        self.downwindow.getelementbyattribute('link text:修改').Click()
        addwin = driver.getelementbyattribute(
            r'xpath://body/div[@style="display: block;"]/div[2]')

        loanform = form(driver, addwin)
        v1 = loanform['对手名称']
        v2 = loanform['银行总行']
        v3 = loanform['银行账户']
        if not readonly(v1, v2, v3):
            raise ClassSelenium.SeleniumExceptions('对手方账号修改字段非只读')

        setvalue(loanform, InputData, '银行名称', '是否内部账户')

        loanform.button('确定')
        msgfloat(self.driver, '提示', '操作成功', '确定', '对手方账号修改')
        return
Esempio n. 13
0
 def _setmulselevalue(self,value):
     '''
         value:支持多个值传入,用','隔开
     '''
     #self.curinputele.Click()
     #temp = self.hidediv.getelementbyattribute('tag name:div,style:[\s\S]*display: block;[\s\S]*')
     temp = self.driver.getelementbyattribute('xpath:.//div[@id="hc_hide_div"]/div,style:[\s\S]*display: block;[\s\S]*')
     # 已经选择的全部清除
     try:
         listeles = temp.getelementbyattribute('xpath:ul/li[@class="h_cur"]',getall=True)
         for i in listeles:
             i.Click()
     except Exception as e:
         print("except",e)
     #values = set(value.split(','))
     tempstr = 'xpath:ul/li/label'
     listeles = temp.getelementbyattribute(tempstr, getall=True)
     if isinstance(value,str):
         numvalue =1
         for listele in listeles:
             if value in listele.gettext():
                 listele.Click()
                 break
     else :
         numvalue = len(value)
         for i in value:
         #tempsrt = 'xpath:ul/li,title:\s*{0}\s*'.format(i)
             for listele in listeles:
                 if i in listele.gettext():
                     listele.Click()
                     break
     title = self.curinputele.getattribute('title')
     if len(title.split(',')) != numvalue:
         errorstring = '多选框值:{0} 选择不成功:输入数量:{1}选择数量:{2}'.format(numvalue,len(title.split(',')))
         logger.error(errorstring)
         raise ClassSelenium.SeleniumExceptions(errorstring)
     self.loanform.Click()
Esempio n. 14
0
 def button(self,name):
     self.window.getelementbyattribute('tag name:button,text:选择').Click()
     if self.window.is_displayed():
         raise ClassSelenium.SeleniumExceptions('对手方选择框没有正常关闭')