Exemple #1
0
 def check_channel_option(self, channel_name):
     # 获取区域元素的所在位置
     area_element = self.index_page.find_channel_area()
     x = area_element.location["x"]
     y = area_element.location["y"]
     # 获取区域元素大小
     w = area_element.size["width"]
     h = area_element.size["height"]
     # 计算其实按住的滑动坐标
     start_x = x + h * 0.5
     start_y = y + w * 0.8
     # 计算目标的坐标
     end_x = start_x
     end_y = y + w * 0.2
     while True:
         # 先获取一次界面信息
         page_old = DriverUtils.get_app_driver().page_source
         # 在当前区域中查找我们所想选择的频道元素对象
         try:
             # 如果能找到就点击
             self.index_page.find_channel_option(channel_name).click()
             break
         # 如果找不到就再次滑动
         except Exception as e:
             DriverUtils.get_app_driver().swipe(start_x, start_y, end_x,
                                                end_y)
             # 在获取一次界面信息和滑动前的相等
             page_new = DriverUtils.get_app_driver().page_source
             if page_new == page_old:
                 raise NoSuchElementException("没有找到{}的频道")
    def check_channel_option(self, channel_name):
        # 获取区域范围
        area = self.home_page.find_channel_area()
        x = area.location["x"]
        y = area.location["y"]

        w = area.size["width"]
        h = area.size["height"]

        start_x = x + w * 0.75
        start_y = y + h * 0.5

        end_x = x + w * 0.25
        end_y = start_y

        # 在当前区域根据频道的名称来查找对应元素
        while True:
            # 获取当前页面信息
            page_old = DriverUtils.get_app_driver().page_source
            # 如果找到元素则点击
            try:
                self.home_page.find_channe_option(channel_name).click()
                break
            # 如果没有找则进行滑动
            except Exception as e:
                DriverUtils.get_app_driver().swipe(start_x, start_y, end_x,
                                                   end_y, 500)
                # 获取滑动之后的页面信息
                page_new = DriverUtils.get_app_driver().page_source
                # 判断滑动之前和滑动之后的页面信息是否相等
                if page_old == page_new:
                    raise NoSuchElementException(
                        "not find {} channel".format(channel_name))
Exemple #3
0
 def check_channel_option(self, channel_name):
     # 获取区域元素的所在位置
     area_element = self.index_page.find_channel_area()
     x = area_element.location["x"]
     y = area_element.location["y"]
     # 获取区域元素的大小
     w = area_element.size["width"]
     h = area_element.size["height"]
     # 计算起始按住的滑动点坐标
     star_y = y + h * 0.5
     star_x = x + w * 0.8
     # 计算目标位置的坐标
     end_y = star_y
     end_x = x + w * 0.2
     while True:
         # 先获取一次界面信息
         page_old = DriverUtils.get_app_driver().page_source
         # 在当前区域中查找所选择的频道元素对象
         try:
             # 如果能找到则点击
             self.index_page.find_channel_option(channel_name).click()
             break
             # 找不到则再次滑动页面
         except Exception as e:
             DriverUtils.get_app_driver().swipe(star_x, star_y, end_x, end_y, 3000)
             # 再获取一次界面信息和滑动前的相等
             page_new = DriverUtils.get_app_driver().page_source
             # 如果滑动之后的页面信息和滑动之前的相等则抛出异常没找到目标的选项
             if page_new == page_old:
                 raise NoSuchElementException("没有找{}的频道")
Exemple #4
0
    def check_channel_option(self, channel_name):
        # 获取区域元素的所在位置
        area_element = self.index_page.find_channel_area()
        x = area_element.location["x"]
        y = area_element.location["y"]
        # 获取区域元素的大小
        w = area_element.size["width"]
        h = area_element.size["height"]
        # 计算起始按住的滑动坐标
        start_x = x + w * 0.8
        start_y = y + h * 0.5
        # 计算目标位置的坐标
        end_x = x + w * 0.2
        end_y = start_y

        while True:
            # 先获取一次界面信息
            page_old = DriverUtils.get_app_driver().page_source
            # 在当前区域中查找我们所想选择的频道元素
            try:
                # 如果能找到则点击
                self.index_page.find_channel_option(channel_name).click()
                # 退出循环
                break
            # 找不到想选择的频道元素再次滑动页面
            except Exception as e:
                DriverUtils.get_app_driver().swipe(start_x, start_y, end_x,
                                                   end_y)
                # 再次获取一次界面信息和滑动前的相等
                page_new = DriverUtils.get_app_driver().page_source
                # 滑动前后页面信息相等则抛出异常没有找到目标的选项
                if page_new == page_old:
                    raise NoSuchElementException("没有找到{}的频道")
Exemple #5
0
 def choose_channel_option(self, channel_name):
     # 获取区域元素的所在位置
     area_element = self.index_page.find_channel_area()
     x = area_element.location["x"]
     y = area_element.location["y"]
     # 获取区域元素的大小
     w = area_element.size["width"]
     h = area_element.size["height"]
     # 计算起始按住的滑动点坐标
     start_x = x + w * 0.8
     start_y = y + h * 0.5
     # 计算目标位置的坐标
     end_x = x + w * 0.2
     end_y = start_y
     while True:
         # 先获取一次界面信息
         page_before = DriverUtils.get_app_driver().page_source
         # 当前区域中查找我们所想选择的频道元素对象
         try:
             # 如果能找到则点击
             self.index_page.find_channel_option(channel_name).click()
             break
         # 如果找不到则再次滑动页面
         except Exception as e:
             DriverUtils.get_app_driver().swipe(start_x, start_y, end_x,
                                                end_y)
             # 再获取一次界面信息和滑动前相等
             page_after = DriverUtils.get_app_driver().page_source
             if page_after == page_before:
                 raise NoSuchElementException(f"没有所需要的元素{channel_name}")
    def check_channel(self, channel_name):
        # 获取滑动区域
        area = self.index_page.find_channel_area()
        x = area.location["x"]
        y = area.location["y"]

        w = area.size["width"]
        h = area.size["height"]

        start_x = x + w * 0.75
        start_y = y + h * 0.5

        end_x = x + w * 0.25
        end_y = start_y
        # 在区域内中去具体某个频道
        while True:
            # 在获取元素之前先获取一下当前页面的所有信息
            page_old = self.driver.page_source
            try:
                # 如找到目标频道则点击
                self.index_page.find_channel_option(channel_name).click()
                break
            except Exception as e:
                # 如没有找到目标频道则滑动
                DriverUtils.get_app_driver().swipe(start_x, start_y, end_x,
                                                   end_y)

                # 滑动到最后也没有找到目标频道则抛出异常
                # 再获取当前页面所有信息和滑动之前的进行对比如相当于则表示滑动到最后
                if page_old == self.driver.page_source:
                    raise NoSuchElementException
Exemple #7
0
    def setUpClass(cls):
        # 获取APP驱动对象
        cls.driver = DriverUtils.get_app_driver()
        # 创建首页业务层对象
        cls.index_proxy = IndexProxy()

        def setUp(self):
            self.driver.start_activity("com.itcast.toutiaoApp",
                                       ".MainActivity")
Exemple #8
0
 def find_channel_option(self, option_name):
     # self.channel_option[1].format(option_name)
     # return self.find_elt(self.channel_option)
     return DriverUtils.get_app_driver().find_element(
         self.channel_option[0], self.channel_option[1].format(option_name))
Exemple #9
0
 def find_channel_option(self, channel_name):
     return DriverUtils.get_app_driver().find_element(
         self.channel_option[0],
         self.channel_option[1].format(channel_name))
 def __init__(self):
     self.driver = DriverUtils.get_app_driver()
Exemple #11
0
 def setup_class(self):
     self.driver = DriverUtils.get_app_driver()
     self.index_proxy = IndexProxy()
Exemple #12
0
 def __init__(self):
     self.index_page = IndexPage()
     self.driver = DriverUtils.get_app_driver()
 def to_window(self, n):
     handles = DriverUtils.get_app_driver().window_handles
     DriverUtils.get_app_driver().switch_to.window(handles[n])
Exemple #14
0
 def setUpClass(cls):
     cls.driver = DriverUtils.get_app_driver()
     cls.index_proxy = IndexProxy()
 def setUpClass(cls):
     # 获取app驱动对象
     cls.driver = DriverUtils.get_app_driver()
     # 创建首页业务层对象
     cls.index_proxy = IndexProxy()
 def setup_class(self):
     self.driver = DriverUtils.get_app_driver()
     self.home_proxy = HomeProxy()
 def __init__(self):
     # 获取浏览器驱动对象
     self.driver = DriverUtils.get_app_driver()