1 package com.yahoo.test.SelNG.YUI.tests;
2 
3 import com.yahoo.test.SelNG.framework.core.SelNGBase;
4 import com.yahoo.test.SelNG.framework.util.BrowserUtil;
5 import com.yahoo.test.SelNG.framework.util.Customreport;
6 import com.yahoo.test.SelNG.framework.util.DumpMonitor;
7 import com.yahoo.test.SelNG.framework.util.ThreadSafeSeleniumSessionStorage;
8 
9 import static com.yahoo.test.SelNG.framework.util.ThreadSafeSeleniumSessionStorage.session;
10 import org.apache.commons.configuration.Configuration;
11 import org.apache.commons.configuration.PropertiesConfiguration;
12 import org.testng.annotations.*;
13 
14 
15 /**
16  * @author
17  */
18 
19 public class CommonTest extends SelNGBase {
20 
21 	public static final int waitTimeInSeconds = 5;
22 
23 
24 	/*Non Grid section
25      * Following methods are for execution in normal mode and not in grid mode. Make sure to include abstract and non-grid groups and
26      * exclude grid group in testng.xml file
27     */
28 
29 	@Parameters({ "config-file" })
30     @BeforeTest(groups = { "abstract", "non-grid" })
initFramework(String configfile)31 	public void initFramework(String configfile) throws Exception {
32 			Configuration conf = new PropertiesConfiguration(configfile);
33 			super.Preparedtdfilesfrom_YALA(conf);
34 			super.initXMLFiles(conf);
35 
36 	}
37 
38 	@BeforeTest(groups = { "abstract", "non-grid" },dependsOnMethods = { "initFramework" })
initTests()39 	public void initTests() throws Exception{
40 		DumpMonitor.monitor(true);
41 		super.startSeleniumServer();
42 
43 	}
44 
45 	@BeforeMethod(groups = { "abstract", "non-grid"})
setUpTests()46 	public void setUpTests() {
47 		try {
48 			super.openBrowser();
49 			session().setSpeed("1000");
50 			SelNGBase.screenshotfilename="";
51 		} catch (Exception e) {
52 			logger.info(e.getMessage());
53 		}
54 	}
55 
56 	@AfterMethod(groups = { "abstract", "non-grid" })
tearDownTests()57 	public void tearDownTests() throws Exception{
58 		try {
59 
60 			//Capture screenshot if 'CAPTURESCREENSHOT' set to true
61 			if(SelNGBase.config.getString("CAPTURESCREENSHOT")!=null){
62 
63 				if(SelNGBase.config.getString("CAPTURESCREENSHOT").equalsIgnoreCase("true")){
64 					SelNGBase.screenshotfilename=Customreport.capturescreenshot();
65 					logger.info("Screenshot file name is "+SelNGBase.screenshotfilename);
66 				}
67 
68 			}
69 			try {
70 				BrowserUtil.deleteCookie("Y", "/");
71 				BrowserUtil.deleteCookie("T", "/");
72 			} catch (Exception f){ };
73 			super.closeBrowser();
74 		} catch (Exception e) {
75 			logger.info(e.getMessage());
76 		}
77 	}
78 
79 	@AfterTest(groups = { "abstract", "non-grid" })
cleanUp()80 	public void cleanUp() {
81 		try {
82 			DumpMonitor.monitor(false);
83 			try {
84 				BrowserUtil.deleteCookie("Y", "/");
85 				BrowserUtil.deleteCookie("T", "/");
86 			} catch (Exception f){ }
87 
88 			super.stopSeleniumServer();
89 		} catch (Exception e) {
90 			logger.info(e.getMessage());
91 		}
92 	}
93 
94 
95 
96 
97 
98 	/*
99 	 * Grid  section
100      * Following methods are for execution in Grid mode . Make sure to include abstract and grid group and exclude non-grid group in testng.xml file
101 	 */
102 
103 	@Parameters({ "config-file" })
104 	@BeforeTest(groups = {"abstract", "grid"})
initTestInGrid(String configfile)105 	public void initTestInGrid(String configfile) throws Exception {
106 		logger.warn("Config File :" + configfile);
107 		config = new PropertiesConfiguration(configfile);
108 		super.Preparedtdfilesfrom_YALA(config);
109 		super.initXMLFilesInGrid(config);
110 		try {
111 			super.openBrowserInGrid();
112 		} catch (Exception e) {
113 			logger.info(e.getMessage());
114 		} finally {
115 			ThreadSafeSeleniumSessionStorage.resetSession();
116 		}
117 	}
118 
119 	@BeforeMethod(groups = {"abstract", "grid"})
setupTestGrid()120 	public void setupTestGrid() {
121 		try {
122 			super.initXMLFilesInGrid(config);
123 			super.openBrowserInGrid();
124 		}catch (Exception e) {
125 			logger.info(e.getMessage());
126 		}
127 	}
128 
129 	@AfterMethod(groups = { "abstract","grid"})
tearDownTestGrid()130 	public void tearDownTestGrid() throws Exception{
131 		try {
132 			super.resetExpectedValueHashMap();
133 			if(config.getString("BROWSER").equals("IE")){
134 				ThreadSafeSeleniumSessionStorage.resetSession();
135 			} else {
136 				super.closeBrowserInGrid();
137 
138 			}
139 		}catch (Exception e) {
140 			logger.info(e.getMessage());
141 		}
142 	}
143 
144 }
145 
146