Category Archives: Javascript

Assign the same tests to the Zephyr suites after they are moved to another project

Hello,

We have received the task of copying a very big suite of tests from a project to another and maintain their test cycle assignment. For the copy and moving part is easy, there are bulk actions. For the automatic assignment we couldn’t find a quick solution, probably there was.

 

Here’s our approach:

1) On the Test Cycles page we extend a test cycle that has tests which will be moved. This is necessary in order to figure out which to move.

In the browser’s console we run this code (search for domain in the ajax call and replace with your own domain):


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function($) {
    var cycleId = (function() {
            var el = $('li.expanded');
            return el.length > 0 ? el.attr('id').replace("cycle-","") : false;
        })(),
        projectId = (function() {
            var el = $('#zprojectId');
            return el.length > 0 ? el.attr('value') : false;
        })(),
        pageCount = (function() {
            var pageText = $('#getMoreSchedulesLbl').text(),
                count = pageText.match(/[0-9]{1,3}/g);
            return Math.ceil(count[count.length-1]/10);
        })(),
        i = 1,
        responses= [],
        offset,
        completed = 0;
    $('body').on('requestscompleted', function(){
        var len = responses.length,
            i = 0,
            summary = [],
            response;
        for(i; i < len; i++) { // iterate through all received responses
            response = responses[i];
            console.log(response);
            (function(item){
                var i = 0,
                    schedules, len;
                if(typeof item != 'undefined') {
                    schedules = item.schedules,
                        len = schedules.length;
                    for(i; i < len; i++) {
                        summary.push(schedules[i].summary);
                    }
                }
            })(response);
            console.log(summary);
        }
    });
    if(cycleId && projectId) {
        for(i; i <= pageCount; i++) {
            if(i == pageCount){
                lastPage = $('#getMoreSchedulesLbl').text().match(/[0-9]{1,3}/g);
                offset = (lastPage[lastPage.length-1] - ((i-1) * 10));
                console.log(offset);
            }else{
                offset = i * 10;
            }
            $.ajax('domain/rest/zephyr/latest/schedule?decorator=none&contentOnly=true&noTitle=true&cycleId=' + cycleId + '&action=expand&offset=' + offset + "&pid=" + projectId + "&vid=-1&sorter=ID", {
                method: "GET",
                async: false,
                complete: function(){
                    if(completed == pageCount -1) {
                        $('body').trigger('requestscompleted');
                    }
                    completed++;
                },
                success: function (response){
                    responses.push(response);
                }
            });
        }
    }
})(jQuery);

 

2) This returns an array of test names. Those names will be used as identifiers later on. Please copy them into another external document.

3) Copy or move the tests into the other project as desired

4) Open the tests search page on the new project and display as many as possible (the current functionality does not cycle through the pages)

5) Paste the following code and replace the first line with the array exported by the previous code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var incomingTitles = ["[Event Validation] Frontend - Checkout flow", "[Event Validation] Frontend - Mobile site", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2", "test name 3", "test name 1", "test name 2"];

(function($,incomingTitles){
    var testSummary = (function(){
        var summaries = $('td.summary'),
            i=0,
            title="",
            currentItem = '',
            currentItemVal = '',
            keysHolder = new Array();
        summaries.each(function(){
            currentItem = $(this).find('a.issue-link').text();
            currentItemVal = $(this).find('a.issue-link').attr('data-issue-key');
            //console.log(currentItem);
            if(incomingTitles.indexOf(currentItem) != -1){
                keysHolder.push(currentItemVal);
            }
        });
        console.log(keysHolder);
        return keysHolder;
    })();
})(jQuery,incomingTitles)

This function will export an array of test IDs. Copy them in a document.

6) Open the “Plan Test Cycle” page and click the cogwheel to add tests

7) Paste the array of IDs returned by the second script

 

We have tried to use the filters functionality but we could not select only the tests assigned to a suite. It got even worse when the same tests were assigned to more widgets.

Thank you,

Gabi