-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDotTestListener.java
314 lines (242 loc) · 13.3 KB
/
DotTestListener.java
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package frameworkcontentspeed.Lider;
import databaseaccesscontentspeed.UtilsDatabase;
import frameworkcontentspeed.Utils.BaseTest;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.contentspeed.automationtesting.Lider.src.src.SendEmailAtachament.*;
public class DotTestListener implements IExecutionListener, ISuiteListener, ITestListener//, IAlterSuiteListener
{
public static List<String> l = null;
public String sessionId;
String fisierConfigurari;
String browser;
String osversion;
RemoteWebDriver driver;
String typeTest = "";
String oosversion = "";
int failedTests = 0;
int totalFailedTests = 0;
boolean resultsSuita = true;
boolean resultsConfigurations = true;
int testfailures;
int testSucess;
int testSkipped;
int totalNumberOfPassedMethodsForSuite = 0;
String deviceName = "";
int totalfailedConfiguration = 0;
String forSephora = "";
BaseTest bt;
int TotalTC = 0;
private String URLClient;
private String tema;
private String host;
private String databaseGeneric;
private String userdatabaseGeneric;
private String passdatabaseGeneric;
// @Override
// public void alter(List<XmlSuite> suites) {
// XmlSuite suite = suites.get(0);
// List<XmlTest> tests = suite.getTests();
//
// System.out.println("size: " + tests.size());
//
// for (XmlTest t : tests) {
//
// t.addParameter("sessionId", sessionId);
// System.out.println(sessionId);
// }
//
//// XmlTest anotherTest = new XmlTest(suite);
//// anotherTest.setName("foo");
//// anotherTest.setClasses(test.getClasses());
// }
public void onStart(ITestContext context) {
try {
URLClient = context.getCurrentXmlTest().getParameter("urlClient");
ISuite suite = context.getSuite();
host = context.getCurrentXmlTest().getParameter("host");
databaseGeneric = context.getCurrentXmlTest().getParameter("database");
userdatabaseGeneric = context.getCurrentXmlTest().getParameter("userdatabase");
passdatabaseGeneric = context.getCurrentXmlTest().getParameter("passdatabase");
fisierConfigurari = context.getCurrentXmlTest().getParameter("filename");
forSephora = context.getCurrentXmlTest().getParameter("forSephora");
osversion = UtilsSelenium.readPropertyBS(fisierConfigurari, "os") + UtilsSelenium.readPropertyBS(fisierConfigurari, "os_version");
typeTest = context.getCurrentXmlTest().getParameter("typetest");
browser = UtilsSelenium.readPropertyBS(fisierConfigurari, "browser") + UtilsSelenium.readPropertyBS(fisierConfigurari, "browser_version") + " " + osversion;
deviceName = UtilsSelenium.readPropertyBS(fisierConfigurari, "deviceName") != null ? UtilsSelenium.readPropertyBS(fisierConfigurari, "deviceName") : "";
TotalTC = Integer.parseInt(UtilsSelenium.readPropertyBS(fisierConfigurari, "TotalTC"));
System.out.println("TotalTC " + TotalTC);
if (deviceName.isEmpty()) {
browser = UtilsSelenium.readPropertyBS(fisierConfigurari, "browser") + UtilsSelenium.readPropertyBS(fisierConfigurari, "browser_version");
} else {
browser = UtilsSelenium.readPropertyBS(fisierConfigurari, "deviceName");
}
tema = UtilsDatabase.GetTemaCurenta(host, databaseGeneric, userdatabaseGeneric, passdatabaseGeneric);
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("Eroare metoda onStart() suita " + ex.getLocalizedMessage());
}
}
// @Override
// public void alter(List<XmlSuite> suites) {
// for (XmlSuite suite : suites) {
// List<XmlTest> tests = new ArrayList<>();
//
// System.out.println(tests.size());
//// //Integer[] datum = getData();
// System.out.println(l.size());
// for (String data : l) {
// XmlTest test = new XmlTest(suite);
//// //test.setName("test_" + data);
// test.addParameter("sessionId", data);
//// //test.getClasses().add(new XmlClass(StudentTest.class));
// }
// }
// }
public void onTestStart(ITestResult result) {
bt = new BaseTest();
// driver = UtilsSelenium.readPropBSByBrowserByType(fisierConfigurari, browser, typeTest);
//
// bt.setWebDriver(driver);
String sessionId = bt.getSessionIdBS();
}
//driver = UtilsSelenium.readPropBSByBrowserByType(filename, Browser, typetest);
// @Override
// public void alter(List<XmlSuite> suites) {
// XmlSuite suite = suites.get(0);
// List<XmlTest> tests = suite.getTests();
//
// System.out.println("size: " + tests.size());
//
// for (XmlTest t : tests) {
//
// sessionId = bt.getSessionIdBS();
// t.addParameter("sessionId", sessionId);
// System.out.println(sessionId);
// }
//
//// XmlTest anotherTest = new XmlTest(suite);
//// anotherTest.setName("foo");
//// anotherTest.setClasses(test.getClasses());
// }
public void onTestSuccess(ITestResult result) {
testSucess += result.getTestContext().getPassedTests().size();
System.out.println("testSucess " + testSucess);
}
public void onTestFailure(ITestResult result) {
testfailures += result.getTestContext().getFailedTests().size();
System.out.println("testfailures: " + testfailures);
}
public void onTestSkipped(ITestResult result) {
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
public void onFinish(ITestContext context) {
}
public void onExecutionStart() {
try {
System.out.println("onExecutionStart()");
// l = new ArrayList<>();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
public void onStart(ISuite suite) {
try {
System.out.println("onStart(ISuite suite)");
l = new ArrayList<>();
System.out.println("dupa initilaizare lista onStart(ISuite suite) " + l.toString());
} catch (Throwable ex) {
ex.printStackTrace();
}
// suite.getXmlSuite()
}
public void onFinish(ISuite suite) {
Map<String, ISuiteResult> tests = suite.getResults();
ITestContext overview = null;
for (ISuiteResult r : tests.values()) {
overview = r.getTestContext();
totalNumberOfPassedMethodsForSuite += overview.getPassedTests().getAllMethods().size();
totalfailedConfiguration += overview.getFailedConfigurations().getAllMethods().size();
}
System.out.println("test cases passed: " + totalNumberOfPassedMethodsForSuite);
System.out.println("totalfailedConfiguration: " + totalfailedConfiguration);
}
public void onExecutionFinish() {
String msg = "";
System.out.println("numarul de elemente din lista de SessionId este: " + l.size());
for (String s : l) {
System.out.println("sesiune Id este pentru testele din suita : " + s);
}
try {
System.out.println("browser" + " " + browser);
if ((totalfailedConfiguration > 0) && !(tema.equals("cs_sephora"))) {
msg = "FAILED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalfailedConfiguration);
System.out.println(typeTest);
System.out.println(msg);
SendEmail("anda.cristea@contentspeed.ro", "dev@contentspeed.ro", "techsupport@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalfailedConfiguration > 0) && (tema.equals("cs_sephora"))) {
msg = "FAILED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalfailedConfiguration + " Sephora");
System.out.println(typeTest + " Sephora");
System.out.println(msg + " Sephora");
SendEmailSephoraFailed("anda.cristea@contentspeed.ro", "ggheorghe@sephora.ro", "dev@contentspeed.ro", "techsupport@contentspeed.ro", "test.sephora@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PJ"))) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
System.out.println(msg);
SendEmailPassed("anda.cristea@contentspeed.ro", "test@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PF")) && (tema.equals("cs_sephora"))) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
System.out.println(msg);
SendEmailSephoraPassed("anda.cristea@contentspeed.ro", "ggheorghe@sephora.ro", "test@contentspeed.ro", "test.sephora@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PF"))) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
System.out.println(msg);
SendEmailPassed("anda.cristea@contentspeed.ro", "test@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PF")) && ((tema.equals("cs_sephora")))) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(msg + " Sephora ");
SendEmailPassed("anda.cristea@contentspeed.ro", "test@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PFPJ")) && (tema.equals("cs_sephora"))) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
SendEmailSephoraPassed("anda.cristea@contentspeed.ro", "ggheorghe@sephora.ro", "test@contentspeed.ro", "test.sephora@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if ((totalNumberOfPassedMethodsForSuite == TotalTC) && (typeTest.equals("PFPJ")) && !tema.equals("cs_sephora")) {
msg = "PASSED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
SendEmailPassed("anda.cristea@contentspeed.ro", "test@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else if (tema.equals("cs_sephora")) {
msg = "FAILED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
System.out.println(msg);
SendEmailSephoraFailed("anda.cristea@contentspeed.ro", "ggheorghe@sephora.ro", "dev@contentspeed.ro", "techsupport@contentspeed.ro", "test.sephora@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
} else {
msg = "FAILED:" + " Raport Teste Automate pentru clientul " + URLClient + " cu tema:" + tema + " " + browser;
System.out.println(totalNumberOfPassedMethodsForSuite);
System.out.println(typeTest);
System.out.println(msg);
SendEmail("anda.cristea@contentspeed.ro", "dev@contentspeed.ro", "techsupport@contentspeed.ro", msg, "D:\\test-output\\emailable-report.html");
}
} catch (Throwable ex) {
System.out.println("Eroare trimitere Raport Teste Automate " + ex.getMessage());
}
}
}