如何使用拉力赛API获取测试用例名称

时间:2014-05-02 20:13:57

标签: python html rally mako pyral

我正在尝试编写一个循环,它将返回一个包含测试集和测试用例的表。但是,我无法获得测试用例的名称,但是反弹会返回“对象ID(OID)。代码为

_M_writer(u'</p>\r\n<table  class="objects" style="width: 60%">\r\n\t\t<tr>\r\n\t\t\t<th>TestSets</td>\r\n\t\t\t<th>TestCases</th>\r\n\t\t</tr>\r\n')

        for ts in testSets:

                __M_writer(u'\t\t\t\t')
                tc = ts.TestCases


                if tc:

                    __M_writer(u'<tr>')
                    __M_writer(u'<td>')
                    __M_writer(unicode(ts.FormattedID))
                    __M_writer(u'\t\t\t\t</td>')

                    __M_writer(u'<td>')

                    __M_writer(filters.html_escape(unicode(tc.FormattedID)))
                    __M_writer(u'</td>')

                __M_writer(u'</tr>\r\n')
                pass

        __M_writer(u'</table>\n')

tc.FormattedID给了我一个属性错误。见下文

 print >> fh, template.render(**workContext)

  File "C:\Python27\lib\site-packages\mako\template.py", line 397, in render
    return runtime._render(self, self.callable_, args, data)

  File "C:\Python27\lib\site-packages\mako\runtime.py", line 764, in _render
    **_kwargs_for_callable(callable_, data))

  File "C:\Python27\lib\site-packages\mako\runtime.py", line 796, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)

  File "C:\Python27\lib\site-packages\mako\runtime.py", line 822, in _exec_template
    callable_(context, *args, **kwargs)

  File "C:\Users\xxx\Documents\xx\tools\xxx\tmp\audit.base.html.py", line 130,               in render_body

    context['self'].content(**pageargs)
  File "C:\Users\xxx\Documents\TOOLS_WS\tools\xxxx\tmp\Validation Test Plan.html.py",               line 171, in render_content
    __M_writer(filters.html_escape(unicode(tc.FormattedID)))
AttributeError: 'list' object has no attribute 'FormattedID'

请帮忙。感谢

2 个答案:

答案 0 :(得分:2)

碰巧我错过了'for loop in my code: ts.TestCases`正在返回一个测试用例列表而不是一个测试用例。

更正后的代码如下:

__M_writer(u'</p>\r\n<table  class="objects" style="width: 60%">\r\n\t\t<tr>\r\n\t\t\t<th>TestSets</td>\r\n\t\t\t<th>TestCases</th>\r\n\t\t</tr>\r\n')

    for ts in testSets:

            __M_writer(u'\t\t\t\t')
            testCaseObjectList = ts.TestCases
            for tc in testCaseObjectList:
                if tc:
                     __M_writer(u'<tr>')
                     __M_writer(u'<td>')
                     __M_writer(unicode(ts.FormattedID))
                     __M_writer(u'\t\t\t\t</td>')
                     __M_writer(u'<td>')
                     __M_writer(filters.html_escape(unicode(tc.FormattedID)))
                     __M_writer(u'</td>')
                     __M_writer(u'</tr>\r\n')
                pass

     __M_writer(u'</table>\n')

干杯。

答案 1 :(得分:0)

这不是特定于Python的,但必须明确获取Name以获取它。尝试使用tc._refObjectName。无需提取_refObjectName,它与名称相同。