Esempio n. 1
0
class MiniProgramComponentPage(WXMPPage):
    '''微信官方小程序示例主页面
    '''
    ui_map = {
        '视图容器区域': {
            'type': WebElement,
            'locator': XPath('//wx-view[@class="kind-list-item"][1]'),
            'ui_map': {
                '标题': XPath('//*[@id="view"]'),
                'view': XPath('//*[text()="view"]'),
                'scroll-view': XPath('//*[text()="scroll-view"]')
            }
        },
        '组件分类': {
            'type': ui_list(WebElement),
            'locator': XPath('//wx-view[@class="kind-list-item"]'),
            'ui_map': {
                '标题': XPath('//wx-view[@class="kind-list-text"]'),
                '组件列表': {
                    'type': ui_list(WebElement),
                    'locator': XPath('//wx-navigator[@class="navigator"]'),
                    'ui_map': {
                        '名称': XPath('/wx-view[@class="navigator-text"]')
                    }
                }
            }
        }
     }


    def open_component_page(self, category, name):
        '''打开组件页面
        '''
        for cat in self.control('组件分类'):
            if cat.control('标题').inner_text == category:
                rect1 = cat.rect
                rect2 = cat.control('标题').rect
                if rect1[3] - rect2[3] < 200:
                    # 需要展开
                    cat.click()
                for comp in cat.control('组件列表'):
                    if comp.control('名称').inner_text == name:
                        comp.click()
                        return
                else:
                    raise RuntimeError('Find component %s failed' % name)
        else:
            raise RuntimeError('Find component type %s failed' % category)
Esempio n. 2
0
class MiniProgramSearchPage(WebPage):
    '''小程序搜索结果页面
    '''
    ui_map = {'推荐搜索列表': {'type': ui_list(WebElement),
                         'locator': XPath('//div[@class="sug_wrp"]/div[@class="weui_cells"]/div[@class="weui_cell"]'),
                         'ui_map': {
        '小程序名': XPath('//p[@class="sug_text"]')
    }
    },
        '使用过的小程序列表': {'type': ui_list(WebElement),
                      'locator': XPath('//div[@class="weui_cells"]/div[@class="weui_cell search_item sug_biz"]'),
                      'ui_map': {'小程序名': XPath('//em[@class="highlight"]')
                                 }
                      },
        '搜索历史列表': {
        'type': ui_list(WebElement),
        'locator': XPath('//div[@class="history_page"]/div[@class="weui_cells"]'),
        'ui_map': {
            '小程序名': XPath('//p[@class="history_text"]')
        }
    },
        '小程序列表': {'type': ui_list(WebElement),
                  'locator': XPath('//ul[@class="search_list"]/div/li'),
                  'ui_map': {'小程序名': XPath('//h3[@class="search_item_title"]/em[@class="highlight"]')
                             }
                  }
    }

    def open_app(self, app_name):
        '''进入小程序
        '''
        # time.sleep(1)
        if len(self.control('推荐搜索列表')) > 0:
            for it in self.control('推荐搜索列表'):
                if it.control('小程序名').inner_text.upper() == app_name.upper():
                    it.click()
                    break
        elif len(self.control('搜索历史列表')) > 0:
            for it in self.control('搜索历史列表'):
                if it.control('小程序名').inner_text.upper() == app_name.upper():
                    it.click()
                    break

        timeout = 5
        time0 = time.time()
        while time.time() - time0 < timeout:
            if len(self.control('小程序列表')) > 0:
                break
            time.sleep(0.2)
        else:
            raise RuntimeError('未搜索到小程序')

        for it in self.control('小程序列表'):
            if it.control('小程序名').inner_text.upper() == app_name.upper():
                it.click()
                return
        else:
            raise RuntimeError('小程序:%s 不存在' % app_name)

        for it in self.control('使用过的小程序列表'):
            if it.control('小程序名').inner_text.upper() == app_name.upper():
                it.click()
                return
        else:
            raise RuntimeError('搜索结果中未找到小程序:%s' % app_name)
Esempio n. 3
0
 def get_uilist(self):
     test = TestElement()
     return ui_list(TestElement)(test, "//div[id@='test']")