-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetupClass.cs
More file actions
227 lines (195 loc) · 8.7 KB
/
Copy pathSetupClass.cs
File metadata and controls
227 lines (195 loc) · 8.7 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using NUnit.Framework;
using System.Net.Mail;
namespace Setup
{
[SetUpFixture]
public class SetupClass
{
public static List<TestCaseSettingList> tl = new List<TestCaseSettingList>();
public static DataSet ds = new DataSet();
public static DataSet Outputds = new DataSet();
public static string masterPath;
public static string BrowserName;
public static string TestCaseDocumentPath = AppDomain.CurrentDomain.BaseDirectory + @"TestCase\TestCaseInput.xls";
public static string ResultTestCaseDocumentPath = AppDomain.CurrentDomain.BaseDirectory + @"TestCase\TestingReport.xls";
public static string sScreenShotPath = AppDomain.CurrentDomain.BaseDirectory + @"ScreenShots\";
public static string TestModules;
public static string TestPerson;
public static DataSet OutputDS
{
get
{
return Outputds;
}
set
{
Outputds = value;
}
}
public static DataSet DS
{
get
{
return ds;
}
set
{
ds = value;
}
}
public string MasterPath
{
get
{
return masterPath;
}
set
{
masterPath = value;
}
}
public List<TestCaseSettingList> GetList()
{
return tl;
}
[SetUp]
public void ReadingValuesFromExcel()
{
try
{
//Added by David to delete the screen shot while running the
Console.WriteLine("Screenshots directory cleared.....");
foreach (string filePath in Directory.GetFiles(sScreenShotPath))
File.Delete(filePath);
DS = new DataSet();
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", TestCaseDocumentPath);
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
Console.WriteLine("Excel DataReader Connection Open..");
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter oleda = new OleDbDataAdapter();
DataTable dt = new DataTable();
dt = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
int rowsCount = dt.Rows.Count;
Console.WriteLine("Reading Values from the Excel...");
for (int i = 0; i < rowsCount; i++)
{
string workSheetName = (string)dt.Rows[i]["TABLE_NAME"];
//Console.WriteLine(workSheetName);
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM [" + workSheetName + "]";
oleda = new OleDbDataAdapter(cmd);
if (workSheetName.Contains("Sheet1") || TestModules.Contains(workSheetName.Replace("$","")))
{
oleda.Fill(ds, workSheetName);
}
if (workSheetName.Contains("Sheet1"))
{
SetProperties(ds, workSheetName);
}
}
con.Close();
Outputds = ds.Copy();
foreach (DataTable dts in Outputds.Tables)
{
if (dts.TableName.Contains("Sheet1"))
{
continue;
}
else
{
dts.Columns.Add("Developer Status");
dts.Columns.Add("TestCase Status");
dts.Columns.Add("Internet Explorer");
dts.Columns.Add("Firefox");
dts.Columns.Add("Chrome");
//dts.Columns.Add();
//dts.Columns.Add();
}
}
Console.WriteLine("Excel Data Reader Connection closed...");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
public void SetProperties(DataSet dts, string TableName)
{
DataTable Properties = dts.Tables[TableName];
masterPath = Properties.Rows[0][0].ToString();
TestModules = Properties.Rows[1][0].ToString();
TestPerson = Properties.Rows[2][0].ToString();
}
[TearDown]
public void WriteResultsToExcel()
{
StreamWriter fs = new StreamWriter(ResultTestCaseDocumentPath, false);
fs.WriteLine("<?xml version=\"1.0\"?>");
fs.WriteLine("<?mso-application progid=\"Excel.Sheet\"?>");
fs.WriteLine("<ss:Workbook xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");
fs.WriteLine(" <ss:Styles>");
fs.WriteLine(" <ss:Style ss:ID=\"1\">");
fs.WriteLine(" <ss:Font ss:Bold=\"1\" />");
fs.WriteLine(" </ss:Style>");
fs.WriteLine(" </ss:Styles>");
foreach (DataTable OutputTable in Outputds.Tables)
{
fs.WriteLine(" <ss:Worksheet ss:Name=\"" + OutputTable.TableName + "\">");
fs.WriteLine(" <ss:Table>");
for (int x = 0; x <= OutputTable.Columns.Count - 1; x++)
{
fs.WriteLine(" <ss:Column ss:Width=\"{0}\"/>", 100);
}
fs.WriteLine(" <ss:Row ss:StyleID=\"1\">");
foreach (DataColumn column in OutputTable.Columns)
{
fs.WriteLine(" <ss:Cell>");
fs.WriteLine(string.Format(" <ss:Data ss:Type=\"String\">{0}</ss:Data>", column.ColumnName));
fs.WriteLine(" </ss:Cell>");
}
fs.WriteLine(" </ss:Row>");
for (int intRow = 0; intRow <= OutputTable.Rows.Count - 1; intRow++)
{
fs.WriteLine(string.Format(" <ss:Row ss:Height =\"{0}\">", 15));
for (int intCol = 0; intCol <= OutputTable.Columns.Count - 1; intCol++)
{
fs.WriteLine(" <ss:Cell>");
fs.WriteLine(string.Format(" <ss:Data ss:Type=\"String\">{0}</ss:Data>", OutputTable.Rows[intRow][intCol].ToString()));
fs.WriteLine(" </ss:Cell>");
}
fs.WriteLine(" </ss:Row>");
}
fs.WriteLine(" </ss:Table>");
fs.WriteLine(" </ss:Worksheet>");
}
fs.WriteLine("</ss:Workbook>");
fs.Close();
string LogonUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Send("The selenium test project was built and run. Kindly check the report attached.", "Selenium Test Excel Report", "[email protected]");
}
private static void Send(string emailbody, string emailSub, string ToAddress)
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 2525;
client.Host = "192.168.4.101";
client.Credentials = new System.Net.NetworkCredential("prasanthk", "dsrc12345");
mail.To.Add(ToAddress);
mail.Body = emailbody;
mail.Subject = emailSub;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(@"C:\Users\davidrajkumar.j\.jenkins\workspace\GenericPortalSeleniumTesting\SeleniumTestingProject\bin\Debug\TestCase\TestingReport.xls");
mail.Attachments.Add(attachment);
mail.IsBodyHtml = true;
client.Send(mail);
}
}
}