How to use ListenerManager class of com.paypal.selion.configuration package

Best SeLion code snippet using com.paypal.selion.configuration.ListenerManager

Source:SeleniumGridListener.java Github

copy

Full Screen

...41import com.paypal.selion.configuration.Config;42import com.paypal.selion.configuration.ConfigManager;43import com.paypal.selion.configuration.Initializer;44import com.paypal.selion.configuration.ListenerInfo;45import com.paypal.selion.configuration.ListenerManager;46import com.paypal.selion.internal.reports.runtimereport.JsonRuntimeReporterHelper;47import com.paypal.selion.internal.utils.InvokedMethodInformation;48import com.paypal.selion.internal.utils.TestNGUtils;49import com.paypal.selion.logger.SeLionLogger;50import com.paypal.selion.platform.grid.Grid;51import com.paypal.selion.reports.runtime.SeLionReporter;52import com.paypal.selion.reports.services.ConfigSummaryData;53import com.paypal.selion.reports.services.ReporterConfigMetadata;54import com.paypal.test.utilities.logging.SimpleLogger;55/**56 * Contains the logic that will take care of all the selenium related57 */58public class SeleniumGridListener implements IInvokedMethodListener, ISuiteListener, ITestListener {59 /**60 * This String constant represents the JVM argument that can be used to enable/disable {@link SeleniumGridListener}61 */62 public static final String ENABLE_GRID_LISTENER = "enable.grid.listener";63 private static SimpleLogger logger = SeLionLogger.getLogger();64 public SeleniumGridListener() {65 ListenerManager.registerListener(new ListenerInfo(this.getClass(), ENABLE_GRID_LISTENER));66 }67 /**68 * 69 * Identifies which version and name of browser to start if it specified in &#064;webtest <br>70 * <b>sample</b><br>71 * 72 * &#064;webtest(<b>browser="*firefox"</b>)<br>73 * 74 * @see org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)75 */76 @Override77 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {78 logger.entering(new Object[] { method, testResult });79 try {80 if (ListenerManager.isCurrentMethodSkipped(this)) {81 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);82 return;83 }84 // For non-session sharing, we only allow our annotation(s) on @Test methods.85 // When this condition is true, we allow the session be created.86 if (!method.isTestMethod() && !isSeLionAnnotatedTestClass(method)) {87 return;88 }89 // For session sharing, we only allow our annotation on the class.90 // In this case the session can only be created in the @Test with the highest priority (first test, smallest91 // number) or in a @BeforeClass92 if (isSeLionAnnotatedTestClass(method)) {93 if (!isValidBeforeCondition(method)) {94 return;95 }96 // For session sharing, we need to ensure @Test methods are priority based.97 if (method.isTestMethod()) {98 // we need to ensure each @Test method is annotated99 if (isLowPriority(method)) {100 // For session sharing tests, Need to create new session only for Test (Web or Mobile) with101 // highest priority (first test, smallest number) in the class.102 testSessionSharingRules(method);103 } else {104 return;105 }106 }107 }108 // Abort if there is already an instance of AbstractTestSession at this point.109 if (Grid.getTestSession() != null) {110 return;111 }112 AbstractTestSession testSession = TestSessionFactory.newInstance(method);113 Grid.getThreadLocalTestSession().set(testSession);114 InvokedMethodInformation methodInfo = TestNGUtils.getInvokedMethodInformation(method, testResult);115 testSession.initializeTestSession(methodInfo);116 if (!(testSession instanceof BasicTestSession)) {117 // BasicTestSession are non selenium tests. So no need to start the Local hub.118 try {119 LocalGridManager.spawnLocalHub(testSession);120 } catch (NoClassDefFoundError e) {121 logger.log(Level.SEVERE, "You are trying to run a local server but are missing Jars. Do you have "122 + "SeLion-Grid and Selenium-Server in your CLASSPATH?", e);123 // No sense in continuing ... SELENIUM_RUN_LOCALLY is a global config property124 System.exit(1); // NOSONAR125 }126 }127 } catch (Exception e) { // NOSONAR128 if (e instanceof RuntimeException) {129 throw e;130 }131 // convert the checked exception into a runtime exception.132 throw new RuntimeException(e.getMessage(), e);133 }134 logger.exiting();135 }136 private boolean isSeLionAnnotatedTestClass(IInvokedMethod method) {137 Class<?> cls = method.getTestMethod().getInstance().getClass();138 final boolean isWebTestClass = cls.getAnnotation(WebTest.class) != null;139 final boolean isMobileTestClass = cls.getAnnotation(MobileTest.class) != null;140 return isMobileTestClass || isWebTestClass;141 }142 private boolean isValidBeforeCondition(IInvokedMethod method) {143 if (method.isTestMethod()) {144 return true;145 }146 return method.getTestMethod().isBeforeClassConfiguration();147 }148 private void testSessionSharingRules(IInvokedMethod method) {149 Test t = method.getTestMethod().getInstance().getClass().getAnnotation(Test.class);150 if (t != null && t.singleThreaded()) {151 if (!isPriorityUnique(method)) {152 throw new IllegalStateException(153 "All the session sharing test methods within the same class should have a unique priority.");154 } else {155 return;156 }157 }158 throw new IllegalStateException(159 "Session sharing test should have a class level @Test annotation with the property singleThreaded = true defined.");160 }161 private boolean isLowPriority(IInvokedMethod method) {162 int low = method.getTestMethod().getPriority();163 for (ITestNGMethod test : method.getTestMethod().getTestClass().getTestMethods()) {164 // ensures all test methods have the @Test annotation. Throw exception if that's not the case165 if (!isAnnotatedWithTest(test.getConstructorOrMethod().getMethod())) {166 throw new IllegalStateException(167 "Session sharing requires all test methods to define a priority via the @Test annotation.");168 }169 if (test.getEnabled() && test.getPriority() < low) {170 return false;171 }172 }173 Test t = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class);174 // If there is an existing session and the test method has a DP then don't create a session175 // For a data driven test method with the first data the session must be created176 // Hence return true if currentInvocationCount is 1 otherwise utilize the same session177 // by returning false178 int currentInvocationCount = method.getTestMethod().getCurrentInvocationCount();179 if (!t.dataProvider().isEmpty()) {180 return currentInvocationCount == 0;181 }182 return true;183 }184 private boolean isHighPriority(IInvokedMethod method) {185 if (!isAnnotatedWithTest(method)) {186 // Abort. There will already be an exception thrown in isLowPriority for this case.187 return true;188 }189 int high = method.getTestMethod().getPriority();190 for (ITestNGMethod test : method.getTestMethod().getTestClass().getTestMethods()) {191 if (test.getEnabled() && test.getPriority() > high) {192 return false;193 }194 }195 Test t = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class);196 // For a test method with a data provider197 if (!(t.dataProvider().isEmpty())) {198 int currentInvocationCount = method.getTestMethod().getCurrentInvocationCount();199 int parameterInvocationCount = method.getTestMethod().getParameterInvocationCount();200 // If the data set from the data provider is exhausted201 // It means its the last method with the data provider- this is the exit condition202 return (currentInvocationCount == parameterInvocationCount);203 }204 return true;205 }206 private boolean isAnnotatedWithTest(IInvokedMethod method) {207 return isAnnotatedWithTest(method.getTestMethod().getConstructorOrMethod().getMethod());208 }209 private boolean isAnnotatedWithTest(Method method) {210 Test t = method.getAnnotation(Test.class);211 return t != null;212 }213 private boolean isPriorityUnique(IInvokedMethod method) {214 // Logic to check priorities of all test methods are unique. This is used in Session Sharing.215 Set<Integer> check = new HashSet<Integer>();216 int length = method.getTestMethod().getTestClass().getTestMethods().length;217 int expectedSize = 0;218 for (int i = 0; i < length; i++) {219 //ignore @Test(enabled = false) methods220 if (!method.getTestMethod().getTestClass().getTestMethods()[i].getEnabled()) {221 continue;222 }223 check.add(method.getTestMethod().getTestClass().getTestMethods()[i].getPriority());224 expectedSize += 1;225 if (check.size() != expectedSize) {226 return false;227 }228 }229 return true;230 }231 /**232 * Executes when test case is finished<br>233 * 234 * Identify if webtest wants to have session open, otherwise close session<br>235 * <b>sample</b><br>236 * &#064;webtest(browser="*firefox", <b>keepSessionOpen = true</b>)<br>237 * Analyzes failure if any238 * 239 * @see org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)240 * 241 */242 @Override243 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {244 logger.entering(new Object[] { method, testResult });245 try {246 if (ListenerManager.isCurrentMethodSkipped(this)) {247 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);248 return;249 }250 // Abort at this point, if there is no AbstractTestSession instance.251 if (Grid.getTestSession() == null) {252 return;253 }254 // For non-session sharing, we only allow our annotation(s) on @Test methods.255 // When this condition is true, we allow the session to be closed.256 if (!method.isTestMethod() && !isSeLionAnnotatedTestClass(method)) {257 return;258 }259 // For session sharing, we only allow our annotation on the class.260 // In this case the session can only be closed in the @Test with the lowest priority (last test, biggest261 // number) or in an @AfterClass262 if (isSeLionAnnotatedTestClass(method)) {263 if (!isValidAfterCondition(method)) {264 return;265 }266 if (method.isTestMethod() && hasValidAfterCondition(method)) {267 return;268 }269 if (method.isTestMethod() && !isHighPriority(method)) {270 // For session sharing tests, Need to close session only for Test (Web or Mobile) with highest271 // priority (last test) in the class.272 return;273 }274 }275 // let's attempt to capture a screenshot in case of failure from Selenium or SeLion PageObject276 // or when there was an assertion failure.277 // That way a user can see the how the page looked like when a test failed.278 if (testResult.getStatus() == ITestResult.FAILURE279 && (testResult.getThrowable() instanceof WebDriverException ||280 testResult.getThrowable() instanceof AssertionError)) {281 warnUserOfTestFailures(testResult);282 }283 AbstractTestSession testSession = Grid.getTestSession();284 testSession.closeSession();285 testResult.setAttribute(JsonRuntimeReporterHelper.IS_COMPLETED, true);286 } catch (Exception e) { // NOSONAR287 logger.log(Level.WARNING, "An error occurred while processing afterInvocation: " + e.getMessage(), e);288 }289 logger.exiting();290 }291 private boolean isValidAfterCondition(IInvokedMethod method) {292 return method.isTestMethod() || method.getTestMethod().isAfterClassConfiguration();293 }294 private boolean hasValidAfterCondition(IInvokedMethod method) {295 return method.getTestMethod().getTestClass().getAfterClassMethods().length > 0;296 }297 private void warnUserOfTestFailures(ITestResult testResult) {298 // don't bother if we don't have a session299 if (!Grid.getTestSession().isStarted()) {300 return;301 }302 // don't bother if we don't have a web or mobile test session303 if (!(Grid.getTestSession() instanceof MobileTestSession) &&304 !(Grid.getTestSession() instanceof WebTestSession)) {305 return;306 }307 String errMsg = "";308 if (testResult.getThrowable() != null) {309 errMsg = testResult.getThrowable().getMessage();310 }311 if (StringUtils.isEmpty(errMsg)) {312 errMsg = "Test Failure screenshot";313 }314 SeLionReporter.log(errMsg, true, true);315 logger.info("Please review the test report for the screenshot at the time of failure.");316 }317 /**318 * Initiate config on suite start319 * 320 * @see org.testng.ISuiteListener#onStart(org.testng.ISuite)321 */322 @Override323 public void onStart(ISuite suite) {324 logger.entering(suite);325 if (ListenerManager.isCurrentMethodSkipped(this)) {326 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);327 return;328 }329 // Nothing should query for SeLionConfig values before this point.330 Config.initConfig(suite);331 ConfigSummaryData.initConfigSummary();332 ReporterConfigMetadata.initReporterMetadata();333 // Printing the JVM information.334 // This info will help us when it comes to debugging issues on fusion335 // a typical output will be as below336 // 13:42:04.312 INFO - JDK Information: Java HotSpot(TM) 64-Bit Server VM from Oracle Corporation VM ver.337 // 23.7-b01338 RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();339 String jdkInfo = runtime.getVmName() + " from " + runtime.getSpecVendor() + " ver. "340 + System.getProperty("java.version");341 logger.info("JDK Information: " + jdkInfo);342 logger.exiting();343 }344 /**345 * Generates and returns output directory string path346 * 347 * @param base348 * String shows path to the suiteName349 * @param suiteName350 * String suiteName specified by config file351 * @return String - path to output directory for that particular suite352 */353 public static String filterOutputDirectory(String base, String suiteName) {354 logger.entering(new Object[] { base, suiteName });355 int index = base.lastIndexOf(suiteName);356 String outputFolderWithoutName = base.substring(0, index);357 logger.exiting(outputFolderWithoutName + File.separator);358 return outputFolderWithoutName + File.separator;359 }360 /**361 * Closes selenium session when suite finished to run362 * 363 * @see org.testng.ISuiteListener#onFinish(org.testng.ISuite)364 */365 @Override366 public void onFinish(ISuite suite) {367 logger.entering(suite);368 if (ListenerManager.isCurrentMethodSkipped(this)) {369 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);370 return;371 }372 LocalGridManager.shutDownHub();373 logger.exiting();374 }375 /**376 * 377 * @see org.testng.ISuiteListener#onFinish(org.testng.ISuite)378 */379 @Override380 public void onFinish(ITestContext context) {381 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.382 // Failing to do so can have un-predictable results.383 if (ListenerManager.isCurrentMethodSkipped(this)) {384 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);385 return;386 }387 }388 /**389 * On start each suite initialize config object and report object390 */391 @Override392 public void onStart(ITestContext context) {393 logger.entering(context);394 if (ListenerManager.isCurrentMethodSkipped(this)) {395 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);396 return;397 }398 String testName = context.getCurrentXmlTest().getName();399 // initializing the ConfigSummaryData before initializers so that config details can be added.400 ConfigSummaryData.initLocalConfigSummary(testName);401 // We have to ensure that our configuration is the first thing that gets loaded.402 // Our loading mechanism is going to be via listeners. But the problem with TestNG listeners is403 // that the order of loading is never guaranteed. Things become complicated if our downstream consumers404 // want to piggy back on our configuration and want to have their configurations loaded as well.405 // Because of all these issues, we cannot rely on building a config specific listener.406 // So we are relying on the ServiceLoaders in Java to do it for us. The moment we are here, we ensure that407 // not only the SeLion specific configurations are loaded, but all downstream consumer's configurations408 // are loaded as well along with us. So SeLion now becomes the single point of initialization and thus409 // does away with all the inherent setbacks that are associated with TestNG listeners orders.410 invokeInitializersBasedOnPriority(context);411 ConfigManager.printConfiguration(testName);412 ISuite suite = context.getSuite();413 if (!suite.getParallel().equals("false") && logger.isLoggable(Level.FINE)) {414 logger.log(Level.FINE, "Parallel suite execution. Updating SeLion local config for Test, "415 + context.getCurrentXmlTest().getName());416 }417 String base = suite.getOutputDirectory();418 String suiteName = suite.getName();419 String rootFolder = filterOutputDirectory(base, suiteName);420 SeLionReporter.setTestNGOutputFolder(rootFolder);421 SeLionReporter.init();422 logger.exiting();423 }424 @Override425 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {426 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.427 // Failing to do so can have un-predictable results.428 if (ListenerManager.isCurrentMethodSkipped(this)) {429 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);430 return;431 }432 }433 @Override434 public void onTestFailure(ITestResult result) {435 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.436 // Failing to do so can have un-predictable results.437 if (ListenerManager.isCurrentMethodSkipped(this)) {438 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);439 return;440 }441 }442 @Override443 public void onTestSkipped(ITestResult result) {444 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.445 // Failing to do so can have un-predictable results.446 if (ListenerManager.isCurrentMethodSkipped(this)) {447 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);448 return;449 }450 }451 @Override452 public void onTestStart(ITestResult result) {453 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.454 // Failing to do so can have un-predictable results.455 if (ListenerManager.isCurrentMethodSkipped(this)) {456 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);457 }458 }459 @Override460 public void onTestSuccess(ITestResult result) {461 // Below conditional check needs to be invoked in all TestNG Listener interface implementation.462 // Failing to do so can have un-predictable results.463 if (ListenerManager.isCurrentMethodSkipped(this)) {464 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);465 }466 }467 /**468 * This method facilitates initialization of all configurations from the current project as well as downstream469 * consumers.470 * 471 * @param context472 */473 private void invokeInitializersBasedOnPriority(ITestContext context) {474 ServiceLoader<Initializer> serviceLoader = ServiceLoader.load(Initializer.class);475 List<AbstractConfigInitializer> loader = new ArrayList<AbstractConfigInitializer>();476 for (Initializer l : serviceLoader) {477 loader.add((AbstractConfigInitializer) l);478 }...

Full Screen

Full Screen

Source:RuntimeReporterListener.java Github

copy

Full Screen

...21import org.testng.ITestListener;22import org.testng.ITestResult;23import com.paypal.selion.annotations.DoNotReport;24import com.paypal.selion.configuration.ListenerInfo;25import com.paypal.selion.configuration.ListenerManager;26import com.paypal.selion.logger.SeLionLogger;27import com.paypal.test.utilities.logging.SimpleLogger;28/**29 * RuntimeReporter is a listener which gets invoked when a test method or configuration method starts or completed.30 * 31 */32public class RuntimeReporterListener implements ISuiteListener, ITestListener, IConfigurationListener {33 private String outputDirectory;34 private final JsonRuntimeReporterHelper jsonHelper;35 /**36 * This String constant represents the JVM argument that can be enabled/disabled to enable/disable37 * {@link RuntimeReporterListener}38 */39 public static final String ENABLE_RUNTIME_REPORTER_LISTENER = "enable.runtime.reporter.listener";40 boolean bInitConfig;41 private static SimpleLogger logger = SeLionLogger.getLogger();42 public RuntimeReporterListener() {43 // Lets register this listener with the ListenerManager44 ListenerManager.registerListener(new ListenerInfo(this.getClass(), ENABLE_RUNTIME_REPORTER_LISTENER));45 jsonHelper = new JsonRuntimeReporterHelper();46 }47 /**48 * Update the test results to the JSON helper which will feed the data to HTML and JSON report.49 * 50 * @param result51 */52 private void updateTestDetails(ITestResult result) {53 if (!ListenerManager.executeCurrentMethod(this)) {54 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);55 return;56 }57 logger.entering(result);58 if (result.getMethod().getConstructorOrMethod().getMethod().getAnnotation(DoNotReport.class) != null) {59 return;60 }61 String fullClassName = result.getTestClass().getName();62 String className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);63 String packageName = "default";64 if (fullClassName.contains(".")) {65 packageName = fullClassName.substring(0, fullClassName.lastIndexOf('.'));66 }67 jsonHelper.insertTestMethod(result.getTestContext().getSuite().getName(), result.getTestContext()68 .getCurrentXmlTest().getName(), packageName, className, result);69 jsonHelper.writeJSON(outputDirectory, false);70 logger.exiting();71 }72 /**73 * Update the configuration results to the JSON helper which will feed the data to HTML and JSON report.74 * 75 * @param result76 */77 private void updateConfigDetails(ITestResult result) {78 if (!ListenerManager.executeCurrentMethod(this)) {79 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);80 return;81 }82 logger.entering(result);83 if (result.getMethod().getConstructorOrMethod().getMethod().getAnnotation(DoNotReport.class) != null) {84 return;85 }86 String fullClassName = result.getTestClass().getName();87 String className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);88 String packageName = "default";89 if (fullClassName.contains(".")) {90 packageName = fullClassName.substring(0, fullClassName.lastIndexOf('.'));91 }92 jsonHelper.insertConfigMethod(result.getTestContext().getSuite().getName(), result.getTestContext()93 .getCurrentXmlTest().getName(), packageName, className, result);94 jsonHelper.writeJSON(outputDirectory, false);95 logger.exiting();96 }97 @Override98 public void onStart(ISuite suite) {99 logger.entering(suite);100 if (!ListenerManager.executeCurrentMethod(this)) {101 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);102 return;103 }104 if (!bInitConfig) {105 bInitConfig = true;106 File outFile = new File(suite.getOutputDirectory());107 outputDirectory = outFile.getParent() + File.separator + "RuntimeReporter";108 logger.info("Runtime Report : " + outputDirectory + File.separator + "index.html");109 RuntimeReportResourceManager resourceMgr = new RuntimeReportResourceManager();110 resourceMgr.copyResources(outFile.getParent());111 }112 logger.exiting();113 }114 @Override115 public void onFinish(ISuite suite) {116 logger.entering(suite);117 if (!ListenerManager.executeCurrentMethod(this)) {118 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);119 return;120 }121 jsonHelper.writeJSON(outputDirectory, true);122 logger.exiting();123 }124 @Override125 public void onConfigurationSuccess(ITestResult itr) {126 updateConfigDetails(itr);127 }128 @Override129 public void onConfigurationFailure(ITestResult itr) {130 updateConfigDetails(itr);131 }132 @Override133 public void onConfigurationSkip(ITestResult itr) {134 updateConfigDetails(itr);135 }136 @Override137 public void onTestStart(ITestResult result) {138 updateTestDetails(result);139 }140 @Override141 public void onTestSuccess(ITestResult result) {142 updateTestDetails(result);143 }144 @Override145 public void onTestFailure(ITestResult result) {146 updateTestDetails(result);147 }148 @Override149 public void onTestSkipped(ITestResult result) {150 updateTestDetails(result);151 }152 @Override153 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {154 updateTestDetails(result);155 }156 @Override157 public void onStart(ITestContext context) {158 if (!ListenerManager.executeCurrentMethod(this)) {159 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);160 return;161 }162 logger.entering(context);163 jsonHelper.generateLocalConfigSummary(context.getSuite().getName(), context.getCurrentXmlTest().getName());164 }165 @Override166 public void onFinish(ITestContext context) {167 }168}...

Full Screen

Full Screen

Source:SeLionAssertsListener.java Github

copy

Full Screen

...18import org.testng.IInvokedMethodListener;19import org.testng.ITestResult;20import org.testng.Reporter;21import com.paypal.selion.configuration.ListenerInfo;22import com.paypal.selion.configuration.ListenerManager;23import com.paypal.selion.logger.SeLionLogger;24import com.paypal.selion.platform.asserts.SeLionSoftAssert;25import com.paypal.test.utilities.logging.SimpleLogger;26/**27 * <code>SeLionAssertsListener</code> holds all the test level logic for SeLion asserts.28 */29public class SeLionAssertsListener implements IInvokedMethodListener {30 private static SimpleLogger logger = SeLionLogger.getLogger();31 /**32 * This String constant represents the JVM argument that can be enabled/disabled to enable/disable33 * {@link SeLionAssertsListener}34 */35 public static final String ENABLE_ASSERTS_LISTENER = "enable.asserts.listener";36 public SeLionAssertsListener() {37 ListenerManager.registerListener(new ListenerInfo(this.getClass(), ENABLE_ASSERTS_LISTENER));38 }39 @Override40 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {41 logger.entering(new Object[] { method, testResult });42 try {43 if (ListenerManager.isCurrentMethodSkipped(this)) {44 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);45 return;46 }47 // Initialize soft asserts for this test method instance.48 SeLionSoftAssert softAsserts = new SeLionSoftAssert();49 testResult.setAttribute(SeLionSoftAssert.SOFT_ASSERT_ATTRIBUTE_NAME, softAsserts);50 } catch (Exception e) { // NOSONAR51 logger.log(Level.WARNING, "An error occurred while processing beforeInvocation: " + e.getMessage(), e);52 }53 }54 @Override55 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {56 logger.entering(new Object[] { method, testResult });57 try {58 if (ListenerManager.isCurrentMethodSkipped(this)) {59 logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG);60 return;61 }62 // Assert all the soft asserts captured as part of this test method instance.63 if (Reporter.getCurrentTestResult() != null) {64 SeLionSoftAssert sa = (SeLionSoftAssert) Reporter.getCurrentTestResult().getAttribute(65 SeLionSoftAssert.SOFT_ASSERT_ATTRIBUTE_NAME);66 if (sa != null) {67 sa.assertAll();68 }69 }70 } catch (Exception e) { // NOSONAR71 logger.log(Level.WARNING, "An error occurred while processing afterInvocation: " + e.getMessage(), e);72 }73 }...

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.configuration.ListenerManager;2import org.testng.ITestContext;3import org.testng.ITestListener;4import org.testng.ITestResult;5public class ListenerManagerTest implements ITestListener {6 public void onStart(ITestContext context) {7 }8 public void onFinish(ITestContext context) {9 }10 public void onTestStart(ITestResult result) {11 }12 public void onTestSuccess(ITestResult result) {13 }14 public void onTestFailure(ITestResult result) {15 }16 public void onTestSkipped(ITestResult result) {17 }18 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {19 }20}21import com.paypal.selion.configuration.ListenerManager;22import org.testng.ITestContext;23import org.testng.ITestListener;24import org.testng.ITestResult;25public class ListenerManagerTest implements ITestListener {26 public void onStart(ITestContext context) {27 }28 public void onFinish(ITestContext context) {29 }30 public void onTestStart(ITestResult result) {31 }32 public void onTestSuccess(ITestResult result) {33 }34 public void onTestFailure(ITestResult result) {35 }36 public void onTestSkipped(ITestResult result) {37 }38 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {39 }40}41import com

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.configuration;2import java.util.ArrayList;3import java.util.List;4import org.testng.ITestContext;5import org.testng.ITestListener;6import org.testng.ITestResult;7import org.testng.annotations.Listeners;8@Listeners({ ListenerManager.class })9public class ListenerManager implements ITestListener {10 private static List<ITestListener> listeners = new ArrayList<ITestListener>();11 public static void registerListener(ITestListener listener) {12 if (listener != null) {13 listeners.add(listener);14 }15 }16 public void onTestStart(ITestResult result) {17 for (ITestListener listener : listeners) {18 listener.onTestStart(result);19 }20 }21 public void onTestSuccess(ITestResult result) {22 for (ITestListener listener : listeners) {23 listener.onTestSuccess(result);24 }25 }26 public void onTestFailure(ITestResult result) {27 for (ITestListener listener : listeners) {28 listener.onTestFailure(result);29 }30 }31 public void onTestSkipped(ITestResult result) {32 for (ITestListener listener : listeners) {33 listener.onTestSkipped(result);34 }35 }36 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {37 for (ITestListener listener : listeners) {38 listener.onTestFailedButWithinSuccessPercentage(result);39 }40 }41 public void onStart(ITestContext context) {42 for (ITestListener listener : listeners) {43 listener.onStart(context);44 }45 }46 public void onFinish(ITestContext context) {47 for (ITestListener listener : listeners) {48 listener.onFinish(context);49 }50 }51}52package com.paypal.selion.configuration;53import org.testng.ITestContext;54import org.testng.ITestListener;55import org.testng.ITestResult;56public class MyTestListener implements ITestListener {57 public void onTestStart(ITestResult result) {58 System.out.println("on test start");59 }60 public void onTestSuccess(ITestResult result) {61 System.out.println("on test success");62 }63 public void onTestFailure(ITestResult result) {

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.configuration.ListenerManager;2import com.paypal.selion.configuration.ListenerManager.ListenerType;3import com.paypal.selion.configuration.ListenerManager.ListenerType;4import com.paypal.selion.platform.grid.Grid;5import com.paypal.selion.platform.grid.GridManagerFactory;6public class ListenerManagerExample {7public static void main(String[] args) {8ListenerManager listenerManager = ListenerManager.getInstance();9listenerManager.addListener(ListenerType.SELENIUM, new MyListener());10listenerManager.addListener(ListenerType.SELENIUM, new MyListener2());11listenerManager.removeListener(ListenerType.SELENIUM, new MyListener());12listenerManager.getAllListeners(ListenerType.SELENIUM);13listenerManager.getAllListenerTypes();14}15}16import com.paypal.selion.configuration.ListenerManager;17import com.paypal.selion.configuration.ListenerManager.ListenerType;18import com.paypal.selion.configuration.ListenerManager.ListenerType;19import com.paypal.selion.platform.grid.Grid;20import com.paypal.selion.platform.grid.GridManagerFactory;21public class ListenerManagerExample {22public static void main(String[] args) {23ListenerManager listenerManager = ListenerManager.getInstance();24listenerManager.addListener(ListenerType.SELENIUM, new MyListener());25listenerManager.addListener(ListenerType.SELENIUM, new MyListener2());26listenerManager.removeListener(ListenerType.SELENIUM, new MyListener());27listenerManager.getAllListeners(ListenerType.SELENIUM);28listenerManager.getAllListenerTypes();29}30}31import com.paypal.selion.configuration.ListenerManager;32import com.paypal.selion.configuration.ListenerManager.ListenerType;33import com.paypal.selion.configuration.ListenerManager.ListenerType;34import com.paypal.selion.platform.grid.Grid;35import com.paypal.selion.platform.grid.GridManagerFactory;36public class ListenerManagerExample {37public static void main(String[] args) {38ListenerManager listenerManager = ListenerManager.getInstance();39listenerManager.addListener(ListenerType.SELENIUM, new MyListener());

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1import org.testng.annotations.Test;2import org.testng.Assert;3import org.testng.AssertJUnit;4import com.paypal.selion.configuration.ListenerManager;5import com.paypal.selion.configuration.ListenerManager.ListenerType;6import com.paypal.selion.platform.grid.Grid;7import com.paypal.selion.platform.grid.GridManagerFactory;8import com.paypal.selion.platform.html.WebPage;9import com.paypal.selion.platform.utilities.WebDriverWaitUtils;10import com.paypal.selion.testcomponents.BasicPageImpl;11public class ListenerManagerTest {12 public void testListenerManager() {13 Grid grid = GridManagerFactory.getGridManager().getThreadLocalGrid();14 grid.addPage("basicPage", new BasicPageImpl());15 WebPage page = grid.getPage("basicPage");16 ListenerManager.addListener(ListenerType.MOBILE, "com.paypal.selion.testcomponents.MobilePageImpl");17 ListenerManager.addListener(ListenerType.MOBILE, "com.paypal.selion.testcomponents.MobilePageImpl");18 ListenerManager.addListener(ListenerType.TABLET, "com.paypal.selion.testcomponents.TabletPageImpl");19 ListenerManager.addListener(ListenerType.TABLET, "com.paypal.selion.testcomponents.TabletPageImpl");20 ListenerManager.addListener(ListenerType.DESKTOP, "com.paypal.selion.testcomponents.DesktopPageImpl");21 ListenerManager.addListener(ListenerType.DESKTOP, "com.paypal.selion.testcomponents.DesktopPageImpl");22 WebDriverWaitUtils.waitUntilElementIsVisible(page.getLocator("loginButton"));23 AssertJUnit.assertTrue(page.isElementPresent("loginButton"));24 }25}26 at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80)27 at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:229)28 at com.paypal.selion.platform.utilities.WebDriverWaitUtils.waitUntilElementIsVisible(WebDriverWaitUtils.java:50)29 at com.paypal.selion.platform.utilities.WebDriverWaitUtils.waitUntilElementIsVisible(WebDriverWaitUtils.java:45)30 at com.paypal.selion.platform.utilities.WebDriverWaitUtils.waitUntilElementIsVisible(WebDriverWaitUtils.java:40)

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.examples;2import java.io.File;3import java.io.IOException;4import java.util.ArrayList;5import java.util.List;6import java.util.Map;7import java.util.Map.Entry;8import org.apache.commons.io.FileUtils;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.FindBy;12import org.openqa.selenium.support.How;13import org.testng.Assert;14import org.testng.annotations.Test;15import com.paypal.selion.annotations.WebTest;16import com.paypal.selion.configuration.ListenerManager;17import com.paypal.selion.internal.platform.grid.WebDriverPlatform;18import com.paypal.selion.platform.grid.Grid;19import com.paypal.selion.platform.html.Button;20import com.paypal.selion.platform.html.CheckBox;21import com.paypal.selion.platform.html.CheckBoxSet;22import com.paypal.selion.platform.html.Dropdown;23import com.paypal.selion.platform.html.Image;24import com.paypal.selion.platform.html.Label;25import com.paypal.selion.platform.html.Link;26import com.paypal.selion.platform.html.ListItem;27import com.paypal.selion.platform.html.ListItemSet;28import com.paypal.selion.platform.html.RadioButton;29import com.paypal.selion.platform.html.RadioButtonSet;30import com.paypal.selion.platform.html.SelectList;31import com.paypal.selion.platform.html.TextField;32import com.paypal.selion.platform.html.impl.ButtonImpl;33import com.paypal.selion.platform.html.impl.CheckBoxImpl;34import com.paypal.selion.platform.html.impl.CheckBoxSetImpl;35import com.paypal.selion.platform.html.impl.DropdownImpl;36import com.paypal.selion.platform.html.impl.ImageImpl;37import com.paypal.selion.platform.html.impl.LabelImpl;38import com.paypal.selion.platform.html.impl.LinkImpl;39import com.paypal.selion.platform.html.impl.ListItemImpl;40import com.paypal.selion.platform.html.impl.ListItemSetImpl;41import com.paypal.selion.platform.html.impl.RadioButtonImpl;42import com.paypal.selion.platform.html.impl.RadioButtonSetImpl;43import com.paypal.selion.platform.html.impl.SelectListImpl;44import com.paypal.selion.platform.html.impl.TextFieldImpl;45import com.paypal.selion.platform.utilities.WebDriverWaitUtils;46import com.paypal.selion.reports.runtime.SeLionReporter;47import com.paypal.selion.testcomponents.BasicPageImpl;48import com.paypal.selion.testcomponents.ForgotPasswordPage;49import com.paypal.selion.testcomponents.HomePage;50import com.paypal.selion.testcomponents.Home

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1package com.paypal.selion.configuration;2import org.testng.annotations.Test;3public class ListenerManagerTest {4 public void testListenerManager() {5 ListenerManager manager = ListenerManager.getInstance();6 manager.addListener(new ListenerManagerTestListener());7 manager.addListener(new ListenerManagerTestListener());8 manager.removeListener(new ListenerManagerTestListener());9 manager.removeListener(new ListenerManagerTestListener());10 }11}12package com.paypal.selion.configuration;13import org.testng.annotations.Test;14public class ListenerManagerTest {15 public void testListenerManager() {16 ListenerManager manager = ListenerManager.getInstance();17 manager.addListener(new ListenerManagerTestListener());18 manager.removeListener(new ListenerManagerTestListener());19 }20}21package com.paypal.selion.configuration;22import org.testng.annotations.Test;23public class ListenerManagerTest {24 public void testListenerManager() {25 ListenerManager manager = ListenerManager.getInstance();26 manager.addListener(new ListenerManagerTestListener());27 manager.removeListener(new ListenerManagerTestListener());28 manager.removeListener(new ListenerManagerTestListener());29 }30}31package com.paypal.selion.configuration;32import org.testng.annotations.Test;33public class ListenerManagerTest {34 public void testListenerManager() {35 ListenerManager manager = ListenerManager.getInstance();36 manager.addListener(new ListenerManagerTestListener());37 manager.removeListener(new ListenerManagerTestListener());38 manager.removeListener(new ListenerManagerTestListener());39 manager.removeListener(new ListenerManagerTestListener());40 }41}42package com.paypal.selion.configuration;43import org.testng.annotations.Test;44public class ListenerManagerTest {45 public void testListenerManager() {46 ListenerManager manager = ListenerManager.getInstance();47 manager.addListener(new ListenerManagerTestListener());48 manager.addListener(new ListenerManagerTestListener());49 manager.addListener(new ListenerManagerTestListener());50 manager.addListener(new ListenerManagerTestListener());51 }52}53package com.paypal.selion.configuration;54import org

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1ListenerManager.addListener(new MyListener());2ListenerManager.addListener(new MyListener2());3ListenerManager.addListener(new MyListener3());4ListenerManager.addListener(new MyListener4());5ListenerManager.addListener(new MyListener());6ListenerManager.addListener(new MyListener2());7ListenerManager.addListener(new MyListener3());8ListenerManager.addListener(new MyListener4());9ListenerManager.addListener(new MyListener());10ListenerManager.addListener(new MyListener2());11ListenerManager.addListener(new MyListener3());12ListenerManager.addListener(new MyListener4());13ListenerManager.addListener(new MyListener());14ListenerManager.addListener(new MyListener2());15ListenerManager.addListener(new MyListener3());16ListenerManager.addListener(new MyListener4());17ListenerManager.addListener(new MyListener());18ListenerManager.addListener(new MyListener2());19ListenerManager.addListener(new MyListener3());20ListenerManager.addListener(new MyListener4());21ListenerManager.addListener(new MyListener());22ListenerManager.addListener(new MyListener2());23ListenerManager.addListener(new MyListener3());24ListenerManager.addListener(new MyListener4());25ListenerManager.addListener(new MyListener());26ListenerManager.addListener(new MyListener2());27ListenerManager.addListener(new MyListener3());28ListenerManager.addListener(new MyListener4());29ListenerManager.addListener(new MyListener());30ListenerManager.addListener(new MyListener2());31ListenerManager.addListener(new MyListener3());32ListenerManager.addListener(new MyListener4());33ListenerManager.addListener(new MyListener());34ListenerManager.addListener(new MyListener2());35ListenerManager.addListener(new MyListener3());36ListenerManager.addListener(new MyListener4());37ListenerManager.addListener(new MyListener());38ListenerManager.addListener(new MyListener2());39ListenerManager.addListener(new MyListener3());40ListenerManager.addListener(new MyListener4());41ListenerManager.addListener(new MyListener());42ListenerManager.addListener(new MyListener2());

Full Screen

Full Screen

ListenerManager

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.configuration.ListenerManager;2import org.testng.annotations.Test;3public class ListenerManagerTest {4 public void testListenerManager() {5 ListenerManager.registerListener(new MyListener());6 }7}8import com.paypal.selion.configuration.ListenerManager;9import org.testng.annotations.Test;10public class ListenerManagerTest {11 public void testListenerManager() {12 ListenerManager.registerListener(new MyListener());13 }14}15import com.paypal.selion.configuration.ListenerManager;16import org.testng.annotations.Test;17public class ListenerManagerTest {18 public void testListenerManager() {19 ListenerManager.registerListener(new MyListener());20 }21}22import com.paypal.selion.configuration.ListenerManager;23import org.testng.annotations.Test;24public class ListenerManagerTest {25 public void testListenerManager() {26 ListenerManager.registerListener(new MyListener());27 }28}29import com.paypal.selion.configuration.ListenerManager;30import org.testng.annotations.Test;31public class ListenerManagerTest {32 public void testListenerManager() {33 ListenerManager.registerListener(new MyListener());34 }35}36import com.paypal.selion.configuration.ListenerManager;37import org.testng.annotations.Test;38public class ListenerManagerTest {39 public void testListenerManager() {40 ListenerManager.registerListener(new MyListener());41 }42}43import com.paypal.selion.configuration.ListenerManager;44import org.testng.annotations.Test;45public class ListenerManagerTest {46 public void testListenerManager() {47 ListenerManager.registerListener(new MyListener());48 }49}50import com.paypal.selion.configuration.ListenerManager;51import org.testng.annotations.Test

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeLion automation tests on LambdaTest cloud grid

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

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