-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
209 lines (166 loc) · 5.95 KB
/
Program.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Created by SharpDevelop.
* User: ankit.pal
* Date: 6/22/2015
* Time: 11:23 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace RobotXMLParser
{
class Program
{
static string MyXmlFile;
static string XMLconfigPath;
public Program()
{
//Console.WriteLine(ConfigurationManager.AppSettings.Get("inputFilePath"));
//Console.WriteLine(ConfigurationManager.AppSettings.Get("OutputFilePath"));
//XMLconfigPath = AppDomain.CurrentDomain.BaseDirectory;
//XMLconfigPath = @"C:\Users\ankit.pal\Desktop\1";
//MyXmlFile = XMLconfigPath+"\\output.xml";
}
// Warning codes:
// 101: Args are sent as null
static void Main(string[] args)
{
Program oProg = new Program();
if (args.Length == 0)
{
Console.WriteLine("Warning Code : 101");
XMLconfigPath = AppDomain.CurrentDomain.BaseDirectory;
if (!XMLconfigPath.EndsWith(@"\"))
{
XMLconfigPath += @"\";
}
MyXmlFile = XMLconfigPath+"output.xml";
}
else
{
for (int i = 0; i < args.Length; i+=2)
{
if(args[i].ToLower().Equals("--path"))
{
XMLconfigPath = args[i+1];
}
}
// #####START #### below code block is for handling the parameters which contain the path having space and not enquoted in ""
// string str = "";
// for (int i = 0; i < args.Length; i++)
// {
// str += args[i] + " ";
//
// }
// str = str.TrimEnd(' ');
// XMLconfigPath = str.Substring(7);
// #####END #### below code block is for handling the parameters which contain the path having space and not enquoted in ""
// XMLconfigPath = @"C:\Users\ankit.pal\Desktop\1";
if (!XMLconfigPath.EndsWith(@"\"))
{
XMLconfigPath += @"\";
}
MyXmlFile = XMLconfigPath+@"output.xml";
}
Console.WriteLine("Running the exe from => "+AppDomain.CurrentDomain.BaseDirectory);
try {
var orobot = oProg.Deserialized();
oProg.ProcessRoboXml(orobot);
oProg.Serialized(orobot);
} catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine("\n==========> GUIDELINE: <========== \n1. Please check if the output.xml is at the path given in the arguments. \n2. if no path was given as the argument then the output.xml should be in the same directory as this RobotXMLParser.exe");
Console.ReadLine();
}
string strCmdText;
string timeStamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
strCmdText = "/C rebot --log " + "\"" + XMLconfigPath + timeStamp + "_LOG.html" + "\"" + " --report " + "\"" + XMLconfigPath + timeStamp + "_REPORT.html" + "\" " + "\"" + XMLconfigPath + "ParsedRobotXML.xml"+"\"";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
public Robot Deserialized()
{
var serializer = new XmlSerializer(typeof(Robot));
var fileStream = new FileStream(MyXmlFile, FileMode.Open);
var result = (Robot)serializer.Deserialize(fileStream);
return result;
}
public void Serialized(Robot oRobot)
{
var serializer = new XmlSerializer(typeof(Robot));
var obj = File.Create(XMLconfigPath + "\\ParsedRobotXML.xml");
serializer.Serialize(obj, oRobot);
obj.Flush();
}
public void ProcessRoboXml(Robot oRobot)
{
for (int i = 0; i < oRobot.Suite.Count; i++)
{
ProcessTestSuite(oRobot.Suite[i]);
}
}
public void ProcessTestSuite(TestSuite oTestSuite)
{
for (int i = 0; i < oTestSuite.TestSuites.Count; i++)
{
ProcessTestSuite(oTestSuite.TestSuites[i]);
}
for (int j = 0; j < oTestSuite.TestCases.Count;j++)
{
ProcessTestCase(oTestSuite.TestCases[j]);
}
}
List<Keyword> logKeywords;
public void ProcessTestCase(TestCase oTestCase)
{
logKeywords = new List<Keyword>();
for (int i = 0; i < oTestCase.KeywordName.Count; i++)
{
bool delete = false;
delete = ProcessKeywords(oTestCase.KeywordName[i]);
if(!delete)
{
oTestCase.KeywordName.RemoveAt(i);
i--;
}
}
}
public bool ProcessKeywords(Keyword okeyword)
{
bool flag=false;
bool isLogPresent = false;
for (int i = 0; i < okeyword.Keywords.Count; i++)
{
isLogPresent = ProcessKeywords(okeyword.Keywords[i]);
if(isLogPresent)
{
flag = true;
}
else
{
okeyword.Keywords.RemoveAt(i);
i--;
}
}
//if(okeyword.Name.ToLower().Equals("builtin.log") && okeyword.Keywords.Count == 0)
if (okeyword.Name.ToLower().Equals("log") && okeyword.Keywords.Count == 0)
{
isLogPresent = true;
}
if(okeyword.Status[0].Status.ToLower().Equals("fail"))
{
isLogPresent = true;
}
if (flag)
{
isLogPresent = true;
}
return isLogPresent;
}
}
}