コード例 #1
0
 def __init__(self,responseData,setApp,setpath,responseResult,istoken,token_value,Authorization):
     self.responseData = responseData
     self.istoken = istoken
     self.setpath = setpath
     self.setApp = setApp
     self.responseResult = responseResult
     self.tokenvalue =token_value
     self.Authorization = Authorization
     self.log = Log().logger()
コード例 #2
0
ファイル: baseapp.py プロジェクト: jim-xiemeng/DestroyerRobot
class BaseApp:
    logger = Log().logger()
    def __init__(self,driver):
        self.driver = driver
        self.TouchAction = TouchAction(driver) #滑动操作


    def implicitly_wait(self):
        time.sleep(2)
        self.driver.implicitly_wait(10)

    def getElementByElement(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        try:
            self.logger.info("查找【%s】的【%s】元素", page_keyword, ui_keyword)
            self.implicitly_wait()
            element =self.driver.find_element(page_keyword, ui_keyword)
        except NoSuchElementException:
            self.logger.info('页面元素不存在')
        else:
            return element

    def getElementByElements(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        try:
            self.logger.info("查找【%s】的【%s】元素", page_keyword, ui_keyword)
            self.implicitly_wait()
            elements = self.driver.find_elements(page_keyword, ui_keyword)
        except NoSuchElementException:
            self.logger.info('页面元素不存在')
        else:
            return elements

    def click(self, driver_ele):
        """
        判断页面元素是否存在,存在点击
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        driver_ele.click()

    def sendkeys(self,elements,ele_value):
        """
        判断页面元素是否存在,如果存在输入信息
        :param elements:
        :param ele_value:
        :return:
        """
        self.clear(elements)
        self.implicitly_wait()
        elements.send_keys(ele_value)
    def clear(self,driver_ele):
        """
        清除缓存信息
        :param driver_ele:
        :return:
        """
        driver_ele.clear()
    def save_img(self,img_path,time_stamp):
        """
        截图
        :img_path :图片路径
        :time_stamp: 获取时间格式
        :return:
        """
        self.implicitly_wait()
        self.driver.get_screenshot_as_file("%s/error%s.png" %(img_path,time_stamp))

    def get_text(self,driver_ele):
        """
        获取文本内容
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("获取文本内容【%s】", driver_ele.text)
        self.implicitly_wait()
        return driver_ele.text

    def get_size(self):
        """
        获取手机屏幕尺寸
        :return:
        """
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        return x, y

    #修改刘建培新增内容
    def swipes(self,x1,y1,x2,y2,times):
        """
        输入滑动信息
        :param x1:
        :param y1:
        :param x2:
        :param y2:
        :param times:
        :return:
        """
        self.implicitly_wait()
        self.driver.swipe(x1, y1, x2, y1, 1000)

    # 向左滑动屏幕 刘建培新增
    def swipe_Left(self,  t=1000, n=1):
        l = self.driver.get_window_size()
        x1 = l['width'] * 0.75
        y1 = l['height'] * 0.5
        x2 = l['width'] * 0.05
        for i in range(n):
            self.driver.swipe(x1, y1, x2, y1, t)


    def swipLeft(self):
        """
        左滑
        :return:
        """
        self.implicitly_wait()
        appsize = self.get_size()
        x1 = int(appsize[0]*0.9)
        y1 = int(appsize[1]*0.5)
        x2 = int(appsize[0]*0.1)
        self.driver.swipe(x1,y1,x2,y1,1000)

    # 向上滑动屏幕 刘建培新增
    def swipe_Up(self, t=1000, n=1):
        l = self.driver.get_window_size()
        x1 = l['width'] * 0.5  # x坐标
        y1 = l['height'] * 0.75  # 起始y坐标
        y2 = l['height'] * 0.25  # 终点y坐标
        for i in range(n):
            self.driver.swipe(x1, y1, x1, y2, t)


    def swipeUp(self):
        """
        上滑
        :return:
        """
        self.implicitly_wait()
        appsize = self.get_size()
        x1 = int(appsize[0] * 0.5)
        y1 = int(appsize[1] * 0.9)
        y2 = int(appsize[1] * 0.35)
        self.driver.swipe(x1, y1, x1, y2, 1000)

    # 向下滑动屏幕 刘建培新增
    def swipe_Down(self,  t=1000, n=1):
        l = self.driver.get_window_size()
        x1 = l['width'] * 0.5  # x坐标
        y1 = l['height'] * 0.25  # 起始y坐标
        y2 = l['height'] * 0.75  # 终点y坐标
        for i in range(n):
            self.driver.swipe(x1, y1, x1, y2, t)


    def swipeDown(self):
        """
        下滑
        :return:
        """
        self.implicitly_wait()
        appsize = self.get_size()
        x1 = int(appsize[0] * 0.5)
        y1 = int(appsize[1] * 0.35)
        y2 = int(appsize[1] * 0.85)
        self.driver.swipe(x1, y1, x1, y2, 1000)

    # 向右滑动屏幕 刘建培新增
    def swip_Right(self,  t=1000, n=1):
        l = self.driver.get_window_size()
        x1 = l['width'] * 0.05
        y1 = l['height'] * 0.5
        x2 = l['width'] * 0.75
        for i in range(n):
            self.driver.swipe(x1, y1, x2, y1, t)


    def swipeRight(self):
        """
        右滑
        :return:
        """
        self.implicitly_wait()
        appsize = self.get_size()
        y1 = int(appsize[1] * 0.5)
        x1 = int(appsize[0] * 0.25)
        x2 = int(appsize[0] * 0.9)
        self.driver.swipe(x1, y1, x2, y1, 1000)


    def get_driver(self):
        """
        返回当前驱动
        :return:
        """
        self.logger.info("返回当前驱动")
        self.implicitly_wait()
        return self.driver

    def press_keycode(self,nums):
        """
        调用键盘操作
        :param num:
        :return:
        """
        self.driver.press_keycode(nums)

    def page_source(self):
        """
        获取页面源码
        :return:
        """
        return self.driver.page_source

    def isElementExist(self, By, value):
        flag = True
        if By == 'xpath':
            try:
                self.driver.find_element_by_xpath(value)
            except:
                flag = False
        elif By == "id":
            try:
                self.driver.find_element_by_id(value)
            except:
                flag = False
        return flag

    def back(self):
        self.driver.back()

    def getattribut(self,driver_ele, value):
        """
        获取元素中属性
        #ele = self.driver.find_element(page_keyword, ui_keyword)
        #ele = self.driver.find_elements(page_keyword, ui_keyword)
        #ele[0].get_attribute(value)
        :return:
        """
        self.implicitly_wait()
        self.logger.info("获取元素中属性【%s】", driver_ele.get_attribute(value))
        return self.driver_ele.get_attribute(value)

    def current_activity(self):
        """
        获取当前activity
        :return:
        """
        current_activity = self.driver.current_activity
        return current_activity

    def MultiAction_add(self,action1,action2):
        """
        MultiAction多点触控操作,需要获取self.TouchAction属性方法
        :param action1: action1=TouchAction(driver) | action1.press(x=x*0.2,y=y*0.2).wait(1000).move_to(x=x*0.4,y=y*0.4).wait(1000).release()
        :param action2:
        :return:
        """
        self.multiaction = MultiAction(self.driver)
        self.multiaction.add(action1,action2)
        self.multiaction.perform()
コード例 #3
0
ファイル: baseapp.py プロジェクト: laixijun/UITest
class BaseApp:
    logger = Log().logger()

    def __init__(self, driver):
        self.driver = driver

    def implicitly_wait(self):
        time.sleep(2)
        self.driver.implicitly_wait(10)

    def getElementByElement(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        self.implicitly_wait()
        return self.driver.find_element(page_keyword, ui_keyword)

    def getElementByElements(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        self.implicitly_wait()
        return self.driver.find_elements(page_keyword, ui_keyword)

    def click(self, driver_ele):
        """
        点击方法
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        self.logger.info("点击【%s】元素", driver_ele)
        self.driver.implicitly_wait(5)
        self.highlight(driver_ele)
        driver_ele.click()

    def sendkeys(self, elements, ele_value):
        self.logger.info("通过【%s】的元素,录入信息为:【%s】", elements, ele_value)
        self.implicitly_wait()
        self.highlight(elements)
        elements.send_keys(ele_value)

    def save_img(self, img_path, time_stamp):
        """
        截图
        :img_path :图片路径
        :time_stamp: 获取时间格式
        :return:
        """
        self.implicitly_wait()
        self.driver.get_screenshot_as_file("%s/error%s.png" %
                                           (img_path, time_stamp))

    def get_text(self, driver_ele):
        """
        获取文本内容
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("获取文本内容【%s】", self.driver_ele.text)
        self.implicitly_wait()
        return self.driver_ele.text

    def get_size(self):
        """
        获取手机屏幕尺寸
        :return:
        """
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        return x, y

    def swipLeft(self):
        """
        左滑
        :return:
        """
        appsize = self.get_size()
        x1 = int(appsize[0] * 0.9)
        y1 = int(appsize[1] * 0.5)
        x2 = int(appsize[0] * 0.1)
        self.driver.swipe(x1, y1, x2, y1, 1000)

    def swipeUp(self):
        """
        上滑
        :return:
        """
        appsize = self.get_size()
        x1 = int(appsize[0] * 0.5)
        y1 = int(appsize[1] * 0.95)
        y2 = int(appsize[1] * 0.35)
        self.driver.swipe(x1, y1, x1, y2, 1000)

    def swipeDown(self):
        """
        下滑
        :return:
        """
        appsize = self.get_size()
        x1 = int(appsize[0] * 0.5)
        y1 = int(appsize[1] * 0.35)
        y2 = int(appsize[1] * 0.85)
        self.driver.swipe(x1, y1, x1, y2, 1000)

    def swipeRight(self):
        """
        右滑
        :return:
        """
        appsize = self.get_size()
        y1 = int(appsize[1] * 0.5)
        x1 = int(appsize[0] * 0.25)
        x2 = int(appsize[0] * 0.95)
        self.driver.swipe(x1, y1, x2, y1, 1000)

    def get_driver(self):
        """
        返回当前驱动
        :return:
        """
        self.logger.info("返回当前驱动")
        self.implicitly_wait()
        return self.driver
コード例 #4
0
class BasePage:
    def __init__(self,driver):
        """
        基础数据驱动封装
        :param driver:
        """
        self.driver =driver

    #日志对象
    logger = Log().logger()
##############################################################################
    """
        driver 数据基础操作
    """
    def title(self):
        """
        获取title
        :return:
        """
        self.logger.info("获取title【%s】", self.driver.title )
        self.implicitly_wait()
        time.sleep(2)
        return self.driver.title

    def implicitly_wait(self):
        time.sleep(2)
        self.driver.implicitly_wait(10)

    def getattribut(self,driver_ele, value):
        """
        获取元素中属性
        #ele = self.driver.find_element(page_keyword, ui_keyword)
        #ele = self.driver.find_elements(page_keyword, ui_keyword)
        #ele[0].get_attribute(value)
        :return:
        """
        self.implicitly_wait()
        self.logger.info("获取元素中属性【%s】", driver_ele.get_attribute(value))
        return self.driver_ele.get_attribute(value)

    def get_text(self,driver_ele):
        """
        获取文本内容
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("获取文本内容【%s】", self.driver_ele.text)
        self.implicitly_wait()
        return self.driver_ele.text

    def get_current_url(self):
        """
        获取当前url
        :return:
        """
        self.logger.info("获取当前url【%s】", self.driver.current_url)
        self.implicitly_wait()
        return self.driver.current_url

    def get_url(self, url):
        """
        打开url
        :param url:
        :return:
        """
        self.logger.info("获取当前url【%s】",url)
        self.implicitly_wait()
        return self.driver.get(url)

    def get_driver(self):
        """
        返回当前驱动
        :return:
        """
        self.logger.info("返回当前驱动")
        self.implicitly_wait()
        return self.driver

    def quit(self):
        """
        关闭浏览器以及驱动
        :return:
        """
        self.implicitly_wait()
        self.driver.quit()

    """
    高亮效果
    """
    def highlight(self,element):
        js = "arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');"#高亮显示
        try:
            self.driver.execute_script(js, element)
        except Exception as e:
            print(element+"高亮失败",EC)



    def clear(self,driver_ele):
        """
        清除文本框中的信息
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("清除文本框中的信息")
        self.implicitly_wait()
        return driver_ele.clear()

    def refresh(self):
        """
        页面刷新
        :return:
        """
        self.logger.info("页面刷新")
        self.driver.refresh()

    def getElementByElement(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        获取驱动
            ID = "id"
            XPATH = "xpath"
            LINK_TEXT = "link text"
            PARTIAL_LINK_TEXT = "partial link text"
            NAME = "name"
            TAG_NAME = "tag name"
            CLASS_NAME = "class name"
            CSS_SELECTOR = "css selector"
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        self.implicitly_wait()
        return self.driver.find_element(page_keyword,ui_keyword)

    def getElementByElements(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        获取驱动
            ID = "id"
            XPATH = "xpath"
            LINK_TEXT = "link text"
            PARTIAL_LINK_TEXT = "partial link text"
            NAME = "name"
            TAG_NAME = "tag name"
            CLASS_NAME = "class name"
            CSS_SELECTOR = "css selector"
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        # self.implicitly_wait()
        WebDriverWait(self.driver,60).until(lambda x:x.find_elements(page_keyword,ui_keyword))
        return self.driver.find_elements(page_keyword,ui_keyword)

    def click(self, driver_ele):
        """
        点击方法
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        self.logger.info("点击【%s】元素",driver_ele)
        self.driver.implicitly_wait(5)
        self.highlight(driver_ele)
        driver_ele.click()

    def sendkeys(self,elements,ele_value):
        self.logger.info("通过【%s】的元素,录入信息为:【%s】",elements, ele_value)
        self.implicitly_wait()
        self.highlight(elements)
        elements.send_keys(ele_value)

    def save_img(self,img_path,time_stamp):
        """
        截图
        :img_path :图片路径
        :time_stamp: 获取时间格式
        :return:
        """
        self.implicitly_wait()
        self.driver.get_screenshot_as_file("%s/error%s.png" %(img_path,time_stamp))

    def maximize_window(self):
        self.implicitly_wait()
        self.driver.maximize_window()

    def alert_accept(self):
        """
        操作alert弹窗
        :return:
        """
        alert = self.driver.switch_to_alert()
        alert.accept()

    def get_alert_text_and_accept(self):
        alert = self.driver.switch_to_alert()
        text = alert.text

        # alert.accept()
        return text


    def get_switch_to_frame(self,driver_ele):
        """
        :Usage:
            driver.switch_to.frame('frame_name')
            driver.switch_to.frame(1)
            driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
            driver.switch_to.parent_frame()
            driver.switch_to.window('main')
        :param driver_ele: driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("通过【%s】的元素,录入信息为:【%s】", driver_ele)
        self.driver.switch_to_frame(driver_ele)

    def get_switch_to_default_content(self):
        """
        退出iframe
        :return:
        """
        self.driver.switch_to.default_content()

    def move_to_ele(self, bys, values):
        """
        页面移到所选元素
        :return:
        """
        ele = self.driver.find_element(bys, values)
        ActionChains(self.driver).move_to_element(ele).perform()
    #############################################################
    """
    alter/confirm/prompt处理
    """
    def alter_accept(self):
        """
        接收警告信息
        :return:
        """
        alert=self.driver.switch_to_alert()
        alert.accept()

    def alter_accept_text(self):
        """
        得到文本信息打印
        :return:
        """
        alert = self.driver.switch_to_alert()
        return  alert.text()

    def alter_dismiss(self):
        """
        取消对话框
        :return:
        """
        alert = self.driver.switch_to_alert()
        alert.dismiss()

    def alter_senkeys(self,ele_text):
        """
        输入值
        :return:
        """
        alert = self.driver.switch_to_alert()
        self.logger.info("alter框输入信息:【%s】", ele_text)
        alert.send_keys(ele_text)


    ##############################################################
    """
    鼠标控件操作
    """
    def ActionChains(self,driver_ele):
        ActionChains(self.driver).move_to_element(driver_ele).perform()


    ############################################################
    """
    js处理方式
    """
    def get_js(self,js_value):
        self.logger.info("js文本内容:【%s】" %js_value)
        self.implicitly_wait()
        self.driver.execute_script(js_value)


    ########################################################
    """
    键盘输入
    """
    def keys_back_space(self,driver_ele):
        """
        传入驱动后,删除一个
        :param driver_ele: driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        driver_ele.send_keys(Keys.BACK_SPACE)
コード例 #5
0
ファイル: BasePage.py プロジェクト: 190356/autoTesting
class BasePage:
    def __init__(self, driver):
        """
        基础数据驱动封装
        :param driver:
        """
        self.driver = driver

    #日志对象
    logger = Log().logger()
    ##############################################################################
    """
        driver 数据基础操作
    """

    def title(self):
        """
        获取title
        :return:
        """
        self.logger.info("获取title【%s】", self.driver.title)
        self.implicitly_wait()
        time.sleep(2)
        return self.driver.title

    def implicitly_wait(self):
        time.sleep(2)
        self.driver.implicitly_wait(10)

    def getattribut(self, driver_ele, value):
        """
        获取元素中属性
        #ele = self.driver.find_element(page_keyword, ui_keyword)
        #ele = self.driver.find_elements(page_keyword, ui_keyword)
        #ele[0].get_attribute(value)
        :return:
        """
        self.implicitly_wait()
        self.logger.info("获取元素中属性【%s】", driver_ele.get_attribute(value))
        return self.driver_ele.get_attribute(value)

    def get_text(self, driver_ele):
        """
        获取文本内容
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("获取文本内容【%s】", self.driver_ele.text)
        self.implicitly_wait()
        return self.driver_ele.text

    def get_current_url(self):
        """
        获取当前url
        :return:
        """
        self.logger.info("获取当前url【%s】", self.driver.current_url)
        self.implicitly_wait()
        return self.driver.current_url

    def get_url(self, url):
        """
        打开url
        :param url:
        :return:
        """
        self.logger.info("获取当前url【%s】", url)
        self.implicitly_wait()
        return self.driver.get(url)

    def get_driver(self):
        """
        返回当前驱动
        :return:
        """
        self.logger.info("返回当前驱动")
        self.implicitly_wait()
        return self.driver

    def quit(self):
        """
        关闭浏览器以及驱动
        :return:
        """
        self.implicitly_wait()
        self.driver.quit()

    def clear(self, driver_ele):
        """
        清除文本框中的信息
        :param driver_ele:  driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("清除文本框中的信息")
        self.implicitly_wait()
        return driver_ele.clear()

    def refresh(self):
        """
        页面刷新
        :return:
        """
        self.logger.info("页面刷新")
        self.driver.refresh()

    def getElementByElement(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        获取驱动
            ID = "id"
            XPATH = "xpath"
            LINK_TEXT = "link text"
            PARTIAL_LINK_TEXT = "partial link text"
            NAME = "name"
            TAG_NAME = "tag name"
            CLASS_NAME = "class name"
            CSS_SELECTOR = "css selector"
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        self.implicitly_wait()
        return self.driver.find_element(page_keyword, ui_keyword)

    def getElementByElements(self, page_keyword, ui_keyword):
        """
        返回定位的单个元素
        :param page_keyword:
        :param ui_keyword:
        获取驱动
            ID = "id"
            XPATH = "xpath"
            LINK_TEXT = "link text"
            PARTIAL_LINK_TEXT = "partial link text"
            NAME = "name"
            TAG_NAME = "tag name"
            CLASS_NAME = "class name"
            CSS_SELECTOR = "css selector"
        :return:
        """
        self.logger.info("点击【%s】的【%s】元素", page_keyword, ui_keyword)
        self.implicitly_wait()
        return self.driver.find_elements(page_keyword, ui_keyword)

    def click(self, driver_ele):
        """
        点击方法
        :param page_keyword:
        :param ui_keyword:
        :return:
        """
        self.logger.info("点击【%s】元素", driver_ele)
        self.driver.implicitly_wait(5)
        driver_ele.click()

    def sendkeys(self, elements, ele_value):
        self.logger.info("通过【%s】的元素,录入信息为:【%s】", elements, ele_value)
        self.implicitly_wait()
        elements.send_keys(ele_value)

    def save_img(self, img_path, time_stamp):
        """
        截图
        :img_path :图片路径
        :time_stamp: 获取时间格式
        :return:
        """
        self.implicitly_wait()
        self.driver.get_screenshot_as_file("%s/error%s.png" %
                                           (img_path, time_stamp))

    def maximize_window(self):
        self.implicitly_wait()
        self.driver.maximize_window()

    def alert_accept(self):
        """
        操作alert弹窗
        :return:
        """
        alert = self.driver.switch_to_alert()
        alert.accept()

    def get_alert_text_and_accept(self):
        alert = self.driver.switch_to_alert()
        text = alert.text

        # alert.accept()
        return text

    def get_switch_to_frame(self, driver_ele):
        """
        :Usage:
            driver.switch_to.frame('frame_name')
            driver.switch_to.frame(1)
            driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
            driver.switch_to.parent_frame()
            driver.switch_to.window('main')
        :param driver_ele: driver_ele = self.driver.find_elements(page_keyword, ui_keyword)
        :return:
        """
        self.logger.info("通过【%s】的元素,录入信息为:【%s】", driver_ele)
        self.driver.switch_to_frame(driver_ele)

    def get_switch_to_default_content(self):
        """
        退出iframe
        :return:
        """
        self.driver.switch_to.default_content()

##############################################################

    """
    鼠标控件操作
    drag_and_drop_by_offset(source, xoffset, yoffset)  拖动到某个位置松开
    """
    def ActionChains(self, driver_ele, x_location, y_location):
        ActionChains(self.driver).move_to_element(driver_ele).perform()


############################################################

    """
    js处理方式
    """

    # def get_js(self, *js_value):
    def get_js(self, js_value):
        self.logger.info("js文本内容:【%s】" % js_value)
        self.implicitly_wait()
        self.driver.execute_script(js_value)
コード例 #6
0
 def __init__(self, driver):
     self.driver = BaseApp(driver)
     self.log = Log().logger()
コード例 #7
0
class test_Estate():
    def __init__(self, driver):
        self.driver = BaseApp(driver)
        self.log = Log().logger()

    def is_Home_page(self):
        """
            判断当前是否在首页,不在首页就重启进入首页,重启失败返回False
            :return:
        """
        flag = True
        locator = '//*[@text="我的应用"]'
        Home_page = self.driver.getElementByElement("xpath", locator)
        if Home_page:
            pass
        else:
            flag = False
        return flag

    def is_Login(self):
        """
        获取当前登录状态,未登录返回 0,登录返回 1,异常返回2
        :return:
        """
        flag = 0
        try:
            login = self.driver.isElementExist("xpath", '//*[@text="请登录/注册"]')
            if login == False:
                flag = 1
        except:
            try:
                login = self.driver.isElementExist('xpath',
                                                   '//*[@text="请登录/注册"]')
                if login == False:
                    flag = 1
            except:
                # 如果没有检测到“我的应用”字样,说明还是没有打开首页,程序异常
                flag = 2
        return flag

    def test_dev_List(self):
        """
        楼盘列表
        :return:
        """
        flag = True
        home_page = self.is_Home_page()
        if home_page:
            login_status = self.is_Login()
            self.driver.swipes(20, 500, 20, 100, 1000)
            element = self.driver.getElementByElement(
                "id", "com.easylife.house.broker:id/tvDataNewHouse"
            )  #com.easylife.house.broker.test:id/tvDataNewHouse
            self.driver.clear(element)
            time.sleep(2)
            dev_list_res = self.driver.page_source()
            if login_status:
                try:
                    assert '方案' in dev_list_res and '报备' in dev_list_res
                    self.log.info('PASS,楼盘列表数据加载正常')
                    element = self.driver.getElementByElement(
                        "xpath", '//*[@text="添加到店铺"]')
                    self.driver.click(element)
                    time.sleep(1)
                    res = self.driver.page_source()
                    if "成功添加至我的店铺" in res:
                        self.log.info('添加店铺成功')
                    else:
                        flag = False
                        self.log.error('楼盘列表添加至我的店铺失败')

                    element = self.driver.getElementByElement(
                        'xpath', '//*[@text="报备"]')
                    self.driver.click(element)
                    time.sleep(1)
                    res = self.driver.page_source()
                    if '注册用户不能报备' in res or '客户姓名' in res:
                        self.log.info('楼盘列表,点击报备,成功跳转至报备页')
                    else:
                        flag = False
                        self.log.info('楼盘列表,点击报备,没有跳转到报备页')
                except:
                    self.log.error('楼盘列表,未检测到“报备按钮”和“佣金方案”数据')
            else:
                # 未登录状态下,点击楼盘列表里的”添加到店铺”和“报备”
                element = self.driver.getElementByElement(
                    'xpath', '//*[@text="添加到店铺"]')
                self.driver.click(element)
                res = self.driver.page_source()
                if "您暂未登录,不可添加至店铺" in res:
                    self.log.info('PASS,未登录状态,不可添加至店铺')
                else:
                    flag = False
                    self.log.error('Failed,未登录状态,添加至店铺没有检测到toast提示')
                element = self.driver.getElementByElement(
                    'xpath', '//*[@text="报备"]')
                self.driver.click(element)
                locator = 'com.easylife.house.broker:id/btnLogin'
                try:
                    #WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.ID, locator)))
                    time.sleep(5)
                    self.log.info('PASS,未登录状态下,点击新房列表里的【报备】按钮,跳转到登录页')
                    self.driver.back()
                except:
                    flag = False
                    self.log.error('Failed,未登录状态下,点击新房列表里的【报备】按钮,未跳转到登录页')
        else:
            flag = False
            self.log.error('程序未成功启动首页,楼盘列表用例未能正常执行')

        assert flag == True, 'test_dev_List 楼盘列表用例执行失败'

    def test_dev_info(self):
        home_page = self.is_Home_page()  #super()
        print('home_page:', home_page)
        flag1 = True
        flag2 = True
        flag3 = True
        flag4 = True
        flag5 = True
        try:
            assert home_page == True, '当前页面不在APP首页,楼盘详情无法正常执行'
            self.driver.swipe(20, 500, 20, 100, 1000)
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/tvDataNewHouse')
            self.driver.click(element)

            time.sleep(2)
            # 搜索出霄云路8号

            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevNam')
            self.driver.click(element)
            time.sleep(1)

            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="请输入楼盘名称"]')
            self.driver.sendkeys(element, '霄云路8号')
            self.driver.press_keycode(66)
            time.sleep(2)
            dev_name = self.driver.isElementExist(
                'xpath', '//*[@text="朝阳区 | 住宅 | 建面 450-520㎡"]')
            dev_img = self.driver.isElementExist(
                'id', 'com.easylife.house.broker:id/imgHouse')
            try:
                assert dev_name and dev_img, '楼盘列表搜索霄云路8号,搜索结果里 未检测到楼盘图片或霄云路8号字段'
                # 进入楼盘详情,查看详情数据
                #self.driver.find_element_by_id('com.easylife.house.broker:id/tvHouseName').click()
                element = self.driver.getElementByElement(
                    'id', 'com.easylife.house.broker:id/tvHouseName')
                self.driver.click(element)
                # 等待元素加载完成
                # WebDriverWait(self.driver,20,0.5).until_not(lambda x: x.find_element_by_id('com.easylife.house.broker:id/progressBar').is_displayed())
                locator = '//*[@text="朝阳区霄云路8号"]'
                #WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.XPATH, locator)))
                time.sleep(5)
                # 获取楼盘详情页数据,检查是否正确
                dev_info_page1 = (('合生霄云路8号', '120000.0元/㎡', '朝阳区霄云路8号'),
                                  ('楼盘数据', '订单数'))
                dev_info_page2 = (('带客规则', '报备规则', '带看规则', '报备间隔:30分钟'),
                                  ('主力户型(2)', '5居(1)'))
                dev_info_page3 = (('楼盘动态(4)', '合生·霄云路8号450-520㎡产品在售',
                                   '合生·霄云路8号项目大户型房源在售'),
                                  ('楼盘信息', '合生', '2009-10-01', '2011-10-08',
                                   '京房售证字(2011)182号'))

                # 先检查第一屏幕里的信息是否正确
                for info in dev_info_page1:

                    for i in info:
                        ele = self.driver.isElementExist(
                            'xpath', '//*[@text="' + i + '"]')
                        try:
                            assert ele
                        except:
                            flag1 = False
                            self.log.error('Failed,楼盘详情:' + info[0] +
                                           '里未检测到元素:' + i)

                if flag1 == True:
                    self.log.info('PASS,楼盘详情页地址价格及确客制度等数据检测正常')

                # 然后滑动到第二屏幕,检查信息
                self.driver.swipe_Up()
                for info in dev_info_page2:

                    for i in info:
                        ele = self.driver.isElementExist(
                            'xpath', '//*[@text="' + i + '"]')
                        try:
                            assert ele
                        except:
                            flag2 = False
                            self.log.error('Failed,楼盘详情:' + info[0] +
                                           '里未检测到元素:' + i)

                if flag2 == True:
                    self.log.info('PASS,楼盘详情页主力户型、楼盘动态数据检测正常')

                # 然后滑动到第三屏幕,检查信息
                self.driver.swipe_Up()
                for info in dev_info_page3:
                    for i in info:
                        ele = self.driver.isElementExist(
                            'xpath', '//*[@text="' + i + '"]')
                        try:
                            assert ele
                        except:
                            flag3 = False
                            self.log.error('Failed,楼盘详情:' + info[0] +
                                           '里未检测到元素:' + i)

                if flag3 == True:
                    self.log.info('PASS,楼盘详情页楼盘信息数据检测正常')

                # 进入楼盘信息详情页,检查是否数据正确
                #self.driver.find_element_by_id('com.easylife.house.broker:id/tvMoreHouseInfo').click()
                element = self.driver.getElementByElement(
                    'id', 'com.easylife.house.broker:id/tvMoreHouseInf')
                self.driver.click(element)
                time.sleep(2)
                dev_more_info = ['京房售证字(2011)182号', '康景物业', '精装修']
                for info in dev_more_info:
                    ele = self.driver.isElementExist(
                        'xpath', '//*[@text="' + info + '"]')
                    try:
                        assert ele
                    except:
                        flag4 = False
                        self.log.error('Failed,楼盘详情【更多信息】里未检测到元素:' + info)

                if flag4 == True:
                    self.log.info('PASS,楼盘详情页【更多信息页】数据检测正常')
                self.driver.back()

                # 楼盘动态页加载检查
                #self.driver.find_element_by_id('com.easylife.house.broker:id/tvMoreDynamic').click()
                element = self.driver.getElementByElement(
                    'id', 'com.easylife.house.broker:id/tvMoreDynamic')
                self.driver.click(element)
                time.sleep(2)
                text = self.driver.page_source()
                try:
                    assert '地处燕莎商圈' in text and '合生·霄云路8号450-520㎡产品在售' in text
                except:
                    flag5 = False
                    self.log.error('Failed,楼盘动态详情页,加载数据异常')
                self.driver.back()
            except:
                assert 1 == 2
                self.log.error('未检测到楼盘图片或霄云路8号字段')

        except:
            self.log.error('楼盘详情用例未执行')

        assert flag1 == True and flag2 == True and flag3 == True and flag4 == True and flag5 == True

    def dev_commision_login(self):
        """
        登录情况下,【缦合·北京】楼盘详情页佣金方案显示,及佣金查看详情
        :return:
        """
        #self.driver.find_element_by_id('com.easylife.house.broker:id/tvDataNewHouse').click()
        element = self.driver.getElementByElement(
            'id', 'com.easylife.house.broker:id/tvDataNewHouse')
        self.driver.click(element)
        time.sleep(2)
        # self.driver.start_activity('com.easylife.house.broker', 'com.easylife.house.broker.ui.house.HouseListActivity')
        locator = 'com.easylife.house.broker:id/edSearchDevName'
        flag = True
        try:
            #WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.ID, locator)))
            time.sleep(5)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/edSearchDevName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevName')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/edSearchDevName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevName')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_xpath('//*[@text="请输入楼盘名称"]').send_keys('缦合·北京')
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="请输入楼盘名称"]')
            self.driver.sendkeys(element, '缦合·北京')
            self.driver.press_keycode(66)
            time.sleep(2)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/tvHouseName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/tvHouseName')
            self.driver.click(element)
            locator = '//*[@text="朝阳区霄云路8号"]'
            #WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.XPATH, locator)))
            time.sleep(5)
            # 先检查是否有佣金激励模块
            page_res = self.driver.page_source()
            # exist_commision = BaseApp(self.driver).isElementExist('xpath', '//*[@text="佣金激励"]')
            if '佣金激励' in page_res:
                # 获取页面数据,检查是否有佣金数据
                commision_res = self.driver.page_source()
                assert '有效期' in commision_res and '套餐' in commision_res, '登录状态下,慢合北京楼盘详情,佣金激励模块未检测到佣金方案详细数据'
                # 查看佣金详情数据
                commision_info_btn = self.driver.isElementExist(
                    'id', 'com.easylife.house.broker:id/tvDetail')
                if commision_info_btn:
                    #self.driver.find_element_by_id('com.easylife.house.broker:id/tvMoreCommission').click()
                    element = self.driver.getElementByElement(
                        'id', 'com.easylife.house.broker:id/tvMoreCommission')
                    self.driver.click(element)
                    time.sleep(3)
                    comm_cont = self.driver.page_source()
                    try:
                        assert '展开详情' in comm_cont and '有效期' in comm_cont, '佣金激励列表,未检测出数据'
                        self.log.info('PASS,楼盘详情页,佣金激励方案,更多列表加载正确')
                    except:
                        flag = False
                else:
                    flag = False
                    self.log.error('慢合北京,楼盘详情页,佣金激励模块登录后,没有查看详情按钮')
            else:
                self.log.info('缦合·北京,楼盘详情页,未检测出佣金激励模块,请查看是否存在佣金数据')

        except:
            flag = False
            self.log.error('缦合·北京楼盘详情页,佣金方案异常')
        assert flag == True

    def dev_commission_not_login(self):
        """
        未登录状态下,楼盘详情页,佣金方案展示,及登录跳转
        :return:
        """
        #self.driver.find_element_by_id('com.easylife.house.broker:id/tvDataNewHouse').click()
        element = self.driver.getElementByElement(
            'id', 'com.easylife.house.broker:id/tvDataNewHouse')
        self.driver.click(element)
        time.sleep(2)
        # self.driver.start_activity('com.easylife.house.broker', 'com.easylife.house.broker.ui.house.HouseListActivity')
        locator = 'com.easylife.house.broker:id/edSearchDevName'
        flag = True
        try:
            #WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.ID, locator)))
            time.sleep(3)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/edSearchDevName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevName')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_xpath('//*[@text="请输入楼盘名称"]').send_keys('缦合·北京')
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="请输入楼盘名称"]')
            self.driver.sendkeys(element, '缦合·北京')
            self.driver.press_keycode(66)
            time.sleep(3)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/tvHouseName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/tvHouseName')
            self.driver.click(element)
            locator = '//*[@text="朝阳区霄云路8号"]'
            #WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.XPATH, locator)))
            time.sleep(3)

            # 先检查是否有佣金激励模块
            exist_commision = self.driver.isElementExist(
                'xpath', '//*[@text="结佣规则"]')
            if exist_commision:
                login_tips = self.driver.isElementExist(
                    'xpath', '//*[@text="登录查看佣金激励,点击“立即登录”"]')
                assert login_tips, '未登录状态下,楼盘详情页,佣金激励模块,未检测到登录提示'
                self.log.info('PASS,未登录状态下,楼盘详情页,佣金激励模块显示去登录按钮')
                if login_tips:
                    # 去登录,然后检查登录后是否可以展示
                    #self.driver.find_element_by_xpath('//*[@text="登录查看佣金激励,点击“立即登录”"]').click()
                    element = self.driver.getElementByElement(
                        'xpath', '//*[@text="登录查看佣金激励,点击“立即登录”"]')
                    self.driver.click(element)
                    time.sleep(3)
                    try:
                        # 检查是否跳转到登录页面
                        login_btn = self.driver.isElementExist(
                            'id', 'com.easylife.house.broker:id/btnLogin')
                        time.sleep(4)
                        if login_btn:
                            # 输入用户名密码登录
                            #self.driver.find_element_by_xpath('//*[@text="密码登录"]').click()
                            element = self.driver.getElementByElement(
                                'xpath', '//*[@text="密码登录"]')
                            self.driver.click(element)
                            time.sleep(1)
                            #self.driver.find_element_by_id('com.easylife.house.broker:id/edphone').send_keys('18810223040')
                            element = self.driver.getElementByElement(
                                'id', 'com.easylife.house.broker:id/edphone')
                            self.driver.sendkeys(element, '18810223040')
                            #self.driver.find_element_by_id('com.easylife.house.broker:id/edPassword').send_keys('123456')
                            element = self.driver.getElementByElement(
                                'id',
                                'com.easylife.house.broker:id/edPassword')
                            self.driver.sendkeys(element, '18810223040')
                            # self.driver.find_element_by_id('com.easylife.house.broker:id/cbAgree').click() # 勾选用户服务协议,默认是勾选的,不用点击勾选了
                            #self.driver.find_element_by_id('com.easylife.house.broker:id/btnLogin').click()
                            element = self.driver.getElementByElement(
                                'id', 'com.easylife.house.broker:id/btnLogin')
                            self.driver.click(element)
                            time.sleep(1)
                            # self.driver.refresh()
                            # 由于返回的时候没有刷新页面,所以需要重新进入楼盘详情页
                            self.log.info('楼盘详情页登录成功')
                            self.driver.back()
                            #self.driver.find_element_by_id('com.easylife.house.broker:id/tvHouseName').click()
                            element = self.driver.getElementByElement(
                                'id',
                                'com.easylife.house.broker:id/tvHouseName')
                            self.driver.click(element)
                            # WebDriverWait(self.driver, 20, 0.5).until(
                            #     EC.visibility_of_element_located((By.XPATH, locator)))
                            time.sleep(5)
                            # 获取页面数据,检查是否有佣金数据
                            commision_res = self.driver.page_source()
                            assert '有效期' in commision_res and '套餐' in commision_res, '登录后,慢合北京楼盘详情,佣金激励模块未检测到佣金方案详细数据'
                            # 查看佣金详情数据
                            commision_info_btn = self.driver.isElementExist(
                                'id', 'com.easylife.house.broker:id/tvDetail')
                            if commision_info_btn:
                                #self.driver.find_element_by_id('com.easylife.house.broker:id/tvMoreCommission').click()
                                element = self.driver.getElementByElement(
                                    'id',
                                    'com.easylife.house.broker:id/tvMoreCommission'
                                )
                                self.driver.click(element)
                                time.sleep(3)
                                comm_cont = self.driver.page_source()
                                try:
                                    assert '展开详情' in comm_cont and '有效期' in comm_cont, '佣金激励列表,未检测出数据'
                                except:
                                    flag = False
                            else:
                                flag = False
                                self.log.error('慢合北京,楼盘详情页,佣金激励模块登录后,没有查看详情按钮')
                        else:
                            flag = False
                            self.log.error('慢合北京,楼盘详情页,未登录状态下,佣金激励模块未检测到登录提示')

                    except:
                        flag = False
                        self.log.error('慢合北京,楼盘详情页,通过佣金激励模块登录功能异常')

            else:
                self.log.info('缦合·北京楼盘详情页,未检测到佣金激励模块,请检查是否有佣金政策')

        except:
            flag = False
            self.log.error('缦合·北京楼盘详情页,佣金方案异常')

        assert flag == True

    def test_dev_house_info(self):
        """
        霄云路8号,户型详情
        :return:
        """
        home_page = self.is_Home_Page()
        try:
            assert home_page, '未能成功进入首页,户型详情执行失败'
            # self.driver.swipe(20, 500, 20, 100, 1000)
            # 点击新房列表
            #self.driver.find_element_by_id('com.easylife.house.broker:id/tvDataNewHouse').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/tvDataNewHouse')
            self.driver.click(element)
            time.sleep(3)
            # 搜索出霄云路8号,回车
            #self.driver.find_element_by_id('com.easylife.house.broker:id/edSearchDevName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevName')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_id('com.easylife.house.broker:id/edSearchDevName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edSearchDevName')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_xpath('//*[@text="请输入楼盘名称"]').send_keys('霄云路8号')
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="请输入楼盘名称"]')
            self.driver.sendkeys(element, '霄云路8号')
            self.driver.press_keycode(66)
            time.sleep(2)
            # 进入楼盘详情,查看详情数据
            #self.driver.find_element_by_id('com.easylife.house.broker:id/tvHouseName').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/tvHouseName')
            self.driver.click(element)
            # 等待元素加载完成
            locator = '//*[@text="朝阳区霄云路8号"]'
            #WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located((By.XPATH, locator)))
            time.sleep(5)
            self.driver.swipe_Up()
            time.sleep(1)
            #self.driver.find_element_by_xpath('//*[@text="5室3厅5卫2厨"]').click()
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="5室3厅5卫2厨"]')
            self.driver.click(element)
            time.sleep(5)
            house_page_info = self.driver.page_source()
            self.driver.swipe_Up()
            house_page_info = self.driver.page_source() + house_page_info
            page_info = [
                '住宅', '520㎡', '户型简介', '会客厅开间8.6米 2、进门双玄关处都更为宽大', '所属楼盘',
                '合生霄云路8号', '朝阳区 | 住宅 | 建面450.0-520.0㎡', '本楼盘其他户型', '4室3厅5卫1厨'
            ]
            flag = True
            for i in page_info:
                try:
                    assert i in house_page_info
                except:
                    flag = False
                    self.log.error('Failed,楼盘动态详情页,未检测到数据:' + i)

            assert flag == True, 'Failed,户型详情页数据加载异常'
            self.log.info('PASS,楼盘-户型详情,数据加载正确')

        except:
            assert 1 == 2
            self.log.error('户型详情用例执行失败')

    def test_dev_commission(self):
        login_state = self.is_Login()
        if login_state == 0:
            self.dev_commission_not_login()
        elif login_state == 1:
            self.dev_commision_login()
        else:
            # 如果登录状态为2,说明程序异常
            self.log.error('程序异常,未能测试楼盘详情佣金数据')
        assert login_state != 2, ('程序异常,未能测试楼盘详情佣金数据')

    def test_broker_store(self):
        '''
        经纪人我的店铺-移除楼盘
        :return:
        '''
        home_page = self.is_Home_Page()
        assert home_page == True, 'Faied,未能成功启动首页'
        time.sleep(3)
        #self.driver.find_element_by_xpath('//*[@text="我的店铺"]').click()
        element = self.driver.getElementByElement('xpath', '//*[@text="我的店铺"]')
        self.driver.click(element)
        time.sleep(1)
        # 判断是否跳转到登录页,跳转的话就进行登录,否则直接进行后续流程
        is_login = self.driver.isElementExist('xpath', '//*[@text="验证码登录"]')
        if is_login:
            # 输入用户名密码登录
            #self.driver.find_element_by_xpath('//*[@text="密码登录"]').click()
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="密码登录"]')
            self.driver.click(element)
            time.sleep(1)
            # self.driver.find_element_by_id('com.easylife.house.broker:id/edphone').send_keys(
            #     '18810223040')
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edphone')
            self.driver.sendkeys(element, "18810223040")
            # self.driver.find_element_by_id('com.easylife.house.broker:id/edPassword').send_keys(
            #     '123456')
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/edPassword')
            self.driver.sendkeys(element, "123456")
            # self.driver.find_element_by_id('com.easylife.house.broker:id/cbAgree').click() # 勾选用户服务协议,默认是勾选的,不用点击勾选了
            #self.driver.find_element_by_id('com.easylife.house.broker:id/btnLogin').click()
            element = self.driver.getElementByElement(
                'id', 'com.easylife.house.broker:id/btnLogin')
            self.driver.click(element)
            time.sleep(1)
            #self.driver.find_element_by_xpath('//*[@text="我的店铺"]').click()
            element = self.driver.getElementByElement('xpath',
                                                      '//*[@text="我的店铺"]')
            self.driver.click(element)
            time.sleep(2)

        # 移除所有店铺
        #res_text = self.driver.find_element_by_id('com.easylife.house.broker:id/tvMyDev').get_attribute('text')
        element = self.driver.getElementByElement(
            'id', 'com.easylife.house.broker:id/tvMyDev')
        res_text = self.driver.getattribut(element, 'text')

        num = re.sub(r'\D', '', res_text)
        if num == '':
            self.log.info('PASS,我的店铺里没有收藏的店铺')
        else:
            for i in range(0, int(num)):
                #self.driver.find_element_by_xpath('//*[@text="移除店铺"]').click()
                element = self.driver.getElementByElement(
                    'xpath', '//*[@text="移除店铺"]')
                self.driver.click(element)
                time.sleep(2)
                #self.driver.find_element_by_xpath('//*[@text="确定"]').click()
                element = self.driver.getElementByElement(
                    'xpath', '//*[@text="确定"]')
                self.driver.click(element)
                time.sleep(2)
            self.log.info('PASS,成功移除店铺内所有楼盘')
コード例 #8
0
class TestCase(unittest.TestCase):
    """
    全局变量中将excel中首行标题提取:testdata2 , yaml数据返回结果:datainfo
    新脚本中配置新的excel需要改写内容如下 :对应新的配置文件信息
    global:全局变量
     file_path = SystemOs().sys_path(datainfo['file_path2'])
    testdata = xlsxoper(file_path).readerXLS_dict(datainfo['SheetName2'])[0]  # 数据用于ddt使用
    testdata2 = xlsxoper(file_path).readerXLS_dict(datainfo['SheetName2'])[1]  # 首行标题

    def:
    执行脚本对应的excel写入sheet
    xls = xlsxoper(file_path).writeXLS_dict(datas['caseNo'],column,str(responseData),datainfo['SheetName2'])

    """
    global log, file_path, datainfo, testdata2
    log = Log().logger()
    conf = Config("ConfigApi")
    keys = conf.parsing_config("public_data")
    public_data = SystemOs().sys_path(keys)  #通过主配置文件config获取主yaml配置文件路径-
    datainfo = yamlUtil(public_data).get_yalm()
    file_path = SystemOs().sys_path(datainfo['file_path2'])
    testdata = xlsxoper(file_path).readerXLS_dict(
        datainfo['SheetName2'])[0]  # 数据用于ddt使用
    testdata2 = xlsxoper(file_path).readerXLS_dict(
        datainfo['SheetName2'])[1]  # 首行标题

    #*testdata 只获取数据
    @data(*testdata)
    def test_01_demo(self, datas):
        """
        接口测试
        :param datas: 从yaml文件中获取excel路径,读取数据集,通过ddt形式
        """

        isSkip = datas['isSkip']  #获取excle中isSkip
        if isSkip == 'y':
            log.info("当isSkip==y跳过此条用例")
        else:
            #print("datas:",datas)
            webapp = datas['setApp']
            setApp = datainfo[webapp]  #获取excel中设备类型setApp是网页还是手机
            log.info('setApp: %s ', setApp)
            setpath = SystemOs().sys_path(
                setApp
            )  #获取yaml子配置文件路径信息如:C:/Users/vivid/PycharmProjects/untitled/DestroyerRobot/yaml_file/header_cms.yaml
            header = yamlUtil(setpath).get_yalm()  #获取header信息
            url = datainfo[datas['domain']] + datas['requestUrl']
            #"请求方式= %s",datas['method'],"请求参数= %s",datas['param'] "请求格式= %s",datas['paramType'],"请求头部信息= %s",header
            log.info("请求地址= %s ", url)
            # log.info("请求方式= %s",datas['method'])
            # log.info("请求格式= %s",datas['paramType'])
            # log.info("请求头部信息= %s",header)
            responseData = HttpClient().request(datas['method'], url,
                                                datas['paramType'],
                                                datas['param'], header)  #实际结果
            log.info("实际响应结果:%s", responseData)
            responseResult = CheckResult.check(responseData,
                                               datas["exceptResponse"])
            log.info("判断预期结果与实际结果是否一致:0 为 False 1 为 True = %s ",
                     responseResult)
            # 判断是否将token写入yaml对应的文件中
            stort_token(responseData, webapp, setpath, responseResult,
                        datas['istoken'], datainfo['token'],
                        datainfo['Authorization']).token()
            #查找CASE_trueResponse中value值对应excel的列位置
            column = testdata2.index(datainfo['CASE_trueResponse'])
            # 写入excel中
            log.info("将实际响应结果集数据写入excel中对应列")
            #写入excel数据必须是字符串,不能是dict
            xls = xlsxoper(file_path).writeXLS_dict(datas['caseNo'], column,
                                                    str(responseData),
                                                    datainfo['SheetName2'])
            time.sleep(1)
コード例 #9
0
class stort_token:
    """
    stort_token只是为了满足权限系统而作
    """

    def __init__(self,responseData,setApp,setpath,responseResult,istoken,token_value,Authorization):
        self.responseData = responseData
        self.istoken = istoken
        self.setpath = setpath
        self.setApp = setApp
        self.responseResult = responseResult
        self.tokenvalue =token_value
        self.Authorization = Authorization
        self.log = Log().logger()

    def token(self):
        #print(self.responseData,"\n\t",self.istoken ,"\n\t",self.setpath ,"\n\t", self.setApp ,"\n\t" ,self.responseResult ,"\n\t",self.tokenvalue ,"\n\t",self.Authorization )
        if self.istoken :
            if self.responseResult :
                if "data" in self.responseData.keys():
                    if self.responseData["data"] == None:
                        self.log.info("data层为null")
                    else:
                        if self.tokenvalue  in self.responseData['data'].keys():
                            reToken = self.responseData["data"][self.tokenvalue]
                            #在权限系统中生成"Bearer "+applicationToken 对应Authorization
                            reAuthorization = "Bearer "+self.responseData["data"]["applicationToken"]
                            self.log.info("reToken:%s" % reToken)
                            if self.setApp == 1 :
                                data = yamlUtil(self.setpath).get_yalm()
                                if self.tokenvalue in data.keys():
                                    yamlUtil(self.setpath).update_yaml(self.tokenvalue,reToken)
                                else:
                                    Token = {self.tokenvalue: reToken}
                                    yamlUtil(self.setpath).write_yaml(Token)
                                if self.Authorization in data.keys():
                                    yamlUtil(self.setpath).update_yaml(self.Authorization,reAuthorization)
                                else:
                                    Authorization = {self.Authorization: reAuthorization}
                                    yamlUtil(self.setpath).write_yaml(Authorization)
                            elif self.setApp == 2 :
                                data = yamlUtil(self.setpath).get_yalm()
                                if self.tokenvalue in data.keys():
                                    yamlUtil(self.setpath).update_yaml(self.tokenvalue,reToken)
                                else:
                                    reToken = {self.tokenvalue :  reToken}
                                    yamlUtil(self.setpath).write_yaml(reToken)
                        else:
                            self.log.info("登录没有返回token")
                else:
                    self.log.info("response没有data层")
            else:
                self.log.info("登录失败" )
        else:
            self.log.info("不是登录")