How to use Interface ITest class of org.testng package

Best Testng code snippet using org.testng.Interface ITest

Source:AbstractChainedListener.java Github

copy

Full Screen

1package com.nordstrom.automation.testng;2import java.lang.reflect.Constructor;3import java.lang.reflect.Method;4import java.util.Collections;5import java.util.HashSet;6import java.util.List;7import java.util.Set;8import org.testng.IAnnotationTransformer;9import org.testng.IClassListener;10import org.testng.IConfigurationListener;11import org.testng.IInvokedMethod;12import org.testng.IInvokedMethodListener;13import org.testng.IMethodInstance;14import org.testng.IMethodInterceptor;15import org.testng.ISuite;16import org.testng.ISuiteListener;17import org.testng.ITestClass;18import org.testng.ITestContext;19import org.testng.ITestListener;20import org.testng.ITestResult;21import org.testng.annotations.IConfigurationAnnotation;22import org.testng.annotations.IDataProviderAnnotation;23import org.testng.annotations.IFactoryAnnotation;24import org.testng.annotations.IListenersAnnotation;25import org.testng.annotations.ITestAnnotation;26public abstract class AbstractChainedListener implements IAnnotationTransformer, ISuiteListener,27 IConfigurationListener, IInvokedMethodListener, ITestListener, IMethodInterceptor, IClassListener {28 29 Set<String> configSuccess = Collections.synchronizedSet(new HashSet<String>());30 Set<String> configFailure = Collections.synchronizedSet(new HashSet<String>());31 Set<String> configSkipped = Collections.synchronizedSet(new HashSet<String>());32 Set<String> beforeConfig = Collections.synchronizedSet(new HashSet<String>());33 34 Set<String> beforeMethodBefore = Collections.synchronizedSet(new HashSet<String>());35 Set<String> beforeMethodAfter = Collections.synchronizedSet(new HashSet<String>());36 Set<String> testMethodBefore = Collections.synchronizedSet(new HashSet<String>());37 Set<String> testMethodAfter = Collections.synchronizedSet(new HashSet<String>());38 Set<String> afterMethodBefore = Collections.synchronizedSet(new HashSet<String>());39 Set<String> afterMethodAfter = Collections.synchronizedSet(new HashSet<String>());40 41 Set<String> beforeClass = Collections.synchronizedSet(new HashSet<String>());42 Set<String> afterClass = Collections.synchronizedSet(new HashSet<String>());43 44 Set<String> testStarted = Collections.synchronizedSet(new HashSet<String>());45 Set<String> testSuccess = Collections.synchronizedSet(new HashSet<String>());46 Set<String> testFailure = Collections.synchronizedSet(new HashSet<String>());47 Set<String> testSkipped = Collections.synchronizedSet(new HashSet<String>());48 Set<String> testCurved = Collections.synchronizedSet(new HashSet<String>());49 Set<String> testsBegun = Collections.synchronizedSet(new HashSet<String>());50 Set<String> testsEnded = Collections.synchronizedSet(new HashSet<String>());51 52 Set<String> suiteBegun = Collections.synchronizedSet(new HashSet<String>());53 Set<String> suiteEnded = Collections.synchronizedSet(new HashSet<String>());54 55 Set<String> xformTest = Collections.synchronizedSet(new HashSet<String>());56 Set<String> xformConfig = Collections.synchronizedSet(new HashSet<String>());57 Set<String> xformProvider = Collections.synchronizedSet(new HashSet<String>());58 Set<String> xformFactory = Collections.synchronizedSet(new HashSet<String>());59 Set<String> xformListeners = Collections.synchronizedSet(new HashSet<String>());60 61 Set<String> interceptor = Collections.synchronizedSet(new HashSet<String>());62 @Override63 public void onConfigurationSuccess(ITestResult itr) {64 configSuccess.add(itr.getName());65 }66 @Override67 public void onConfigurationFailure(ITestResult itr) {68 configFailure.add(itr.getName());69 }70 @Override71 public void onConfigurationSkip(ITestResult itr) {72 configSkipped.add(itr.getName());73 }74 // @Override omitted to avoid interface conflict75 public void beforeConfiguration(ITestResult tr) {76 beforeConfig.add(tr.getName());77 }78 79 @Override80 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {81 if (method.getTestMethod().isBeforeMethodConfiguration()) {82 beforeMethodBefore.add(testResult.getName());83 } else if (method.isTestMethod()) {84 testMethodBefore.add(testResult.getName());85 } else if (method.getTestMethod().isAfterMethodConfiguration()) {86 afterMethodBefore.add(testResult.getName());87 }88 }89 @Override90 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {91 if (method.getTestMethod().isBeforeMethodConfiguration()) {92 beforeMethodAfter.add(testResult.getName());93 } else if (method.isTestMethod()) {94 testMethodAfter.add(testResult.getName());95 } else if (method.getTestMethod().isAfterMethodConfiguration()) {96 afterMethodAfter.add(testResult.getName());97 }98 }99 @Override100 public void onBeforeClass(ITestClass testClass) {101 beforeClass.add(testClass.getRealClass().getSimpleName());102 }103 @Override104 public void onAfterClass(ITestClass testClass) {105 afterClass.add(testClass.getRealClass().getSimpleName());106 }107 @Override108 public void onTestStart(ITestResult result) {109 testStarted.add(result.getName());110 }111 @Override112 public void onTestSuccess(ITestResult result) {113 testSuccess.add(result.getName());114 }115 @Override116 public void onTestFailure(ITestResult result) {117 testFailure.add(result.getName());118 }119 @Override120 public void onTestSkipped(ITestResult result) {121 testSkipped.add(result.getName());122 }123 @Override124 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {125 testCurved.add(result.getName());126 }127 @Override128 public void onStart(ITestContext context) {129 testsBegun.add(context.getName());130 }131 @Override132 public void onFinish(ITestContext context) {133 testsEnded.add(context.getName());134 }135 @Override136 public void onStart(ISuite suite) {137 suiteBegun.add(suite.getName());138 }139 @Override140 public void onFinish(ISuite suite) {141 suiteEnded.add(suite.getName());142 }143 @SuppressWarnings("rawtypes")144 @Override145 public void transform(ITestAnnotation annotation, Class testClass, Constructor testCtor,146 Method testMethod) {147 148 if (testClass != null) {149 xformTest.add("class: " + testClass.getSimpleName());150 } else if (testCtor != null) {151 xformTest.add("ctor: " + testCtor.getName());152 } else {153 xformTest.add("method: " + testMethod.getName());154 }155 }156 @SuppressWarnings("rawtypes")157 // @Override omitted to avoid interface conflict158 public void transform(IConfigurationAnnotation annotation, Class testClass,159 Constructor testCtor, Method testMethod) {160 161 if (testClass != null) {162 xformConfig.add("class: " + testClass.getSimpleName());163 } else if (testCtor != null) {164 xformConfig.add("ctor: " + testCtor.getName());165 } else {166 xformConfig.add("method: " + testMethod.getName());167 }168 }169 // @Override omitted to avoid interface conflict170 public void transform(IDataProviderAnnotation annotation, Method method) {171 xformProvider.add("method: " + method.getName());172 }173 // @Override omitted to avoid interface conflict174 public void transform(IFactoryAnnotation annotation, Method method) {175 if (method != null) {176 xformFactory.add("method: " + method.getName());177 } else {178 xformFactory.add("ctor: (unknown)");179 }180 }181 @SuppressWarnings("rawtypes")182 // @Override omitted to avoid interface conflict183 public void transform(IListenersAnnotation annotation, Class testClass) {184 xformListeners.add("class: " + testClass.getSimpleName());185 }186 187 @Override188 public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {189 interceptor.add(context.getName());190 return methods;191 }192}...

Full Screen

Full Screen

Source:TestListener.java Github

copy

Full Screen

1/*******************************************************************************2 * * Copyright 2018 T Mobile, Inc. or its affiliates. All Rights Reserved.3 * *4 * * Licensed under the Apache License, Version 2.0 (the "License"); you may not5 * * use this file except in compliance with the License. You may obtain a copy6 * * of the License at7 * *8 * * http://www.apache.org/licenses/LICENSE-2.09 * *10 * * Unless required by applicable law or agreed to in writing, software11 * * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12 * * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13 * * License for the specific language governing permissions and limitations under14 * * the License.15 ******************************************************************************/16package com.tmobile.ct.codeless.test.testng.listeners;17import org.testng.ITestContext;18import org.testng.ITestListener;19import org.testng.ITestResult;20import com.tmobile.ct.codeless.core.Test;21import com.tmobile.ct.codeless.test.extentreport.ExtentTestManager;22import org.slf4j.Logger;23import org.slf4j.LoggerFactory;24/**25 * The listener interface for receiving test events.26 * The class that is interested in processing a test27 * event implements this interface, and the object created28 * with that class is registered with a component using the29 * component's <code>addTestListener<code> method. When30 * the test event occurs, that object's appropriate31 * method is invoked.32 *33 * @author Rob Graff34 * @author Sai Chandra Korpu35 * @see TestEvent36 */37public class TestListener implements ITestListener {38 public static final Logger log = LoggerFactory.getLogger(TestListener.class);39 /**40 * Gets the test method name.41 *42 * @param iTestResult the i test result43 * @return the test method name44 */45 private static String getTestMethodName(ITestResult iTestResult) {46 return iTestResult.getMethod().getConstructorOrMethod().getName();47 }48 /* (non-Javadoc)49 * @see org.testng.ITestListener#onTestStart(org.testng.ITestResult)50 */51 @Override52 public void onTestStart(ITestResult result) {53 log.debug("Entering TestListener.onTestStart method " + getTestMethodName(result) + " start");54 Test test = (Test) result.getParameters()[0];55 ExtentTestManager.startTest(test.getName(), "Test Start");56 }57 /* (non-Javadoc)58 * @see org.testng.ITestListener#onTestSuccess(org.testng.ITestResult)59 */60 @Override61 public void onTestSuccess(ITestResult result) {62 log.debug("Entering TestListener.onTestSuccess method " + getTestMethodName(result) + " succeed");63 // Extentreports log operation for passed tests.64 // ExtentTestManager.getTest().log(LogStatus.PASS, "Test passed");65 }66 /* (non-Javadoc)67 * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult)68 */69 @Override70 public void onTestFailure(ITestResult iTestResult) {71 // To add it in the extent report72 // logger.log(LogStatus.FAIL, logger.addScreenCapture(screenshotPath));73 /*74 * log.debug("Entering TestListener.onTestFailure method " +75 * getTestMethodName(iTestResult) + " failed");76 * 77 * // Get driver from BaseTest and assign to local webdriver variable. Object78 * testClass = iTestResult.getInstance(); WebDriver webDriver = ((WebTest)79 * testClass).getDriver();80 * 81 * // Take base64Screenshot screenshot. String base64Screenshot =82 * "data:image/png;base64," + ((TakesScreenshot)83 * webDriver).getScreenshotAs(OutputType.BASE64);84 * 85 * // Extentreports log and screenshot operations for failed tests.86 * ExtentTestManager.getTest().log(LogStatus.FAIL, "Test Failed",87 * ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));88 */89 }90 /* (non-Javadoc)91 * @see org.testng.ITestListener#onTestSkipped(org.testng.ITestResult)92 */93 @Override94 public void onTestSkipped(ITestResult iTestResult) {95 log.debug("Entering TestListener.onTestSkipped method " + getTestMethodName(iTestResult) + " skipped!");96 // Extentreports log operation for skipped tests.97 // ExtentTestManager.getTest().log(LogStatus.SKIP, "Test Skipped");98 log.error("skip exception:: "+iTestResult.getThrowable());99 iTestResult.getThrowable().printStackTrace();100 }101 /* (non-Javadoc)102 * @see org.testng.ITestListener#onTestFailedButWithinSuccessPercentage(org.testng.ITestResult)103 */104 @Override105 public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {106 log.debug("Test failed but it is in defined success ratio " + getTestMethodName(iTestResult));107 }108 /* (non-Javadoc)109 * @see org.testng.ITestListener#onStart(org.testng.ITestContext)110 */111 @Override112 public void onStart(ITestContext context) {113 log.debug("Entering TestListener.onStart method " + context.getName());114// context.setAttribute("WebDriver", this.getDriver());115 116 }117 /* (non-Javadoc)118 * @see org.testng.ITestListener#onFinish(org.testng.ITestContext)119 */120 @Override121 public void onFinish(ITestContext context) {122 log.debug("Entering TestListener.onFinish method " + context.getName());123 ExtentTestManager.endTest();124 ExtentTestManager.getReporter().flush();125 }126}...

Full Screen

Full Screen

Source:Listener.java Github

copy

Full Screen

1package com.HFramework.utility;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.ISuite;5import org.testng.ISuiteListener;6import org.testng.ITestContext;7import org.testng.ITestListener;8import org.testng.ITestNGMethod;9import org.testng.ITestResult;10import org.testng.Reporter;11public class Listener implements ITestListener, ISuiteListener, IInvokedMethodListener {12 /*13 * What is Listeners in Selenium WebDriver? 14 * Listener is defined as interface that modifes the default TestNG's behavior. As the name suggests Listeners15 * "listen" to the event defined in the selenium script and behave accordingly.16 * It is used in selenium by implementing Listeners Interface. It allows17 * customizing TestNG reports or logs. There are many types of TestNG listeners18 * available19 * 20 * Types of Listeners in TestNG There are many types of listeners which allows21 * you to change the TestNG's behavior.22 * 23 * Below are the few TestNG listeners:24 * 25 * IAnnotationTransformer , IAnnotationTransformer2 , IConfigurable ,26 * IConfigurationListener , IExecutionListener, IHookable ,27 * IInvokedMethodListener , IInvokedMethodListener2 , IMethodInterceptor ,28 * IReporter, ISuiteListener, ITestListener . Above Interface are called TestNG29 * Listeners. These interfaces are used in selenium to generate logs or30 * customize the Testing reports.31 */32 // This belongs to ISuiteListener and will execute before the Suite start33 public void onStart(ISuite isuitestart) {34 Reporter.log("About to begin executing Suite " + isuitestart.getName(), true);35 }36 // This belongs to ISuiteListener and will execute, once the Suite is finished37 public void onFinish(ISuite isuiteend) {38 Reporter.log("About to end executing Suite " + isuiteend.getName(), true);39 }40 // This belongs to ITestListener and will execute before starting of Test41 // set/batch42 public void onStart(ITestContext iteststart) {43 Reporter.log("About to begin executing Test " + iteststart.getName(), true);44 }45 // This belongs to ITestListener and will execute, once the Test set/batch is46 // finished47 public void onFinish(ITestContext itestend) {48 Reporter.log("Completed executing test " + itestend.getName(), true);49 }50 // This belongs to ITestListener and will execute only when the test is pass51 public void onTestSuccess(ITestResult itestpass) {52 // This is calling the printTestResults method53 printTestResults(itestpass);54 }55 // This belongs to ITestListener and will execute only on the event of fail test56 public void onTestFailure(ITestResult itestfail) {57 // This is calling the printTestResults method58 printTestResults(itestfail);59 }60 // This belongs to ITestListener and will execute before the main test start61 // (@Test)62 public void onTestStart(ITestResult mainiteststart) {63 System.out.println("The execution of the main test starts now");64 }65 // This belongs to ITestListener and will execute only if any of the main66 // test(@Test) get skipped67 public void onTestSkipped(ITestResult mainitestskiped) {68 printTestResults(mainitestskiped);69 }70 // This is just a piece of shit, ignore this71 public void onTestFailedButWithinSuccessPercentage(ITestResult successpercentage) {72 73 System.out.println(successpercentage);74 }75 // This is the method which will be executed in case of test pass or fail76 // This will provide the information on the test77 private void printTestResults(ITestResult result) {78 Reporter.log("Test Method resides in " + result.getTestClass().getName(), true);79 if (result.getParameters().length != 0) {80 String params = null;81 for (Object parameter : result.getParameters()) {82 params += parameter.toString() + ",";83 }84 Reporter.log("Test Method had the following parameters : " + params, true);85 }86 String status = null;87 switch (result.getStatus()) {88 case ITestResult.SUCCESS:89 status = "Pass";90 break;91 case ITestResult.FAILURE:92 status = "Failed";93 break;94 case ITestResult.SKIP:95 status = "Skipped";96 }97 Reporter.log("Test Status: " + status, true);98 }99 // This belongs to IInvokedMethodListener and will execute before every method100 // including @Before @After @Test101 public void beforeInvocation(IInvokedMethod methodname, ITestResult itestresults) {102 String textMsg = "About to begin executing following method : " + returnMethodName(methodname.getTestMethod());103 Reporter.log(textMsg, true);104 }105 // This belongs to IInvokedMethodListener and will execute after every method106 // including @Before @After @Test107 public void afterInvocation(IInvokedMethod arg1, ITestResult arg2) {108 String textMsg = "Completed executing following method : " + returnMethodName(arg1.getTestMethod());109 Reporter.log(textMsg, true);110 }111 // This will return method names to the calling function112 private String returnMethodName(ITestNGMethod method) {113 return method.getRealClass().getSimpleName() + "." + method.getMethodName();114 }115}...

Full Screen

Full Screen

Source:TestListenerFailPass.java Github

copy

Full Screen

1package com.quiksilver.util;2import java.io.File;3import java.io.IOException;4import java.text.DateFormat;5import java.text.SimpleDateFormat;6import java.util.Date;7import org.apache.commons.io.FileUtils;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.TakesScreenshot;10import org.openqa.selenium.WebDriver;11import org.testng.ISuite;12import org.testng.ITestResult;13import org.testng.Reporter;14import org.testng.TestListenerAdapter;15import org.testng.annotations.AfterMethod;16import org.testng.annotations.Listeners;17import org.apache.log4j.*;18/*19 * It's very easy to generate your own reports with TestNG with Listeners and Reporters:20Listeners implement the interface org.testng.ITestListener and are notified in real time 21of when a test starts, passes, fails, etc...22Reporters implement the interface org.testng.IReporter and are notified when all the suites 23have been run by TestNG. The IReporter instance receives a list of objects24 that describe the entire test run.25 */26/*27 * I chose to extend TestListenerAdapter, which implements ITestListener with empty methods, 28 * so I don't have to override other methods from the interface that I have no interest in. 29 * If you try public class 'TestScreenshotOnFailure implements ITestResult' - implementing an interface instead of 30 * extending your class with a TestNG class that implements the interface you want (ITestResult) then31 * you will have to override ALL (15-18) methods declared in ITestResult interface which is not productive32 */33/*THIS CLASS DEFINES RULES for DEFAULT BEHAVIOUR of org.testng.ITestResult.Failure or Success34 * http://testng.org/javadocs/constant-values.html#org.testng.ITestResult.FAILURE35 * TO USE THIS CLASS:36 * 37 *put this annotation before you class where you define your test methods38 * @Listeners({ com.quicksilver.util.TestListenerFailPass.class })39 */40public class TestListenerFailPass extends TestListenerAdapter {41 42 WebDriver driver;43 private int m_count = 0;44 Logger log=WebDriverManager.LoggerGetInstance();45 46 ReadingProperties rp = new ReadingProperties();47 String failPath=rp.readConfigProperties("fail.screenshot.path");48 String passPath=rp.readConfigProperties("pass.screenshot.path");49 String usergenPath =rp.readConfigProperties("usergen.screenshot.path");50 51 @Override52 public void onTestFailure(ITestResult tr) {53 //log("Failed");//testng logger54 driver = WebDriverManager.getDriverInstance();55 WebDriverManager.getBrowser(driver);56 File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);57 DateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy__hh_mm_ssaa");58 String destDir = System.getProperty("user.dir")+failPath;59 new File(destDir).mkdirs();60 String destFile = dateFormat.format(new Date()) + ".png";61 try {62 FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));63 } catch (IOException e) {64 e.printStackTrace();65 System.out.println("Could not take screenshot on failure"+ tr.getInstanceName());//getInstanceName =package+className66 log.debug("Could not take screenshot on failure"+ tr.getInstanceName());//getInstanceName =package+className67 }68 Reporter.setEscapeHtml(false);69 Reporter.log("Saved <a href=../screenshot/FAIL/" + destFile + ">Screenshot</a>");70 }71 @Override72 public void onTestSkipped(ITestResult tr) {73 log("Skipped test");74 Reporter.log("Skipped test to avoid test failure due to dependency");75 }76 @Override77 public void onTestSuccess(ITestResult tr) {78 //log("Pass");79 driver = WebDriverManager.getDriverInstance();80 File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);81 DateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy__hh_mm_ssaa");82 String destDir = System.getProperty("user.dir")+passPath;83 new File(destDir).mkdirs();84 String destFile = dateFormat.format(new Date()) + ".png";85 try {86 FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));87 } catch (IOException e) {88 e.printStackTrace();89 System.out.println("Could not take screenshot on success"+ tr.getInstanceName());//getInstanceName =package+className90 log.debug("Could not take screenshot on success"+ tr.getInstanceName());//getInstanceName =package+className91 }92 Reporter.setEscapeHtml(false);93 Reporter.log("Saved <a href=../screenshot/PASS/" + destFile + ">Screenshot</a>");94 }95 private void log(String string) {96 System.out.print(string);97 if (++m_count % 40 == 0) {98 System.out.println("");99 }100 }101 102 103 public void onFinish(ISuite suite)104 /*every time testng finished running a testsuite it should create a folder - label it with suite name and date of run105 * 106 */107 {108 109 }110}...

Full Screen

Full Screen

Source:ReportListener.java Github

copy

Full Screen

1package com.core.api.config;23import org.testng.ITestContext;4import org.testng.ITestListener;5import org.testng.ITestResult;6import org.testng.annotations.Test;78// TODO: Auto-generated Javadoc9/**10 * The listener interface for receiving report events. The class that is11 * interested in processing a report event implements this interface, and the12 * object created with that class is registered with a component using the13 * component's addReportListener method. When the report event14 * occurs, that object's appropriate method is invoked.15 * 16 * @author Pavan.DV17 * @since 1.318 */19public class ReportListener implements ITestListener {2021 /**22 * Gets the test name.23 *24 * @param result the result25 * @return the test name26 */27 public String getTestName(ITestResult result) {28 Test testAnnotation = result.getMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class);29 if (testAnnotation != null && !"".equals(testAnnotation.testName().trim())) {30 return testAnnotation.testName().trim();31 }32 return result.getTestName() != null ? result.getTestName()33 : result.getMethod().getConstructorOrMethod().getName();34 }3536 /**37 * Gets the main test name.38 *39 * @param result the result ,if not available return the Test class name40 * @return the main test name41 */42 public String getMainTestName(ITestResult result) {43 result.getMethod().isDataDriven();44 Test test = result.getTestClass().getRealClass().getDeclaredAnnotation(Test.class);45 if (test != null && !"".equalsIgnoreCase(test.testName().trim())) {46 return test.testName().trim();47 }48 return result.getTestClass().getRealClass().getSimpleName();49 }5051 /**52 * Gets the main test name.53 *54 * @param result the result ,if not available return the Test class name55 * @return the main test name56 */57 public String getMainTestDescription(ITestResult result) {58 Test test = result.getTestClass().getRealClass().getDeclaredAnnotation(Test.class);59 if (test != null && !"".equalsIgnoreCase(test.description().trim())) {60 return test.description().trim();61 }62 return "";63 }6465 /**66 * Gets the main test name.67 *68 * @param result the result ,if not available return the Test class name69 * @return the main test name70 */71 public String[] getTestGroups(ITestResult result) {72 return result.getMethod().getGroups();73 }7475 /**76 * Gets the test description.77 *78 * @param result the result79 * @return the test description80 */81 public String getTestDescription(ITestResult result) {82 return result.getMethod().getDescription() != null ? result.getMethod().getDescription() : getTestName(result);83 }8485 /* (non-Javadoc)86 * @see org.testng.ITestListener#onTestStart(org.testng.ITestResult)87 */88 @Override89 public void onTestStart(ITestResult result) {90 ExtentReportManager.startTest(getMainTestName(result), getMainTestDescription(result), getTestName(result),91 getTestDescription(result), getTestGroups(result));92 }9394 /* (non-Javadoc)95 * @see org.testng.ITestListener#onTestSuccess(org.testng.ITestResult)96 */97 @Override98 public void onTestSuccess(ITestResult result) {99 100 }101102 /* (non-Javadoc)103 * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult)104 */105 @Override106 public void onTestFailure(ITestResult result) {107 Throwable t = result.getThrowable();108 @SuppressWarnings("unused")109 String cause = "";110 if (t != null)111 cause = t.getMessage();112 try {113 ReportUtil.logException(t);114 } catch (Exception e) {115 e.printStackTrace();116 }117 }118119 /* (non-Javadoc)120 * @see org.testng.ITestListener#onTestSkipped(org.testng.ITestResult)121 */122 @Override123 public void onTestSkipped(ITestResult result) {124 }125126 /* (non-Javadoc)127 * @see org.testng.ITestListener#onTestFailedButWithinSuccessPercentage(org.testng.ITestResult)128 */129 @Override130 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {131 }132133 /* (non-Javadoc)134 * @see org.testng.ITestListener#onStart(org.testng.ITestContext)135 */136 @Override137 public void onStart(ITestContext context) {138 }139140 /* (non-Javadoc)141 * @see org.testng.ITestListener#onFinish(org.testng.ITestContext)142 */143 @Override144 public void onFinish(ITestContext context) {145 ExtentReportManager.getExtentReports().flush();146 }147148} ...

Full Screen

Full Screen

Source:TestngListener.java Github

copy

Full Screen

1package main.java.com.dbyl.appiumCore.testng;2import java.lang.reflect.Method;3import java.util.List;4import org.testng.ITestContext;5import org.testng.ITestNGMethod;6import org.testng.ITestResult;7import org.testng.TestListenerAdapter;8import main.java.com.dbyl.appiumCore.utils.CaseId;9/**10 * The listener interface for receiving testng events. The class that is11 * interested in processing a testng event implements this interface, and the12 * object created with that class is registered with a component using the13 * component's <code>addTestngListener<code> method. When the testng event14 * occurs, that object's appropriate method is invoked.15 *16 * @author Young17 * @version V1.018 * @see TestngEvent19 */20public class TestngListener extends TestListenerAdapter {21 /*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:DefaultMethodTest.java Github

copy

Full Screen

1package test.defaultmethods;2import org.testng.Assert;3import org.testng.ITestClass;4import org.testng.ITestNGMethod;5import org.testng.TestNG;6import org.testng.annotations.Test;7import test.SimpleBaseTest;8import test.listeners.TestAndClassListener;9public class DefaultMethodTest extends SimpleBaseTest {10 @Test(description = "Test default methods defined in an interface should be run")11 public void testDefaultShouldRun() {12 ITestClass testClass = runTestWithDefaultMethods();13 ITestNGMethod[] testMethods = testClass.getTestMethods();14 Assert.assertEquals(testMethods.length, 1);15 Assert.assertEquals(testMethods[0].getMethodName(), "defaultMethodTest");16 }17 @Test(description = "Before class default methods defined in an interface should be run")18 public void beforeClassDefaultShouldRun() {19 ITestClass testClass = runTestWithDefaultMethods();20 ITestNGMethod[] beforeClassMethods = testClass.getBeforeClassMethods();21 Assert.assertEquals(beforeClassMethods.length, 1);22 Assert.assertEquals(beforeClassMethods[0].getMethodName(), "beforeClassRun");23 }24 @Test(description = "After class default methods defined in an interface should be run")25 public void afterClassDefaultShouldRun() {26 ITestClass testClass = runTestWithDefaultMethods();27 ITestNGMethod[] afterClassMethods = testClass.getAfterClassMethods();28 Assert.assertEquals(afterClassMethods.length, 1);29 Assert.assertEquals(afterClassMethods[0].getMethodName(), "afterClassRun");30 }31 @Test(description = "Before method default methods defined in an interface should be run")32 public void beforeMethodDefaultShouldRun() {33 final ITestClass testClass = runTestWithDefaultMethods();34 ITestNGMethod[] beforeMethods = testClass.getBeforeTestMethods();35 Assert.assertEquals(beforeMethods.length, 1);36 Assert.assertEquals(beforeMethods[0].getMethodName(), "beforeMethodRun");37 }38 @Test(description = "After method default methods defined in an interface should be run")39 public void afterMethodDefaultShouldRun() {40 final ITestClass testClass = runTestWithDefaultMethods();41 ITestNGMethod[] afterMethods = testClass.getAfterTestMethods();42 Assert.assertEquals(afterMethods.length, 1);43 Assert.assertEquals(afterMethods[0].getMethodName(), "afterMethodRun");44 }45 private ITestClass runTestWithDefaultMethods() {46 TestNG tng = create(TestA.class);47 TestClassListener listener = new TestClassListener();48 tng.addListener(listener);49 tng.run();50 return listener.testClass;51 }52 public static class TestClassListener extends TestAndClassListener {53 private ITestClass testClass;54 @Override55 public void onBeforeClass(ITestClass testClass) {56 this.testClass = testClass;57 }58 }59}...

Full Screen

Full Screen

Source:ITestResultNotifier.java Github

copy

Full Screen

1package org.testng.internal;2import java.util.List;3import java.util.Set;4import org.testng.IConfigurationListener;5import org.testng.ITestListener;6import org.testng.ITestNGMethod;7import org.testng.ITestResult;8import org.testng.xml.XmlTest;9/**10 * An interface defining the notification for @Test results and also11 * \@Configuration results.12 *13 * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>14 * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>15 */16public interface ITestResultNotifier {17 Set<ITestResult> getPassedTests(ITestNGMethod tm);18 Set<ITestResult> getFailedTests(ITestNGMethod tm);19 Set<ITestResult> getSkippedTests(ITestNGMethod tm);20 void addPassedTest(ITestNGMethod tm, ITestResult tr);21 void addSkippedTest(ITestNGMethod tm, ITestResult tr);22 void addFailedTest(ITestNGMethod tm, ITestResult tr);23 void addFailedButWithinSuccessPercentageTest(ITestNGMethod tm, ITestResult tr);24 void addInvokedMethod(InvokedMethod im);25 XmlTest getTest();26 List<ITestListener> getTestListeners();27 List<IConfigurationListener> getConfigurationListeners();28}...

Full Screen

Full Screen

Interface ITest

Using AI Code Generation

copy

Full Screen

1import org.testng.ITest;2import org.testng.ITestResult;3import org.testng.ITestListener;4import org.testng.IRetryAnalyzer;5import org.testng.IAnnotationTransformer;6import org.testng.IAnnotationTransformer2;7import org.testng.IMethodInterceptor;8import org.testng.IClassListener;9import org.testng.IClassInterceptor;10import org.testng.ITestAnnotation;11import org.testng.IAlterSuiteListener;12import org.testng.IAlterSuiteListener2;13import org.testng.IHookable;14import org.testng.IExecutionListener;15import org.testng.ISuiteListener;16import org.testng.IConfigurable;17import org.testng.IDataProviderListener;18import org.testng.IDataProviderMethod;19import org.testng.IAttributes;20import org.testng.IDataProvider;21import org.testng.IDataProviderInterceptor;22import org.testng.ITestNGMethod;23import org.testng.ITestContext;24import org.testng.ITest

Full Screen

Full Screen

Interface ITest

Using AI Code Generation

copy

Full Screen

1public interface ITest {2 public String getTestName();3 public long getStartMillis();4 public long getEndMillis();5 public void setTestName(String testName);6 public void setStartMillis(long startMillis);7 public void setEndMillis(long endMillis);8}9package org.testng;10import java.lang.reflect.Method;11import java.util.Map;12import org.testng.internal.Utils;13public class TestNGMethod implements ITest {14 private final Method m_method;15 private final ITestClass m_testClass;16 private final boolean m_isAlwaysRun;17 private final String m_description;18 private final String m_testName;19 private final String m_groupName;20 private final String[] m_groups;21 private final String[] m_groupsDependedUpon;22 private final String[] m_methodsDependedUpon;23 private final boolean m_isBeforeMethodConfiguration;24 private final boolean m_isAfterMethodConfiguration;25 private final boolean m_isBeforeClassConfiguration;26 private final boolean m_isAfterClassConfiguration;27 private final boolean m_isBeforeTestConfiguration;28 private final boolean m_isAfterTestConfiguration;

Full Screen

Full Screen

Interface ITest

Using AI Code Generation

copy

Full Screen

1import org.testng.ITest;2import org.testng.ITestResult;3import org.testng.TestListenerAdapter;4public class TestListener extends TestListenerAdapter {5 public void onTestStart(ITestResult result) {6 super.onTestStart(result);7 System.out.println("Test started");8 }9 public void onTestSuccess(ITestResult tr) {10 super.onTestSuccess(tr);11 System.out.println("Test Success");12 }13 public void onTestFailure(ITestResult tr) {14 super.onTestFailure(tr);15 System.out.println("Test Failure");16 }17 public void onTestSkipped(ITestResult tr) {18 super.onTestSkipped(tr);19 System.out.println("Test Skipped");20 }21 public void onTestFailedButWithinSuccessPercentage(ITestResult tr) {22 super.onTestFailedButWithinSuccessPercentage(tr);23 System.out.println("Test Failed but within success percentage");24 }25 public void onStart(ITestContext testContext) {26 super.onStart(testContext);27 System.out.println("Test Started");28 }29 public void onFinish(ITestContext testContext) {30 super.onFinish(testContext);31 System.out.println("Test Finished");32 }33}34import org.testng.annotations.Test;35public class Test {36 public void test1() {37 System.out.println("Test 1");38 }39 public void test2() {40 System.out.println("Test 2");41 }42 public void test3() {

Full Screen

Full Screen

Interface ITest

Using AI Code Generation

copy

Full Screen

1import org.testng.ITest;2import org.testng.ITestResult;3import org.testng.annotations.Test;4public class TestNGITest implements ITest {5 private String m_testName = null;6 public String getTestName() {7 return m_testName;8 }9 public void setTestName(String testName) {10 m_testName = testName;11 }12 public void f() {13 }14 public void g() {15 }16 public void h() {17 }18 public void i() {19 }20 public void j() {21 }22 public void k() {23 }24 public void l() {25 }26 public void m() {27 }28 public void n() {29 }30 public void o() {31 }32 public void p() {33 }34 public void q() {35 }36 public void r() {37 }38 public void s() {39 }40 public void t() {41 }42 public void u() {43 }44 public void v() {45 }46 public void w() {47 }48 public void x() {49 }50 public void y() {51 }52 public void z() {53 }

Full Screen

Full Screen

Interface ITest

Using AI Code Generation

copy

Full Screen

1package testng;2import org.testng.ITest;3import org.testng.ITestResult;4import org.testng.annotations.Test;5public class TestNGITestTest implements ITest {6 private String testname;7 public void testMethod1() {8 System.out.println("TestNG ITest Test");9 }10 public String getTestName() {11 return testname;12 }13 public void setTestName(String testname) {14 this.testname = testname;15 }16 public long getStartMillis() {17 return 0;18 }19 public long getEndMillis() {20 return 0;21 }22 public ITestResult getTestResult() {23 return null;24 }25}

Full Screen

Full Screen
copy
1POSIX syntax Java syntax23[[:Lower:]] \p{Lower}4[[:Upper:]] \p{Upper}5[[:ASCII:]] \p{ASCII}6[[:Alpha:]] \p{Alpha}7[[:Digit:]] \p{Digit}8[[:Alnum:]] \p{Alnum}9[[:Punct:]] \p{Punct}10[[:Graph:]] \p{Graph}11[[:Print:]] \p{Print}12[[:Blank:]] \p{Blank}13[[:Cntrl:]] \p{Cntrl}14[[:XDigit:]] \p{XDigit}15[[:Space:]] \p{Space}16
Full Screen
copy
1 compile 'com.squareup.retrofit2:retrofit:2.1.0'2
Full Screen
copy
1ext.retrofit2Version = '2.4.0' -> '2.6.0'2implementation"com.squareup.retrofit2:retrofit:$retrofit2Version"3implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2Version"4implementation "com.squareup.retrofit2:converter-gson:$retrofit2Version"5
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.

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Interface-ITest

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful