-1
//testing.js file
describe('Criteria and Adjustment Section', function () {
    it('the labels should have correct spellings -Expected result- the labels have correct spellings', function () {
    //some logic
});


describe('Test 1', function () {
    it('Click on the company dropdown -Expected result- Four options will be shown', function () {
    //some logic 
});

//there are multiple describe-it functions like this.

//this is a testing.js file and I have to parse this file into an xml file so that it looks like:

//.xml file
Test No.     Test-Cases                 Expected Results
----------
01           all the labels should      the labels have correct spellings
             have correct spellings

----------
02           Click on the company       Four options will be shown
             dropdown
cnishina
  • 5,016
  • 1
  • 23
  • 40
P. H. Nabila
  • 45
  • 2
  • 6
  • The input is Javascript code, and the output you show is not XML. It is unclear what you are asking, and in any event you are require to show the code you have written and ask a specific question. Nobody here is going to write the code for you. – Jim Garrison Nov 06 '16 at 06:00
  • Are you talking about generating xml unit test reports from mocha tests? https://github.com/michaelleeallen/mocha-junit-reporter – allonhadaya Nov 06 '16 at 06:18

1 Answers1

0

Regex you can try is:

describe\('[^']*', function \(\) {.*?it\('([^']*)-Expected result-([^']*)',

Explanation

Sample C# Code:

using System;
using System.Text.RegularExpressions;

public class Test
{
    public static void Main()
    {

        string pattern = @"describe\('[^']*', function \(\) {.*?it\('([^']*)-Expected result-([^']*)',";
        string input = @"describe('Criteria and Adjustment Section', function () {
    it('the labels should have correct spellings -Expected result- the labels have correct spellings', function () {
    //some logic
});


describe('Test 1', function () {
    it('Click on the company dropdown -Expected result- Four options will be shown', function () {
    //some logic 
});";
        RegexOptions options = RegexOptions.Multiline | RegexOptions.Singleline;
        int count=0;
        foreach (Match m in Regex.Matches(input, pattern, options))
        {
            ++count;
            Console.WriteLine("Test No : "+count);
            Console.WriteLine("Test-Cases: "+m.Groups[1].Value);
            Console.WriteLine("Expected Reult: "+m.Groups[2].Value);

        }
    }
}

Sample Output

Test No : 1
Test-Cases: the labels should have correct spellings 
Expected Reult:  the labels have correct spellings
Test No : 2
Test-Cases: Click on the company dropdown 
Expected Reult:  Four options will be shown

Run the code here

Format the output as you want

Mustofa Rizwan
  • 10,215
  • 2
  • 28
  • 43