Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

How to add the section name to the Push defect plugin


#1

I am trying to figure out how we can append a test suite section name (or any nested level of section names) to our Fogbugz push defect plugin.
I’ve read the document:
http://docs.gurock.com/testrail-integration/defects-plugins-custom
The section on the $context argument doesn’t seem to list any higher level section information about the current test, but maybe I am missing something?

As an example:
We have a Test Suite section name “608CC Suite” and a test case “abc test”.
When we log a bug using the push feature, we want the default bug tracker title to be:
“Failed Test - 608CC Suite: abc test”

currently I use the following in our push method:
$title = 'Failed Test - ’ . current($context[‘tests’])->case->title;

but that only gets me
"Failed Test - abc test"

Is there any way to get the section name from the $context argument?

Regards,
Daniel


#2

Hello Daniel,

Thanks for your posting. Sections are currently not part of the $context argument. I’ve just added this to our feature request list. That said, it would also be possible to read the sections from the database via custom code by getting the section ID/name and any parent sections via the case ID. If you are interested in this, I can suggest the best ways to implement this.

Regards,
Tobias


#3

Hi Tobias,

I would be interested in learning how to do this.

Thanks!
Daniel


#4

Hello Daniel,

Sure, no problem. I will prepare a small example and will post it later today/tomorrow.

Regards,
Tobias


#5

Hello Daniel,

The following code should do the trick:

[code]private function _get_sections_by_case_id($case_id)
{
$db = dbpool::get_default();
$case = $db->by_id(‘cases’, $case_id);

if (!$case)
{
    return null;
}

$sections = array();
$section_id = $case->section_id;

while ($section_id != null)
{
    $section = $db->by_id('sections', $section_id);
    if (!$section)
    {
        break;
    }

    $sections[] = $section;
    $section_id = $section->parent_id; // One level up
}

return $sections;

}

private function _get_title_default($context)
{
$test = current($context[‘tests’]);
$sections = $this->_get_sections_by_case_id($test->case_id);

$title = '';
if ($sections)
{
    foreach ($sections as $section)
    {
        if ($title)
        {
            $title = ' > ' . $title;
        }

        $title = $section->name . $title;
    }
}

$title = "Failed Test - $title: " . $test->case->title;

if ($context['test_count'] > 1)
{
    $title .= ' (+others)';
}

return $title;

}[/code]

Just replace the standard _get_title_default with these two methods above and the dialog should now also include the section hierarchy.

I hope this helps. Just let me know in case you have any questions.

Regards,
Tobias


#6

That’s just what we needed; plus, I learned a little about how to get information from the database, which could be useful in the future.

Thanks so much Tobias!

Best Regards,
Daniel


#7

You are welcome. Just let me know in case you have any further questions and have a good weekend!

Regards,
Tobias