How to use id method of org.testng.Interface ITestResult class

Best Testng code snippet using org.testng.Interface ITestResult.id

Source:SeleniumGridListener.java Github

copy

Full Screen

1package com.dd.test.catpaw.platform.grid;2import java.io.File;3import java.util.HashMap;4import org.testng.IInvokedMethod;5import org.testng.IInvokedMethodListener;6import org.testng.ISuite;7import org.testng.ISuiteListener;8import org.testng.ITestContext;9import org.testng.ITestListener;10import org.testng.ITestResult;11import org.testng.Reporter;12import com.dd.test.catpaw.platform.config.CatPawConfig;13import com.dd.test.catpaw.platform.config.ServiceLoaderManager;14import com.dd.test.catpaw.reports.reporter.services.TestCaseUtility;15import com.dd.test.catpaw.reports.runtime.WebReporter;16/**17 * Contains the logic that will take care of all the selenium related18 */19public class SeleniumGridListener implements IInvokedMethodListener, ISuiteListener, ITestListener{20 // used to track browser sessions across all threads21 // data structure format <HashMap<String "sessionName", CatPawWebSession>22 private volatile HashMap<String, CatPawWebSession> sessionMap;23 // private static SimpleLogger logger = CatPawLogger.getLogger();24 25 /**26 * 27 * Identifies which version and name of browser to start if it specified in28 * &#064;webtest <br>29 * <b>sample</b><br>30 * 31 * &#064;webtest(<b>browser="*firefox"</b>)<br>32 * Identifies if test case wants to open new session <br>33 * <b>sample</b><br>34 * &#064;webtest(browser="*firefox", <b>openNewSession = true</b>)35 * 36 * @see org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod,37 * org.testng.ITestResult)38 */39 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {40 // logger.entering(new Object[] { method, testResult });41 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {42 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);43 return;44 }45 boolean webTest = method.isTestMethod()46 && method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(WebTest.class) != null;47 TestCaseUtility.appendECaseId(method, testResult);48 if (webTest) {49 try {50 // Acquire @WebTest annotation parameter values specified by51 // user52 WebTestConfig webTestConfig = new WebTestConfig().initWebTestConfig(method, sessionMap, testResult);53 String sessionName = webTestConfig.getSessionName();54 // Lazy start the grid on the first encounter of a @WebTest55 // annotated test method56 LocalGridManager.spawnLocalHub(webTestConfig.getBrowser());57 synchronized (this) {58 if (webTestConfig.getOpenNewSession()) {59 // if we already have a session with this name, on this60 // thread, close it61 if (sessionMap.containsKey(sessionName)) {62 IllegalStateException e = new IllegalStateException(63 "Found an existing session ["64 + sessionName65 + "]. Please either change the session name to a unique value or re-use that session.");66 // logger.log(Level.SEVERE, e.getMessage(), e);67 throw e;68 }69 70 CatPawWebSession newSession = Grid.startSession(webTestConfig);71 sessionMap.put(sessionName, newSession);72// if (logger.isLoggable(Level.FINE)) {73// // logger.log(Level.FINE, "Thread " + threadId + " created new " + sessionName + " = "74// + sessionMap.get(sessionName).toString());75// }76 } else {77 // try to switch into a session by the same name78 if (sessionMap.containsKey(sessionName)) {79 CatPawWebSession session = sessionMap.get(sessionName);80 if ((session == null) || (session.getWebDriver() == null)) {81 closeSession(sessionName, true);82 // Tell TestNG the exception occurred in83 // beforeInvocation84 IllegalStateException e = new IllegalStateException("The session " + sessionName85 + " is already closed. It probably timed out.");86 // logger.log(Level.SEVERE, e.getMessage(), e);87 throw e;88 } else {89// if (logger.isLoggable(Level.FINE)) {90// // logger.log(Level.FINE, "Thread " + threadId + " switching into " + sessionName91// + " = " + session.toString());92// }93 Grid.switchSession(sessionMap.get(sessionName), webTestConfig);94 }95 } else {96 IllegalStateException e = new IllegalStateException(97 "Unable to find an already existing session with name [" + sessionName + "].");98 // logger.log(Level.SEVERE, e.getMessage(), e);99 throw e;100 }101 }102 } // synchronized block103 // TODO : We need to be able to segregate CatPaw originated104 // Runtime Exceptions from other runtime105 // exceptions raised by Selenium or JSON. Including a marker for106 // this task here.107 } catch (RuntimeException e) {108 // We are looking for any additional unchecked exceptions that109 // Grid may have thrown110 String errorMsg = "An error occured while setting up the test environment. \nRoot cause: ";111 Reporter.log(errorMsg + e.getMessage(), true);112 // Tell TestNG the exception occurred in beforeInvocation113 RuntimeException runTimeException = new RuntimeException(errorMsg, e);114 testResult.setThrowable(runTimeException);115 // Time to raise an Exception to let TestNG know that the116 // configuration method failed117 // so that it doesn't start executing the test methods.118 // logger.log(Level.SEVERE, e.getMessage(), e);119 throw runTimeException;120 }121 }122 // logger.exiting();123 }124 125 /**126 * Executes when test case is finished<br>127 * 128 * Identify if webtest wants to have session open, otherwise close session<br>129 * <b>sample</b><br>130 * &#064;webtest(browser="*firefox", <b>keepSessionOpen = true</b>)<br>131 * Analyzes failure if any132 * 133 * @see org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod,134 * org.testng.ITestResult)135 * 136 */137 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {138 // logger.entering(new Object[] { method, testResult });139 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {140 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);141 return;142 }143 boolean webTest = method.isTestMethod()144 && method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(WebTest.class) != null;145// TestCaseCalData.setTime(false, method, testResult);146 if (webTest == false) {147 // logger.exiting();148 return;149 }150 // Acquire @WebTest annotation parameter values specified by user151 WebTestConfig webTestConfig = Grid.getWebTestConfig();152 //WebTestConfig would be a Null only under the following conditions (ofcourse because of us throwing an exception)153 //a. If the test-case with same session name already exists.154 //b. If we are unable to find an already existing session with name provided155 //c. Session with the session name is already closed.156 if (webTestConfig == null){157 return;158 }159 if (!webTestConfig.getKeepSessionOpen()) {160 closeSession(webTestConfig.getSessionName(), true);161 }162 // logger.exiting();163 }164 /*165 * go through and close all open sessions166 */167 private synchronized void closeAllSessions() {168 // logger.entering();169 // Close all open sessions170 for (String key : sessionMap.keySet()) {171 closeSession(key, false);172 sessionMap.put(key, null);173 }174 sessionMap.clear();175 // logger.exiting();176 }177 /*178 * close a sessions by name. optionally, also remove it from the sessionMap179 */180 private synchronized void closeSession(String name, boolean removeSessionFromMap) {181 // logger.entering(new Object[] { name, removeSessionFromMap });182 try {183 if ((sessionMap.get(name) != null) && (sessionMap.get(name).getWebDriver() != null)) {184 Grid.closeSession(sessionMap.get(name));185 }186 } catch (Throwable e) {187 // Ignore ... Grid.closeSession seems to ALWAYS throws something.188 } finally {189 sessionMap.put(name, null);190 }191 if (removeSessionFromMap) {192 sessionMap.remove(name);193 }194 // logger.exiting();195 }196 /**197 * Initiate config on suite start198 * 199 * @see org.testng.ISuiteListener#onStart(org.testng.ISuite)200 */201 public void onStart(ISuite suite) {202 // Look at public void onStart(ITestContext context) from other Listener203 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {204 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);205 return;206 }207 CatPawConfig.initConfig(suite);208 }209 /**210 * Generates and returns output directory string path211 * 212 * @param base213 * String shows path to the suiteName214 * @param suiteName215 * String suiteName specified by config file216 * @return String - path to output directory for that particular suite217 */218 public static String filterOutputDirectory(String base, String suiteName) {219 // logger.entering(new Object[] { base, suiteName });220 int index = base.lastIndexOf(suiteName);221 String outputFolderWithoutName = base.substring(0, index);222 // logger.exiting(outputFolderWithoutName + File.separator);223 return outputFolderWithoutName + File.separator;224 }225 /**226 * Closes selenium session when suite finished to run227 * 228 * @see org.testng.ISuiteListener#onFinish(org.testng.ISuite)229 */230 public void onFinish(ISuite suite) {231 // logger.entering(suite);232 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {233 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);234 return;235 }236// if (logger.isLoggable(Level.FINE)) {237// // logger.log(Level.FINE, "Thread " + Thread.currentThread().getId() + " finished Suite, Open Sessions = "238// + sessionMap.toString());239// }240 closeAllSessions();241 LocalGridManager.shutDownHub();242 // logger.exiting();243 }244 /**245 * 246 * @see org.testng.ISuiteListener#onFinish(org.testng.ISuite)247 */248 public void onFinish(ITestContext context) {249 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.250 //Failing to do so can have un-predictable results.251 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {252 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);253 return;254 }255 return;256 }257 /**258 * On start each suite initialize config object and report object259 */260 public void onStart(ITestContext context) {261 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {262 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);263 return;264 }265 sessionMap = new HashMap<String, CatPawWebSession>();266 ISuite suite = context.getSuite();267 CatPawConfig.initConfig(context);268 String base = suite.getOutputDirectory();269 String suiteName = suite.getName();270 String rootFolder = filterOutputDirectory(base, suiteName);271 WebReporter.setTestNGOutputFolder(rootFolder);272 WebReporter.init();273 }274 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {275 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.276 //Failing to do so can have un-predictable results.277 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {278 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);279 return;280 }281 return;282 }283 public void onTestFailure(ITestResult result) {284 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.285 //Failing to do so can have un-predictable results.286 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {287 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);288 return;289 }290 return;291 }292 public void onTestSkipped(ITestResult result) {293 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.294 //Failing to do so can have un-predictable results.295 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {296 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);297 return;298 }299 return;300 }301 public void onTestStart(ITestResult result) {302 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.303 //Failing to do so can have un-predictable results.304 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {305 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);306 return;307 }308 return;309 }310 public void onTestSuccess(ITestResult result) {311 //Below conditional check needs to be invoked in all TestNG Listener interface implementation.312 //Failing to do so can have un-predictable results.313 if (ServiceLoaderManager.executeCurrentMethod(this) == false) {314 // logger.exiting(ServiceLoaderManager.THREAD_EXCLUSION_MSG);315 return;316 }317 return;318 }319 320}...

Full Screen

Full Screen

Source:FacileTestListener.java Github

copy

Full Screen

...16import org.testng.ITestResult;17import org.testng.Reporter;18import org.testng.TestListenerAdapter;19import org.testng.annotations.ITestAnnotation;20import com.ooyala.facile.grid.saucelabs.SauceREST;21import com.ooyala.facile.util.NoRetry;22import com.ooyala.facile.util.ReadPropertyFile;23import com.ooyala.facile.util.ReadTriggerFile;24import com.ooyala.facile.util.TestDescription;25// TODO: Auto-generated Javadoc26/**27 * The listener interface for receiving facileTest events. The class that is28 * interested in processing a facileTest event implements this interface, and29 * the object created with that class is registered with a component using the30 * component's <code>addFacileTestListener<code> method. When31 * the facileTest event occurs, that object's appropriate32 * method is invoked.33 * 34 * @author pkumar35 */36public class FacileTestListener extends TestListenerAdapter implements37 IRetryAnalyzer, IAnnotationTransformer {38 /** The logger. */39 public static Logger logger = Logger.getLogger(FacileTestListener.class);40 /** The test case execution time. */41 private long testCaseExecutionTime = 0;42 /** The test start time. */43 private long testStartTime = 0;44 /** The test end time. */45 private long testEndTime = 0;46 /** The retry count. */47 protected int retryCount = 1;48 /** The Constant DEFAULT_MAX_RETRY. */49 protected final int DEFAULT_MAX_RETRY = 3;50 51 private static final Map<Integer, Integer> methods = Collections.synchronizedMap(new HashMap<Integer, Integer>());52 /*53 * (non-Javadoc)54 * 55 * @see org.testng.TestListenerAdapter#onTestStart(org.testng.ITestResult)56 */57 @Override58 public void onTestStart(ITestResult tr) {59 // Init the Reporter log with the correct60 Reporter.setCurrentTestResult(tr);61 String fullTestName = tr.getMethod().toString();62 testEndTime = 0;63 testCaseExecutionTime = 0;64 testStartTime = new java.util.Date().getTime();65 logger.info(now("MMddyyyy:hhmmss") + "=== Running... <" + fullTestName66 + ">===");67 // Logging the test description in the report68 if (tr.getMethod()69 .getConstructorOrMethod()70 .getMethod()71 .isAnnotationPresent(72 (Class<? extends Annotation>) TestDescription.class)) {73 TestDescription testDescription = tr.getMethod()74 .getConstructorOrMethod().getMethod()75 .getAnnotation(TestDescription.class);76 logger.info("******************************************************************");77 logger.info("Test description is " + testDescription.description());78 logger.info("******************************************************************");79 Reporter.log(testDescription.description() + "<br>");80 }81 // Output the retry number so that we can correlate the TestNG results82 // with83 // screenshots that are taken.84 if (retryCount == 0) {85 // Reporter.log("Running Test for First Time<br>");86 } else {87 Reporter.log("Running Retry #" + retryCount + "<br>");88 }89 }90 /*91 * (non-Javadoc)92 * 93 * @see org.testng.TestListenerAdapter#onTestSuccess(org.testng.ITestResult)94 */95 @Override96 public void onTestSuccess(ITestResult tr) {97 String fullTestName = getSuiteTestName(tr.getMethod().toString());98 testEndTime = new java.util.Date().getTime();99 testCaseExecutionTime = testEndTime - testStartTime;100 logger.info(now("MMddyyyy:hhmmss") + " Test Passed : " + fullTestName101 + " in " + testCaseExecutionTime + "ms.");102 logger.info("");103 if (tr.getAttributeNames() != null && !tr.getAttributeNames().isEmpty()104 && tr.getAttribute("jobId") != null)105 this.updateSauceTestJob(tr.getAttribute("jobId").toString(), true,106 tr);107 // Make sure to reset the retry count to 0 again108 retryCount = 0;109 }110 /*111 * (non-Javadoc)112 * 113 * @see org.testng.TestListenerAdapter#onTestSkipped(org.testng.ITestResult)114 */115 @Override116 public void onTestSkipped(ITestResult tr) {117 String fullTestName = getSuiteTestName(tr.getMethod().toString());118 testEndTime = new java.util.Date().getTime();119 testCaseExecutionTime = testEndTime - testStartTime;120 logger.info("Test Skipped: " + fullTestName + " in "121 + testCaseExecutionTime + "ms.");122 }123 /*124 * (non-Javadoc)125 * 126 * @see org.testng.TestListenerAdapter#onTestFailure(org.testng.ITestResult)127 */128 @Override129 public void onTestFailure(ITestResult tr) {130 testEndTime = new java.util.Date().getTime();131 testCaseExecutionTime = testEndTime - testStartTime;132 logger.info(now("MMddyyyy:hhmmss") + " Test FAILED "133 + getSuiteTestName(tr.getMethod().toString()) + "in "134 + testCaseExecutionTime + " ms.");135 if (tr.getAttributeNames() != null && !tr.getAttributeNames().isEmpty()136 && tr.getAttribute("jobId") != null)137 this.updateSauceTestJob(tr.getAttribute("jobId").toString(), false,138 tr);139 140 int hashCode = getHashCode(tr);141 int retryCount = getRetryCount(tr);142 if(retryCount > 0){143 if (methods.containsKey(hashCode)) {144 if (methods.get(hashCode) <= retryCount) {145 tr.setStatus(ITestResult.SKIP);146 tr.getTestContext().getFailedTests().removeResult(tr.getMethod());147 }148 } else {149 tr.setStatus(ITestResult.SKIP);150 tr.getTestContext().getFailedTests().removeResult(tr.getMethod());151 }152 }153 }154 /**155 * Gets the suite test name.156 * 157 * @param fullTestName158 * the full test name159 * @return the suite test name160 */161 protected String getSuiteTestName(String fullTestName) {162 fullTestName = fullTestName.replaceAll("com.ooyala.webdriver.tests.",163 "");164 return fullTestName;165 }166 /*167 * (non-Javadoc)168 * 169 * @see org.testng.IRetryAnalyzer#retry(org.testng.ITestResult)170 */171 172 private int getRetryCount(ITestResult result) {173 // Check to see if the "NoRetry" annotation is present in which case the174 // test SHOULD NOT be retried.175 if (result.getMethod().getMethod().isAnnotationPresent((Class<? extends Annotation>) NoRetry.class)) {176 return -1;177 }178 String retryString = System.getProperty("retry");179 String retryCountString = System.getProperty("retryCount");180 if (retryString != null && !retryString.equals("") && retryCountString != null181 && !retryCountString.equals("")) {182 int retryCount = Integer.parseInt(retryCountString);183 boolean retry = Boolean.parseBoolean(retryString);184 if (retry)185 return retryCount;186 else187 return -1;188 } else {189 File confFile = new File("src/test/resources/facile.properties");190 if (confFile.exists()) {191 ReadTriggerFile propertiesFile = new ReadTriggerFile("src/test/resources/facile.properties");192 String retry = propertiesFile.getParameter("retry", "");193 int retryCount = Integer.parseInt(propertiesFile.getParameter("retryCount", ""));194 logger.info("Retry count is " + retryCount);195 logger.info("Is Retry is enabled? " + retry);196 if (retry != null) {197 if (retry.equalsIgnoreCase("true")) {198 return retryCount;199 } else if (retry.equalsIgnoreCase("false")) {200 return -1;201 }202 }203 }204 }205 return DEFAULT_MAX_RETRY;206 }207 208 209 /*210 * (non-Javadoc)211 * 212 * @see org.testng.IRetryAnalyzer#retry(org.testng.ITestResult)213 */214 public boolean retry(ITestResult result) {215 216 int retryCount = getRetryCount(result);217 if(retryCount==-1)218 return false;219 else220 return retryTracker(retryCount, result);221 }222 /**223 * Now.224 * 225 * @param format226 * the format227 * @return the string228 */229 private String now(String format) {230 Calendar cal = Calendar.getInstance();231 return (new SimpleDateFormat(format)).format(cal.getTime());232 }233 /***234 * creating a hashcode to add it to the map to take care of retries. Needed this as testng's retry does not support data provider tests.235 * 236 * @param result237 * @return238 */239 private int getHashCode(ITestResult result){240 String name = result.getTestName() + result.getMethod().getMethodName();241 for(Object obj : result.getParameters()){242 if(obj!=null && obj.getClass()!=null && obj instanceof String)243 name = name + obj.toString();244 else if(obj != null && obj.getClass()==null)245 name = name + obj.toString();246 }247 return name.hashCode();248 }249 250 /**251 * Retry tracker.252 * 253 * @return true, if successful254 */255 private boolean retryTracker(int maxRetryCount,ITestResult result) {256 if(retryCount<=0)257 return false;258 int hashCode = getHashCode(result);259 if(methods.containsKey(hashCode)){260 int count = methods.get(hashCode);261 if(count <= maxRetryCount){262 count++;263 methods.put(hashCode, count);264 return true;265 }else{266 return false;267 }268 }else {269 methods.put(hashCode, 2);270 return true;271 }272 }273 /**274 * Update sauce test job.275 * 276 * @param jobID277 * the job id278 * @param testResult279 * the test result280 * @param result281 * the result282 */283 private void updateSauceTestJob(String jobID, boolean testResult,284 ITestResult result) {285 String sauceConfigFile = "/config/sauce.properties";286 InputStream in = FacileTestListener.class287 .getResourceAsStream(sauceConfigFile);288 if (!(in == null)) {289 String isSauceEnabled = ReadPropertyFile.getConfigurationParameter(290 sauceConfigFile, "USE_SAUCELAB_GRID");291 if (System.getProperty("USE_SAUCELAB_GRID") != null292 && System.getProperty("USE_SAUCELAB_GRID")293 .equalsIgnoreCase("true")) {294 logger.info("Sauce labs is enabled by Environment variable USE_SAUCELAB_GRID");295 } else if (isSauceEnabled != null) {296 if (isSauceEnabled.equalsIgnoreCase("true")) {297 logger.info("Sauce is enabled by property file "298 + sauceConfigFile);299 } else {300 logger.debug("Sauce is not enabled.");301 return;302 }303 } else {304 logger.info("Please provide valid value for USE_SAUCELAB_GRID in "305 + sauceConfigFile);306 return;307 }308 String sauceUserName = ReadPropertyFile.getConfigurationParameter(309 sauceConfigFile, "SAUCE_USERNAME");310 String sauceAPiKey = ReadPropertyFile.getConfigurationParameter(311 sauceConfigFile, "SAUCE_API_KEY");312 if (sauceUserName != null && sauceAPiKey != null) {313 logger.info("Saucelabs is enabled so updating the sauce labs job.");314 SauceREST client = new SauceREST(sauceUserName, sauceAPiKey);315 Map<String, Object> updates = new HashMap<String, Object>();316 // updates.put("name", result.getMethod().getMethodName());317 updates.put("passed", testResult);318 logger.info("Updating the status of method :'"319 + result.getMethod().getMethodName() + " '" + " as :"320 + testResult);321 // Temp fix, if the user name is not scmbuild (which is true if322 // the run from jenkins).323 // the current user name will be udpated to the job build324 // details325 if (!System.getProperty("user.name").equalsIgnoreCase(326 "scmbuild")) {327 updates.put(328 "build",329 "Test Started By :"330 + System.getProperty("user.name"));331 logger.info("Since the job is not invkoed from Jenkins, updating the user who started the job");332 }333 JSONArray tags = new JSONArray();334 tags.add(result.getTestContext().getIncludedGroups());335 // updates.put("tags", tags);336 client.updateJobInfo(jobID, updates);337 logger.info("Updating Sauce Job Id :" + jobID + " Completed.");338 }339 } else {340 logger.info("Sauce config file does not exist at "341 + sauceConfigFile);342 }343 }344 public void transform(ITestAnnotation annotation, Class testClass,345 Constructor testConstructor, Method testMethod) {346 IRetryAnalyzer retry = annotation.getRetryAnalyzer();347 logger.info("In retry of method " + testMethod.getName());348 if (retry == null) {349 annotation.setRetryAnalyzer(FacileTestListener.class);350 }351 }352}...

Full Screen

Full Screen

Source:IInvokedMethodYamlFactoryListenerTest.java Github

copy

Full Screen

...8import org.testng.ITestContext;9import org.testng.ITestNGMethod;10import org.testng.ITestResult;11import org.testng.annotations.BeforeMethod;12import org.testng.annotations.DataProvider;13import org.testng.annotations.Listeners;14import org.testng.annotations.Test;15import guru.mikelue.jdut.annotation.JdutResource;16import guru.mikelue.jdut.assertion.ResultSetAssert;17import guru.mikelue.jdut.jdbc.JdbcTemplateFactory;18import guru.mikelue.jdut.jdbc.function.DbResultSet;19import guru.mikelue.jdut.jdbc.function.DbStatement;20import guru.mikelue.jdut.testng.test.AbstractDataSourceTestBase;21@Listeners(IInvokedMethodYamlFactoryListenerTest.TestMethodInfoKeeper.class)22public class IInvokedMethodYamlFactoryListenerTest extends AbstractDataSourceTestBase {23 public static class TestMethodInfoKeeper implements IInvokedMethodListener {24 private final static Map<String, Object[]> callbackArgs = new HashMap<>();25 @Override26 public void beforeInvocation(IInvokedMethod method, ITestResult testResult)27 {28 if (!IInvokedMethodYamlFactoryListenerTest.class.isAssignableFrom(testResult.getTestClass().getRealClass())) {29 return;30 }31 callbackArgs.put(buildKey(method), new Object[] { method, testResult });32 }33 @Override34 public void afterInvocation(IInvokedMethod method, ITestResult testResult)35 {36 if (!IInvokedMethodYamlFactoryListenerTest.class.isAssignableFrom(testResult.getTestClass().getRealClass())) {37 return;38 }39 callbackArgs.remove(buildKey(method));40 }41 public static Object[] getCallbackArgs(Class<?> targetClass, String methodName)42 {43 return callbackArgs.get(buildKey(targetClass, methodName));44 }45 private static String buildKey(Class<?> targetClass, String methodName)46 {47 return String.format("%s#%s", targetClass.getCanonicalName(), methodName);48 }49 private static String buildKey(IInvokedMethod method)50 {51 ITestNGMethod testingMethod = method.getTestMethod();52 return buildKey(testingMethod.getRealClass(), testingMethod.getMethodName());53 }54 }55 private final IInvokedMethodYamlFactoryListener testedListener = new IInvokedMethodYamlFactoryListener();56 public IInvokedMethodYamlFactoryListenerTest() {}57 @BeforeMethod(firstTimeOnly=true)58 void prepareTable(Method method) throws SQLException59 {60 int tableId = -1;61 switch (method.getName()) {62 case "loadAndClean":63 case "withoutAnnotation":64 tableId = 22;65 break;66 case "loadAndCleanForOneTimeOnly":67 tableId = 45;68 break;69 case "loadAndCleanForMultipleTimes":70 tableId = 63;71 break;72 default:73 return;74 }75 final int decidedTableId = tableId;76 JdbcTemplateFactory.buildRunnable(77 () -> getDataSource().getConnection(),78 conn -> DbStatement.buildRunnableForStatement(79 conn, stmt -> {80 stmt.execute(String.format("DROP TABLE IF EXISTS tab_%d", decidedTableId));81 stmt.execute(String.format("CREATE TABLE tab_%d(t%d_id INTEGER)", decidedTableId, decidedTableId));82 }83 ).runJdbc()84 ).runJdbc();85 }86 /**87 * Tests building/clean on method level.88 */89 @Test @JdutResource90 void loadAndClean() throws SQLException91 {92 Object[] callbackArgs = TestMethodInfoKeeper.getCallbackArgs(getClass(), "loadAndClean");93 ITestContext testContext = ((ITestResult)callbackArgs[1]).getTestContext();94 YamlFactoryListenerBase.setDataSource(testContext, getDataSource());95 invokeCallback(testedListener::beforeInvocation, callbackArgs);96 /**97 * Asserts the building of data98 */99 String checkData = "SELECT COUNT(*) FROM tab_22 WHERE t22_id = 33";100 assertData(checkData, 2);101 // :~)102 invokeCallback(testedListener::afterInvocation, callbackArgs);103 YamlFactoryListenerBase.removeDataSource(testContext);104 /**105 * Asserts the clean of data106 */107 assertData(checkData, 0);108 // :~)109 }110 /**111 * Tests the build/clean on method without @JdutResource(nothing happened).112 */113 @Test114 void withoutAnnotation() throws SQLException115 {116 Object[] callbackArgs = TestMethodInfoKeeper.getCallbackArgs(getClass(), "withoutAnnotation");117 ITestContext testContext = ((ITestResult)callbackArgs[1]).getTestContext();118 YamlFactoryListenerBase.setDataSource(testContext, getDataSource());119 invokeCallback(testedListener::beforeInvocation, callbackArgs);120 /**121 * Asserts the building of data122 */123 String checkData = "SELECT COUNT(*) FROM tab_22 WHERE t22_id = 33";124 assertData(checkData, 0);125 // :~)126 invokeCallback(testedListener::afterInvocation, callbackArgs);127 YamlFactoryListenerBase.removeDataSource(testContext);128 /**129 * Asserts the clean of data130 */131 assertData(checkData, 0);132 // :~)133 }134 /**135 * Tests one time only(as true) for multi-time calling of a testing method by @DataProvider.136 */137 @Test(dataProvider="multiTimes")138 @JdutResource @TestNGConfig(oneTimeOnly=true)139 void loadAndCleanForOneTimeOnly(int v) throws SQLException140 {141 Object[] callbackArgs = TestMethodInfoKeeper.getCallbackArgs(getClass(), "loadAndCleanForOneTimeOnly");142 ITestContext testContext = ((ITestResult)callbackArgs[1]).getTestContext();143 YamlFactoryListenerBase.setDataSource(testContext, getDataSource());144 invokeCallback(testedListener::beforeInvocation, callbackArgs);145 /**146 * Asserts the building of data147 */148 String checkData = "SELECT COUNT(*) FROM tab_45 WHERE t45_id = 77";149 if (v == FIRST_TIME) {150 assertData(checkData, 1);151 }152 // :~)153 invokeCallback(testedListener::afterInvocation, callbackArgs);154 YamlFactoryListenerBase.removeDataSource(testContext);155 /**156 * Asserts the clean of data157 */158 if (v == LAST_TIME) {159 assertData(checkData, 2);160 }161 // :~)162 }163 /**164 * Tests one time only(as false) for multi-time calling of a testing method by @DataProvider.165 */166 @Test(dataProvider="multiTimes")167 @JdutResource @TestNGConfig(oneTimeOnly=false)168 void loadAndCleanForMultipleTimes(int v) throws SQLException169 {170 Object[] callbackArgs = TestMethodInfoKeeper.getCallbackArgs(getClass(), "loadAndCleanForMultipleTimes");171 ITestContext testContext = ((ITestResult)callbackArgs[1]).getTestContext();172 YamlFactoryListenerBase.setDataSource(testContext, getDataSource());173 invokeCallback(testedListener::beforeInvocation, callbackArgs);174 /**175 * Asserts the building of data176 */177 String checkData = "SELECT COUNT(*) FROM tab_63 WHERE t63_id = 89";178 if (v == FIRST_TIME) {179 assertData(checkData, 1);180 }181 // :~)182 invokeCallback(testedListener::afterInvocation, callbackArgs);183 YamlFactoryListenerBase.removeDataSource(testContext);184 /**185 * Asserts the clean of data186 */187 if (v == LAST_TIME) {188 assertData(checkData, 6);189 }190 // :~)191 }192 private final static int FIRST_TIME = 1;193 private final static int LAST_TIME = 3;194 @DataProvider195 Object[][] multiTimes()196 {197 return new Object[][] {198 { 1 }, { 2 }, { 3 },199 };200 }201 private static void assertData(String sql, int expectedCount) throws SQLException202 {203 JdbcTemplateFactory.buildRunnable(204 () -> getDataSource().getConnection(),205 conn -> DbResultSet.buildRunnable(206 conn, sql,207 rs -> new ResultSetAssert(rs)208 .assertNextTrue()209 .assertInt(1, expectedCount)210 ).runJdbc()211 ).runJdbc();212 }213 private static void invokeCallback(MethodCallBack callback, Object[] args)214 {215 callback.execute((IInvokedMethod)args[0], (ITestResult)args[1]);216 }217}218@FunctionalInterface219interface MethodCallBack {220 void execute(IInvokedMethod m, ITestResult r);221}...

Full Screen

Full Screen

Source:TestCaseUtility.java Github

copy

Full Screen

...11public class TestCaseUtility {12 13 // private static SimpleLogger logger = CatPawLogger.getLogger();14 15 public static void appendECaseId(IInvokedMethod method, ITestResult testResult) {16 // logger.entering(new Object[]{method, testResult});17 if (! method.isTestMethod()) {18 // logger.exiting();19 return;20 }21 Test testMethod = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class);22 String eCaseID = null;23 if (testMethod != null) {24 eCaseID = testMethod.testName();25 }26 // If methodName is not null, it means a Test Method was invoked as27 // @Test(testName="eCaseID")28 if (eCaseID != null && eCaseID.length() > 1) {29 appendAttribute(testResult, eCaseID);30// // // logger.exiting();31 return;32 }33 // check if the test method uses CatPaw framework comprehensible34 // data driven approach35 if (isCatPawDataDriven(testResult)) {36 appendAttribute(testResult, null);37// // // logger.exiting();38 return;39 }40 //If we reached here, it means the user wanted to update eztracker but we couldn't find the41 // ecase id in any way at all. So lets warn the user.42 StringBuffer errMsg = new StringBuffer("To update EZTracker either add 'testName' attribute to @Test annotation (or)\n");43 errMsg.append("Have your @Test method's data parameter class implement IECase interface (or)\n");44 errMsg.append("Have your test class that is instantiated by your @Factory method implement IECase interface.");45// logger.warning(errMsg.toString());46// // logger.exiting();47 }48 /**49 * This method helps set eCase ID attribute for CatPaw framework comprehensible Data Driven approach test cases or50 * for tests which are annotated as Test Methods and which pass the eCase ID as a parameter to the attribute51 * "testName"52 * 53 * @param result54 * - A result object of type {@link ITestResult}55 * @param attribute56 * - The eCase ID as a string that is to be set as an attribute to the result object57 */58 private static void appendAttribute(ITestResult result, String attribute) {59// // logger.entering(new Object[] { result, attribute });60 if (attribute == null) {61 Object[] parameters = result.getParameters();62 // First check if this is a regular data driven63 if (parameters.length > 0 && (IECase.class.isAssignableFrom(parameters[0].getClass()))) {64 IECase eCaseID1 = (IECase) result.getParameters()[0];65 attribute = eCaseID1.geteCase();66 result.setAttribute("eCaseID", attribute);67 // // // logger.exiting();68 return;69 }70 // If we are here, then it means it is a data driven test but71 // factories may be involved. So we need to check if the test class72 // implements IECase interface73 Object testClassInstance = result.getMethod().getInstance();74 if (testClassInstance instanceof IECase) {75 attribute = ((IECase) testClassInstance).geteCase();76 }77 }78 result.setAttribute("eCaseID", attribute);79// // logger.exiting();80 }81 /**82 * This method essentially helps the CatPaw Framework identify if a particular method that makes use of83 * DataProvider is intending to use CatPaw Framework comprehensible Data Driven Approach or not.84 * 85 * @param result86 * - A result object of type {@link ITestResult}87 * @return - A boolean that indicates of the result represents a method that is using CatPaw Framework defined Data88 * Driven approach or not.89 */90 private static boolean isCatPawDataDriven(final ITestResult result) {91 // logger.entering(result);92 boolean isDataDriven = false;93 if (result.getParameters().length == 1) {94 if (IECase.class.isAssignableFrom(result.getParameters()[0].getClass())) {95 // logger.exiting(true);96 return true;97 }98 }99 //Assuming it wasn't a regular data driven, lets check if Factories were used.100 Object testClassInstance = result.getMethod().getInstance();101 if (testClassInstance instanceof IECase){102 isDataDriven = true;103 }104 // logger.exiting(isDataDriven);105 return isDataDriven;106 }107 /**108 * This method iterates through a {@link IResultMap} and returns a list of {@link ITestResult}109 * 110 * @param results111 * - an object of type {@link IResultMap}112 * @return - a list of test results of type {@link ITestResult}113 */114 public static List<ITestResult> fetchTests(IResultMap results) {115 // logger.entering(results);116 List<ITestResult> consolidatedResults = new ArrayList<ITestResult>();117 Iterator<ITestResult> i = results.getAllResults().iterator();118 while (i.hasNext()){119 consolidatedResults.add(i.next());120 }121 // logger.exiting(consolidatedResults);122 return consolidatedResults;123 }124}...

Full Screen

Full Screen

Source:TestngListener.java Github

copy

Full Screen

...22 * (non-Javadoc)23 * 24 * @see org.testng.TestListenerAdapter#onTestFailure(org.testng.ITestResult)25 */26 @Override27 public void onTestFailure(ITestResult tr) {28 ITestNGMethod im = tr.getMethod();29 getCaseID(im);30 super.onTestFailure(tr);31 }32 /*33 * (non-Javadoc)34 * 35 * @see org.testng.TestListenerAdapter#onTestSkipped(org.testng.ITestResult)36 */37 @Override38 public void onTestSkipped(ITestResult tr) {39 ITestNGMethod im = tr.getMethod();40 getCaseID(im);41 super.onTestSkipped(tr);42 }43 /*44 * (non-Javadoc)45 * 46 * @see org.testng.TestListenerAdapter#onStart(org.testng.ITestContext)47 */48 @Override49 public void onStart(ITestContext testContext) {50 System.out.println("Start Test");51 super.onStart(testContext);52 }53 /*54 * (non-Javadoc)55 * 56 * @see org.testng.TestListenerAdapter#onFinish(org.testng.ITestContext)57 */58 @Override59 public void onFinish(ITestContext testContext) {60 // TODO Auto-generated method stub61 super.onFinish(testContext);62 }63 /*64 * (non-Javadoc)65 * 66 * @see org.testng.TestListenerAdapter#getFailedTests()67 */68 @Override69 public List<ITestResult> getFailedTests() {70 // TODO Auto-generated method stub71 return super.getFailedTests();72 }73 /*74 * (non-Javadoc)75 * 76 * @see org.testng.TestListenerAdapter#getPassedTests()77 */78 @Override79 public List<ITestResult> getPassedTests() {80 // TODO Auto-generated method stub81 return super.getPassedTests();82 }83 /*84 * (non-Javadoc)85 * 86 * @see org.testng.TestListenerAdapter#getSkippedTests()87 */88 @Override89 public List<ITestResult> getSkippedTests() {90 // TODO Auto-generated method stub91 return super.getSkippedTests();92 }93 /*94 * (non-Javadoc)95 * 96 * @see org.testng.TestListenerAdapter#onTestStart(org.testng.ITestResult)97 */98 @Override99 public void onTestStart(ITestResult result) {100 ITestNGMethod im = result.getMethod();101 getCaseID(im);102 super.onTestStart(result);103 }104 /**105 * Gets the case ID.106 *107 * @param im108 * the im109 * @return the case ID110 */111 private String[] getCaseID(ITestNGMethod im) {112 Method m = im.getConstructorOrMethod().getMethod();113 CaseId caseId = m.getAnnotation(CaseId.class);114 if (null != caseId) {115 for (String str : caseId.id()) {116 System.out.println("++++++++++++++++>>>>>>>>>>>>>\n\n\n" + str + "<<<<<<<\n\n");117 }118 return caseId.id();119 }120 return null;121 }122 /*123 * (non-Javadoc)124 * 125 * @see org.testng.TestListenerAdapter#getTestContexts()126 */127 @Override128 public List<ITestContext> getTestContexts() {129 // TODO Auto-generated method stub130 return super.getTestContexts();131 }132}...

Full Screen

Full Screen

Source:BaseTest.java Github

copy

Full Screen

...26 27 @Parameters({"browserName", "appUrl", "implicitTo", "explicitTo"})28 29 @BeforeClass30 public void openApp( @Optional(DEFAULT_BROWSER)String browserName,31 @Optional(DEFAULT_URL)String appUrl,32 @Optional(ITO)String implicitTo,33 @Optional(ETO)String explicitTo)34 {35 if(browserName.equalsIgnoreCase("chrome"))36 {37 System.setProperty(CHROME_KEY, CHROME_PATH);38 driver = new ChromeDriver();39 }40 else if(browserName.equalsIgnoreCase("firefox"))41 {42 System.setProperty(GECKO_KEY, GECKO_PATH);43 driver = new FirefoxDriver();44 }45 else 46 {47 throw new IllegalArgumentException();48 49 }50 driver.manage().window().maximize();51 52 long impTO=Long.parseLong(implicitTo);53 long expTO=Long.parseLong(explicitTo);54 driver.manage().timeouts().implicitlyWait(impTO, TimeUnit.SECONDS);55 56 driver.get(appUrl);57 webActionUtil=new WebActionUtil(driver,expTO); 58 59 }60 @Parameters({"emailId","emailpassword"})61 62 @BeforeMethod63 64 public void loginToApp( @Optional(DEFAULT_USER)String emailId,65 @Optional(DEFAULT_PWD)String emailpassword)66 {67 Loginpage lp=new Loginpage(driver,webActionUtil);68 lp.login(emailId, emailpassword);69 }70 71 @AfterMethod72 73 public void logout(ITestResult result)74 {75 if(result.getStatus()==ITestResult.FAILURE)// ITestResult is a interface and it will take the screenshot76 {77 CaptureScreenshot.getImage(driver, result.getName());78 }79 Homepage hp = new Homepage(driver, webActionUtil);80 hp.signOut();81 }82 83 @AfterClass84 public void closeApp()85 {86 driver.quit();87 88 }89 90 } ...

Full Screen

Full Screen

Source:ScreenShot.java Github

copy

Full Screen

...16public class ScreenShot {17 private WebDriver driver = new FirefoxDriver();18 String base = System.getProperty("user.dir");19 @Test (description = "take screen in try/catch block")20 public void captureScreen() throws Exception{21 driver.get("https://zoom.com");22 try{23 driver.findElement(By.id("invalidID"));24 }catch (Exception e){25 // implement 'TakesScreenshots' interface26 File image = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);27 //save it in project28 FileUtils.copyFile(image, new File(base+"/test-output/testScreen.png"));29 System.out.println("Screenshot captured successful.");30 }finally {31 driver.quit();32 }33 }34 @Test (description = "screenshots by using 'ITestResult' interface")35 public void captureScreen2()throws Exception{36 driver.get("https://zoom.com");37 driver.findElement(By.id("invalidID"));38 System.out.println("@After method should catch a screenshots ");39 }40 @AfterMethod41 public void getScreenshots(ITestResult result){42 // if method FAILS...43 if(ITestResult.FAILURE == result.getStatus()){44 // make a screenshots45 try {46 TakesScreenshot screen = (TakesScreenshot)driver;47 File image = screen.getScreenshotAs(OutputType.FILE);48 FileUtils.copyFile(image,49 new File(base+"/test-output/" + result.getName() + ".png"));50 System.out.println("Screenshot captured successful.");51 }catch (Exception e){52 System.out.println("Screenshot did not captured."+e.getMessage());53 }finally {54 driver.quit();55 }56 }57 }58}...

Full Screen

Full Screen

Source:SauceLabsIntegration.java Github

copy

Full Screen

...8import org.testng.Reporter;9public class SauceLabsIntegration implements IInvokedMethodListener {10 private static final Logger LOGGER = Logger11 .getLogger(SauceLabsIntegration.class);12 @Override13 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {14 try {15 // it will throw Null pointer exception for the method who are not16 // omelet driven , should be fixed as using try catch is a temporary17 // one!18 if (Driver.getBrowserConf().host().contains("sauce")19 && Driver.getBrowserConf().isRemoteFlag()) {20 RemoteWebDriver driver = (RemoteWebDriver) Driver.getDriver();21 LOGGER.debug("After in SL Integration driver Session ID: "22 + driver.getSessionId());23 WebInterface slWebInterface = new WebInterface();24 slWebInterface.updateSauceLabsJob(driver.getSessionId()25 .toString(), method.getTestMethod().getMethodName(),26 method.getTestResult().isSuccess());27 Reporter.setCurrentTestResult(testResult);28 Reporter.log("SauceLabs Report :: ");29 Reporter.log(slWebInterface.generateLinkForJob(driver30 .getSessionId().toString()));31 // Reporter.log(slWebInterface.generateLinkForEmbedScript(driver32 // .getSessionId().toString(), true));33 // Reporter.log("<br>");34 // Reporter.log("SauceLabs Video :: "35 // + slWebInterface.generateLinkForEmbedScript(driver36 // .getSessionId().toString(), false));37 Reporter.log("<br>");38 }39 } catch (Exception e) {40 LOGGER.error("Not to interfere in the test result!, but needs to be taken care!");41 }42 }43 @Override44 public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) {45 }46}...

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1package com.test;2import org.testng.Assert;3import org.testng.ITestResult;4import org.testng.annotations.Test;5public class TestNGListenerDemo {6 public void test1() {7 System.out.println("I am inside test1");8 }9 public void test2() {10 System.out.println("I am inside test2");11 }12 public void test3() {13 System.out.println("I am inside test3");14 }15}16package com.test;17import org.testng.ITestContext;18import org.testng.ITestListener;19import org.testng.ITestResult;20public class TestNGListeners implements ITestListener {21 public void onTestStart(ITestResult result) {22 System.out.println("on test start"+result.getName());23 }24 public void onTestSuccess(ITestResult result) {25 System.out.println("on test success"+result.getName());26 }27 public void onTestFailure(ITestResult result) {28 System.out.println("on test failure"+result.getName());29 }30 public void onTestSkipped(ITestResult result) {31 System.out.println("on test skipped"+result.getName());32 }33 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {34 }35 public void onStart(ITestContext context) {36 }37 public void onFinish(ITestContext context) {38 }39}

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1public class TestNGListener implements ITestListener {2 public void onTestStart(ITestResult result) {3 System.out.println("Test started: " + result.getMethod().getMethodName() + " with id: " + result.getId());4 }5 public void onTestSuccess(ITestResult result) {6 System.out.println("Test passed: " + result.getMethod().getMethodName() + " with id: " + result.getId());7 }8 public void onTestFailure(ITestResult result) {9 System.out.println("Test failed: " + result.getMethod().getMethodName() + " with id: " + result.getId());10 }11 public void onTestSkipped(ITestResult result) {12 System.out.println("Test skipped: " + result.getMethod().getMethodName() + " with id: " + result.getId());13 }14 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {15 System.out.println("Test failed but within success percentage: " + result.getMethod().getMethodName() + " with id: " + result.getId());16 }17 public void onStart(ITestContext context) {18 System.out.println("Test started: " + context.getName());19 }20 public void onFinish(ITestContext context) {21 System.out.println("Test finished: " + context.getName());22 }23}24public class TestNGTest {25 public void testMethod1() {26 System.out.println("Test method 1");27 }28 public void testMethod2() {29 System.out.println("Test method 2");30 }31}

Full Screen

Full Screen

id

Using AI Code Generation

copy

Full Screen

1public class TestNGListener implements ITestListener {2 public void onTestStart(ITestResult result) {3 System.out.println("Test started: " + result.getName());4 }5 public void onTestSuccess(ITestResult result) {6 System.out.println("Test succeeded: " + result.getName());7 }8 public void onTestFailure(ITestResult result) {9 System.out.println("Test failed: " + result.getName());10 }11 public void onTestSkipped(ITestResult result) {12 System.out.println("Test skipped: " + result.getName());13 }14 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {15 }16 public void onStart(ITestContext context) {17 }18 public void onFinish(ITestContext context) {19 }20}21import org.testng.annotations.Test;22public class TestNGListenerExample {23 public void testMethod1() {24 System.out.println("TestNGListenerExample.testMethod1");25 }26 public void testMethod2() {27 System.out.println("TestNGListenerExample.testMethod2");28 }29}

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful