Exemplo n.º 1
0
def wait_for_node_visible(poco,
                          str_node,
                          timeout=1,
                          clickable=False,
                          logout=False):
    if logout:
        out('wait: ' + str_node)

    f_exit = False
    while not f_exit:
        # poco = UnityPoco()
        with poco.freeze() as frozen_poco:
            node = get_node_quick(frozen_poco, str_node, False)
            if node.exists():
                if node.attr('visible'):
                    if clickable:
                        if node.attr('clickable'):
                            f_exit = True
                    else:
                        f_exit = True

        if not f_exit:
            time.sleep(1)
            timeout = timeout - 1
            if (timeout < 1):
                if logout:
                    log(
                        'Node \'' + str_node +
                        '\' is not visible, exit for timeout', get_trace())
                return node
        else:
            if logout:
                out('wait return: ' + str_node)
            return node
    def test(self):
        # 指定登录数据集
        g().group = '商城测试案例003'
        # 构造数据
        userName = g().get_test_data("用户名")
        vagueUserName = g().get_test_data("模糊用户名")
        loginPwd = g().get_test_data("密码")
        goodName = g().get_test_data("商品名称")

        # 构造断言数据
        assertDict = {
            "去逛逛页面跳转成功": '''
                               #断言去逛逛页面跳转成功
                               self.assert_ui_exists(g().get_resource_infor('商品详情页加入购物车按钮'),"断言去逛逛页面跳转成功")
                            '''
        }

        #运行流程
        log('登录手机银行')
        Login().login(userName, vagueUserName, loginPwd)
        time.sleep(2)
        Mall().getIntoGoodsDetail(goodName, assertDict=assertDict)  #搜索商城商品并进入商品详情页面
        time.sleep(2)
        Mall().checkMessageInGoodsDetail(assertDict=assertDict)   #检验商品详情页面消息按钮
        time.sleep(2)
        Mall().checkSearchInGoodsDetail(assertDict=assertDict)    #检验商品详情页面搜索按钮
        time.sleep(2)
        Mall().checkHomepageInGoodsDetail(assertDict=assertDict)  #检验商品详情页面首页按钮
Exemplo n.º 3
0
    def test(self):
        # 指定测试数据集
        g().group = '商城测试案例002'
        # 构造数据
        userName = g().get_test_data("用户名")
        vagueUserName = g().get_test_data("模糊用户名")
        loginPwd = g().get_test_data("密码")
        goodName = g().get_test_data("商品名称")

        # 构造断言数据
        assertDict1 = {
            "断言登录成功":
            '''
                        #登录成功断言
                        self.assert_ui_exists(g().get_resource_infor('我的页面设置按钮'),"断言登录成功")
                    ''',
            "断言搜索商品成功":
            '''
                        #断言搜索商品是否成功
                        self.assert_ui_exists(g().get_resource_infor('搜索有结果'),"断言搜索商品成功")
                    '''
        }

        #运行流程
        log('登录手机银行')
        Login().login(userName, vagueUserName, loginPwd)
        Mall().searchGoods(goodName, assertDict=assertDict2)  #搜索商城商品
Exemplo n.º 4
0
 def runTest(self):
     log("main_script", {"script": self.args.script})
     scriptpath = self.args.script
     pyfilename = os.path.basename(scriptpath).replace(self.SCRIPTEXT, ".py")
     pyfilepath = os.path.join(scriptpath, pyfilename)
     code = open(pyfilepath).read()
     exec(compile(code, pyfilepath.encode(sys.getfilesystemencoding()), 'exec')) in self.scope
Exemplo n.º 5
0
def print_attr(node, write_to_log=False):
    if not node.exists():
        e = get_trace()
        print('node not exists...\n' + e)
        log('node not exists...', e)
        return

    var_str = 'name: ' + node.attr('name') + '; '
    var_str = var_str + 'type: ' + node.attr('type') + '; '

    var_str = var_str + 'visible: '
    if node.attr('visible'): var_str = var_str + 'True; '
    else: var_str = var_str + 'False; '

    var_str = var_str + 'clickable: '
    if node.attr('clickable'): var_str = var_str + 'True; '
    else: var_str = var_str + 'False; '

    # _lst = node.attr('components')
    # if len(_lst) >= 0:
    #    var_str = var_str + 'components: ['
    #    first = True
    #    for component in _lst:
    #        if not first: var_str = var_str + ', '
    #        first = False
    #        var_str = var_str + component
    #    var_str = var_str + ']; '

    print(var_str)
    if (write_to_log):
        log(var_str)
Exemplo n.º 6
0
 def poco_exists(self, **kwargs):
     """
     测试UI元素是否在层次结构中
     :param kwargs: [text,name]
     """
     result = self.poco_freeze(**kwargs).exists()
     log("元素{}验证结果: {}".format(kwargs, result))
     return result
Exemplo n.º 7
0
 def log(self,message, traceback=""):
     '''
     输出文字到报告
     :param message: log message
     :param traceback: log traceback if exists, use traceback.format_exc to get best format
     :return:
     '''
     log(message,traceback)
Exemplo n.º 8
0
 def poco_text(self, **kwargs):
     """
     获取 UI 元素的文本属性。如果没有此类属性,则返回"无"。
     :param kwargs:
     :return: txt
     """
     txt = self.poco_obj(**kwargs).get_text()
     log("获取元素{}文本:{}".format(kwargs, txt))
     return txt
Exemplo n.º 9
0
 def runTest(self):
     log("main_script", {"script": self.args.script})
     scriptpath = self.args.script
     pyfilename = os.path.basename(scriptpath).replace(self.SCRIPTEXT, ".py")
     pyfilepath = os.path.join(scriptpath, pyfilename)
     pyfilepath = os.path.abspath(pyfilepath)
     self.scope["__file__"] = pyfilepath
     with open(pyfilepath, 'r', encoding="utf8") as f:
         code = f.read()
     exec(compile(code.encode("utf-8"), pyfilepath.encode(sys.getfilesystemencoding()), 'exec')) in self.scope
Exemplo n.º 10
0
 def poco_click(self, **kwargs):
     """
     对由UI代理表示的UI元素执行click操作。如果这个UI代理代表一组
     UI元素,单击集合中的第一个元素,并将UI元素的定位点用作默认值
     一个。还可以通过提供“focus”参数单击另一个点偏移。
     :param kwargs: [text, name]
     """
     log("点击元素:{}".format(kwargs))
     self.poco_obj(**kwargs).click()
     self.poco.sleep_for_polling_interval()
Exemplo n.º 11
0
    def setUp(self):
        if self.args.log and self.args.recording:
            for dev in G.DEVICE_LIST:
                try:
                    dev.start_recording()
                except:
                    traceback.print_exc()

        if self.args.pre:
            log("pre_script", {"script": self.args.pre})
            self.exec_other_script(self.args.pre)
Exemplo n.º 12
0
 def report_html(*args, **kwargs):
     init_reportdir()
     # fun执行失败将写入日志,并标记用例执行失败
     try:
         fun(*args, **kwargs)
     except Exception as err:
         tb = traceback.format_exc()
         log("异常错误", tb)
         six.reraise(*sys.exc_info())
     finally:
         pass
         post_action(caseName)
Exemplo n.º 13
0
    def tearDown(self):
        if self.args.log and self.args.recording:
            for k, dev in enumerate(G.DEVICE_LIST):
                try:
                    output = os.path.join(self.args.log, "recording_%d.mp4" % k)
                    dev.stop_recording(output)
                except:
                    traceback.print_exc()

        if self.args.post:
            log("post_script", {"script": self.args.post})
            self.exec_other_script(self.args.post)
Exemplo n.º 14
0
    def test(self):
        # 构造断言数据
        assertDict = {
            "进入消息页面成功":
            '''
                                self.assert_ui_exists(g().get_resource_infor('消息页面'),"断言进入消息页面成功")
                            '''
        }

        # 运行流程
        log("从购物车进入消息中心")
        Mall().enterShoppingCart(assertDict=assertDict)  # 从购物车进入消息页面
        Mall().back()  #返回到商城界面
Exemplo n.º 15
0
def hyper_assert(condition, assert_content):
    """
    @Pramas1:  condition
    @Pramas2:  assert_content
    @Return  Void But it will Snapshot the device screen
    """
    print(condition)
    try:
        assert condition, assert_content
        snapshot(msg=assert_content)
        log(assert_content, None)
    except:
        import traceback
        snapshot(msg=assert_content + "-未找到")
        log('', traceback.format_exc())
Exemplo n.º 16
0
    def test(self):
        # 指定数据集
        g().group = '搜索商城商品名称'
        # 构造数据
        goodName = g().get_test_data("商品名称")

        # 构造断言数据
        assertDict = {
            "断言搜索商品成功": '''
                        #断言搜索商品是否成功
                        self.assert_ui_exists(g().get_resource_infor('搜索商品成功商品列表综合按钮'),"通过分类搜索商品成功")
                    '''
        }

        # 运行流程
        log('按终极分类搜索商品')
        Mall().classificationEnquiry(assertDict=assertDict)  #按终极分类搜索商品
Exemplo n.º 17
0
    def test(self):
        # 指定数据集
        g().group = '商城UI自动化测试账号2'
        # 构造数据
        userName = g().get_test_data("用户名")
        vagueUserName = g().get_test_data("模糊用户名")
        loginPwd = g().get_test_data("密码")

        # 构造断言数据
        assertDict = {
            "断言登录成功":
            '''
                #登录成功断言
                self.assert_ui_exists(g().get_resource_infor('我的页面设置按钮'),"断言登录成功")
            '''
        }

        # 运行流程
        log('登录手机银行')
        Login().login(userName, vagueUserName, loginPwd, assertDict=assertDict)
Exemplo n.º 18
0
def out(s, str_trace=''):
    print(s, str_trace)
    log(s, str_trace)