2016-11-06 8 views
-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 
}); 

//有多个这样的描述函数。如何使用c#中的正则表达式将这个.js文件解析为xml文件?

//这是一个testing.js文件,我有这个文件解析为一个XML文件,以便它看起来像:

//.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 
+0

输入输出Javascript代码,并显示您的输出不是XML。你不清楚你在问什么,无论如何你都需要显示你写的代码并提出一个具体的问题。这里没有人会为你编写代码。 –

+0

您是否在谈论从摩卡测试中生成xml单元测试报告? https://github.com/michaelleeallen/mocha-junit-reporter – allonhadaya

回答

0

正则表达式,你可以尝试是:

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

Explanation

样品C#代码:

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); 

     } 
    } 
} 

样本输出

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

格式,只要你想

+0

非常感谢你特立独行!我主要遇到了正则表达式模式的问题。 :) –

相关问题