How to use CarinaListener method of com.qaprosoft.carina.core.foundation.listeners.CarinaListener class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.listeners.CarinaListener.CarinaListener

Source:CarinaListener.java Github

copy

Full Screen

...92import com.zebrunner.agent.core.registrar.maintainer.ChainedMaintainerResolver;93import com.zebrunner.agent.core.webdriver.RemoteWebDriverFactory;94import com.zebrunner.agent.testng.core.testname.TestNameResolverRegistry;95/*96 * CarinaListener - base carina-core TestNG Listener.97 *98 * @author Vadim Delendik99 */100public class CarinaListener extends AbstractTestListener implements ISuiteListener, IQTestManager, ITestRailManager, IClassListener {101 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());102 protected static final long EXPLICIT_TIMEOUT = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);103 protected static final String SUITE_TITLE = "%s%s%s - %s (%s)";104 protected static final String XML_SUITE_NAME = " (%s)";105 protected static boolean automaticDriversCleanup = true;106 107 protected boolean isRunLabelsRegistered = false;108 109 110 private static final Pattern S3_BUCKET_PATTERN = Pattern.compile("s3:\\/\\/([a-zA-Z-0-9][^\\/]*)\\/(.*)");111 private static final Pattern AZURE_CONTAINER_PATTERN = Pattern.compile("\\/\\/([a-z0-9]{3,24})\\.blob.core.windows.net\\/(?:(\\$root|(?:[a-z0-9](?!.*--)[a-z0-9-]{1,61}[a-z0-9]))\\/)?(.{1,1024})");112 // appcenter://appName/platformName/buildType/version113 private static final Pattern APPCENTER_PATTERN = Pattern.compile(114 "appcenter:\\/\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)\\/([a-zA-Z-0-9][^\\/]*)");115 public CarinaListener() {116 // Add shutdown hook117 Runtime.getRuntime().addShutdownHook(new ShutdownHook());118 // Zebrunner core java agent is user for capturing events of RemoteDriverSession instances.119 // Internally, the agent uses java instrumentation agent for its purposes.120 // The instrumentation agent implicitly triggers initialization of the R class because it uses logger.121 // Carina has the ThreadLogAppender class which is closely related to logging and internally uses the R class.122 // Technically, this happen when the maven-surefire-plugin has not set inherited program arguments (passed to mvn process).123 // That is why it is necessary to reinit R class here when TestNG loads the CarinaListener class.124 R.reinit();125 126 LOGGER.info(Configuration.asString());127 // Configuration.validateConfiguration();128 try {129 L10N.load();130 } catch (Exception e) {131 LOGGER.error("L10N bundle is not initialized successfully!", e);132 }133 // declare global capabilities in configuration if custom_capabilities is declared134 String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);135 if (!customCapabilities.isEmpty()) {136 // redefine core CONFIG properties using global custom capabilities file137 new CapabilitiesLoader().loadCapabilities(customCapabilities);138 }139 // declare global capabilities from Zebrunner Launcher if any140 Capabilities zebrunnerCapabilities = RemoteWebDriverFactory.getCapabilities();141 if (!zebrunnerCapabilities.asMap().isEmpty()) {142 // redefine core CONFIG properties using caps from Zebrunner launchers143 new CapabilitiesLoader().loadCapabilities(zebrunnerCapabilities);144 }145 IScreenshotRule autoScreenshotsRule = (IScreenshotRule) new AutoScreenshotRule();146 Screenshot.addScreenshotRule(autoScreenshotsRule);147 TestNameResolverRegistry.set(new ZebrunnerNameResolver());148 CompositeLabelResolver.addResolver(new TagManager());149 CompositeLabelResolver.addResolver(new PriorityManager());150 ReportContext.getBaseDir(); // create directory for logging as soon as possible151 }152 @Override153 public void onStart(ISuite suite) {154 LOGGER.debug("CarinaListener->onStart(ISuite suite)");155 // first means that ownership/maintainer resolver from carina has higher priority156 ChainedMaintainerResolver.addFirst(new Ownership(suite.getParameter("suiteOwner")));157 if (!"INFO".equalsIgnoreCase(Configuration.get(Parameter.CORE_LOG_LEVEL))) {158 LoggerContext ctx = (LoggerContext) LogManager.getContext(this.getClass().getClassLoader(), false);159 org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration();160 // make sure to update after moving to "com.zebrunner"161 LoggerConfig logger = config.getLoggerConfig("com.qaprosoft.carina.core");162 logger.setLevel(Level.getLevel(Configuration.get(Parameter.CORE_LOG_LEVEL)));163 }164 updateAppPath();165 166 setThreadCount(suite);167 168 if (Configuration.getPlatform().equalsIgnoreCase(SpecialKeywords.API)) {169 CurrentTestRun.setPlatform(SpecialKeywords.API);170 }171 String mobileApp = Configuration.getMobileApp();172 if (!mobileApp.isEmpty()) {173 // [VD] do not move into the static block as Zebrunner reporting need registered test run!174 Artifact.attachReferenceToTestRun("app", mobileApp);175 }176 // register app_version/build as artifact if available...177 Configuration.setBuild(Configuration.get(Parameter.APP_VERSION));178 179 String sha1 = Configuration.get(Parameter.GIT_HASH);180 if (!sha1.isEmpty()) {181 Label.attachToTestRun("sha1", sha1);182 }183 184 /*185 * To support multi-suite declaration as below we have to init test run labels at once only!186 * <suite-files>187 * <suite-file path="suite1.xml"/>188 * <suite-file path="suite2.xml"/>189 * </suite-files>190 */191 192 if (!this.isRunLabelsRegistered) {193 attachTestRunLabels(suite);194 this.isRunLabelsRegistered = true;195 }196 LOGGER.info("CARINA_CORE_VERSION: " + getCarinaVersion());197 }198 @Override199 public void onStart(ITestContext context) {200 LOGGER.debug("CarinaListener->OnTestStart(ITestContext context): " + context.getName());201 super.onStart(context);202 }203 @Override204 public void beforeConfiguration(ITestResult result) {205 LOGGER.debug("CarinaListener->beforeConfiguration");206 super.beforeConfiguration(result);207 // remember active test phase to organize valid driver pool manipulation208 // process209 if (result.getMethod().isBeforeSuiteConfiguration()) {210 TestPhase.setActivePhase(Phase.BEFORE_SUITE);211 }212 if(result.getMethod().isBeforeTestConfiguration()){213 TestPhase.setActivePhase(Phase.BEFORE_TEST);214 }215 if (result.getMethod().isBeforeClassConfiguration()) {216 TestPhase.setActivePhase(Phase.BEFORE_CLASS);217 }218 if (result.getMethod().isBeforeMethodConfiguration()) {219 TestPhase.setActivePhase(Phase.BEFORE_METHOD);220 }221 if (result.getMethod().isAfterMethodConfiguration()) {222 TestPhase.setActivePhase(Phase.AFTER_METHOD);223 }224 if (result.getMethod().isAfterClassConfiguration()) {225 TestPhase.setActivePhase(Phase.AFTER_CLASS);226 }227 if (result.getMethod().isAfterTestConfiguration()){228 TestPhase.setActivePhase(Phase.AFTER_TEST);229 }230 if (result.getMethod().isAfterSuiteConfiguration()) {231 TestPhase.setActivePhase(Phase.AFTER_SUITE);232 }233 }234 @Override235 public void onConfigurationFailure(ITestResult result) {236 LOGGER.debug("CarinaListener->onConfigurationFailure");237 super.onConfigurationFailure(result);238 }239 @Override240 public void onTestStart(ITestResult result) {241 LOGGER.debug("CarinaListener->onTestStart");242 TestPhase.setActivePhase(Phase.METHOD);243 // handle expected skip244 Method testMethod = result.getMethod().getConstructorOrMethod().getMethod();245 if (ExpectedSkipManager.getInstance().isSkip(testMethod, result.getTestContext())) {246 skipExecution("Based on rule listed above");247 }248 super.onTestStart(result);249 }250 @Override251 public void onTestSuccess(ITestResult result) {252 LOGGER.debug("CarinaListener->onTestSuccess");253 onTestFinish(result);254 super.onTestSuccess(result);255 }256 @Override257 public void onTestFailure(ITestResult result) {258 LOGGER.debug("CarinaListener->onTestFailure");259 takeScreenshot();260 onTestFinish(result);261 super.onTestFailure(result);262 }263 @Override264 public void onTestSkipped(ITestResult result) {265 LOGGER.debug("CarinaListener->onTestSkipped");266 takeScreenshot();267 onTestFinish(result);268 super.onTestSkipped(result);269 }270 private boolean hasDependencies(ITestResult result) {271 String methodName = result.getMethod().getMethodName();272 String className = result.getMethod().getTestClass().getName();273 // analyze all suite methods and return true if any of them depends on274 // existing method275 List<ITestNGMethod> methods = result.getTestContext().getSuite().getAllMethods();276 for (ITestNGMethod method : methods) {277 List<String> dependencies = Arrays.asList(method.getMethodsDependedUpon());278 if (dependencies.contains(methodName) ||279 dependencies.contains(className + "." + methodName)) {280 LOGGER.debug("dependency detected for " + methodName);281 return true;282 }283 }284 return false;285 }286 private void onTestFinish(ITestResult result) {287 try {288 // clear all kind of temporary properties289 R.CONFIG.clearTestProperties();290 R.TESTDATA.clearTestProperties();291 R.DATABASE.clearTestProperties();292 R.EMAIL.clearTestProperties();293 R.REPORT.clearTestProperties();294 R.ZAFIRA.clearTestProperties();295 LOGGER.debug("Test result is : " + result.getStatus());296 // result status == 2 means failure, status == 3 means skip. We need to quit driver anyway for failure and skip297 if ((automaticDriversCleanup && !hasDependencies(result)) || result.getStatus() == 2 || result.getStatus() == 3) {298 if (!Configuration.getBoolean(Parameter.FORCIBLY_DISABLE_DRIVER_QUIT)) {299 quitDrivers(Phase.BEFORE_METHOD, Phase.METHOD);300 }301 }302 attachTestLabels(result);303 } catch (Exception e) {304 LOGGER.error("Exception in CarinaListener->onTestFinish!", e);305 }306 }307 @Override308 public void onAfterClass(ITestClass testClass){309 LOGGER.debug("CarinaListener->onAfterClass(ITestClass testClass)");310 quitDrivers(Phase.BEFORE_CLASS);311 }312 @Override313 public void onFinish(ITestContext context) {314 LOGGER.debug("CarinaListener->onFinish(ITestContext context)");315 super.onFinish(context);316 // [SZ] it's still needed to close driver from BeforeClass stage.317 // Otherwise it could be potentially used in other test classes 318// quitDrivers(Phase.BEFORE_CLASS); already exited in onAfterClass() method319 quitDrivers(Phase.BEFORE_TEST);320 LOGGER.debug("CarinaListener->onFinish(context): " + context.getName());321 }322 @Override323 public void onFinish(ISuite suite) {324 LOGGER.debug("CarinaListener->onFinish(ISuite suite)");325 try {326 String browser = getBrowser();327 // String suiteName = getSuiteName(context);328 String title = getTitle(suite.getXmlSuite());329 TestResultType testResult = EmailReportGenerator.getSuiteResult(EmailReportItemCollector.getTestResults());330 String status = testResult.getName();331 title = status + ": " + title;332 String env = "";333 if (!Configuration.isNull(Parameter.ENV)) {334 env = Configuration.get(Parameter.ENV);335 }336 if (!Configuration.get(Parameter.URL).isEmpty()) {337 env += " - <a href='" + Configuration.get(Parameter.URL) + "'>" + Configuration.get(Parameter.URL)338 + "</a>";339 }340 ReportContext.getTempDir().delete();341 // EmailReportItemCollector.getTestResults());342 LOGGER.debug("Generating email report...");343 // Generate emailable html report using regular method344 EmailReportGenerator report = new EmailReportGenerator(title, env, Configuration.get(Parameter.APP_VERSION),345 browser, DateUtils.now(), EmailReportItemCollector.getTestResults(),346 EmailReportItemCollector.getCreatedItems());347 String emailContent = report.getEmailBody();348 // Store emailable report under emailable-report.html349 ReportContext.generateHtmlReport(emailContent);350 printExecutionSummary(EmailReportItemCollector.getTestResults());351 LOGGER.debug("Finish email report generation.");352 } catch (Exception e) {353 LOGGER.error("Exception in CarinaListener->onFinish(ISuite suite)", e);354 }355 }356 /**357 * Disable automatic drivers cleanup after each TestMethod and switch to controlled by tests itself.358 * But anyway all drivers will be closed forcibly as only suite is finished or aborted 359 */360 public static void disableDriversCleanup() {361 LOGGER.info("Automatic drivers cleanup will be disabled!");362 automaticDriversCleanup = false;363 }364 protected String getBrowser() {365 return Configuration.getBrowser();366 }367 protected String getTitle(XmlSuite suite) {368 String browser = getBrowser();369 if (!browser.isEmpty()) {370 browser = " " + browser; // insert the space before371 }372 String env = !Configuration.isNull(Parameter.ENV) ? Configuration.get(Parameter.ENV)373 : Configuration.get(Parameter.URL);374 String title = "";375 String app_version = "";376 if (!Configuration.get(Parameter.APP_VERSION).isEmpty()) {377 // if nothing is specified then title will contain nothing378 app_version = Configuration.get(Parameter.APP_VERSION) + " - ";379 }380 String suiteName = getSuiteName(suite);381 String xmlFile = getSuiteFileName(suite);382 title = String.format(SUITE_TITLE, app_version, suiteName, String.format(XML_SUITE_NAME, xmlFile), env, browser);383 return title;384 }385 private String getSuiteFileName(XmlSuite suite) {386 // TODO: investigate why we need such method and suite file name at all387 String fileName = suite.getFileName();388 if (fileName == null) {389 fileName = "undefined";390 }391 LOGGER.debug("Full suite file name: " + fileName);392 if (fileName.contains("\\")) {393 fileName = fileName.replaceAll("\\\\", "/");394 }395 fileName = StringUtils.substringAfterLast(fileName, "/");396 LOGGER.debug("Short suite file name: " + fileName);397 return fileName;398 }399 protected String getSuiteName(XmlSuite suite) {400 String suiteName = "";401 if (suite != null && !"Default suite".equals(suite.getName())) {402 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? suite.getName()403 : Configuration.get(Parameter.SUITE_NAME);404 } else {405 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? R.EMAIL.get("title")406 : Configuration.get(Parameter.SUITE_NAME);407 }408 return suiteName;409 }410 private void printExecutionSummary(List<TestResultItem> tris) {411 Messager.INFORMATION.info("**************** Test execution summary ****************");412 int num = 1;413 for (TestResultItem tri : tris) {414 String failReason = tri.getFailReason();415 if (failReason == null) {416 failReason = "";417 }418 if (!tri.isConfig()) {419 String reportLinks = !StringUtils.isEmpty(tri.getLinkToScreenshots())420 ? "screenshots=" + tri.getLinkToScreenshots() + " | " : "";421 reportLinks += !StringUtils.isEmpty(tri.getLinkToLog()) ? "log=" + tri.getLinkToLog() : "";422 Messager.TEST_RESULT.info(String.valueOf(num++), tri.getTest(), tri.getResult().toString(),423 reportLinks);424 }425 }426 }427 @Deprecated428 protected void putS3Artifact(String key, String path) {429 AmazonS3Manager.getInstance().put(Configuration.get(Parameter.S3_BUCKET_NAME), key, path);430 }431 @Deprecated432 protected S3Object getS3Artifact(String bucket, String key) {433 return AmazonS3Manager.getInstance().get(Configuration.get(Parameter.S3_BUCKET_NAME), key);434 }435 @Deprecated436 protected S3Object getS3Artifact(String key) {437 return getS3Artifact(Configuration.get(Parameter.S3_BUCKET_NAME), key);438 }439 @Deprecated440 protected void putAzureArtifact(String remotePath, String localPath) {441 AzureManager.getInstance().put(Configuration.get(Parameter.AZURE_CONTAINER_NAME), remotePath, localPath);442 }443 @Deprecated444 protected void getAzureArtifact(String bucket, String remotePath, File localPath) {445 AzureManager.getInstance().download(bucket, remotePath, localPath);446 }447 private static void updateAppPath() {448 449 String mobileAppPath = Configuration.getMobileApp();450 Matcher matcher = S3_BUCKET_PATTERN.matcher(mobileAppPath);451 LOGGER.debug("Analyzing if mobile app is located on S3...");452 if (matcher.find()) {453 mobileAppPath = updateS3AppPath(mobileAppPath);454 }455 matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);456 LOGGER.debug("Analyzing if mobile app is located on Azure...");457 if (matcher.find()) {458 mobileAppPath = updateAzureAppPath(mobileAppPath);459 }460 461 matcher = APPCENTER_PATTERN.matcher(mobileAppPath);462 LOGGER.debug("Analyzing if mobile_app is located on AppCenter...");463 if (matcher.find()) {464 mobileAppPath = updateAppCenterAppPath(mobileAppPath);465 }466 467 if (!mobileAppPath.isEmpty()) {468 Configuration.setMobileApp(mobileAppPath);469 }470 }471 /**472 * Method to update MOBILE_APP path in case if apk is located in Hockey App.473 */474 private static String updateAppCenterAppPath(String mobileAppPath) {475 Matcher matcher = APPCENTER_PATTERN.matcher(mobileAppPath);476 if (matcher.find()) {477 LOGGER.info("app artifact is located on AppCenter...");478 String appName = matcher.group(1);479 String platformName = matcher.group(2);480 String buildType = matcher.group(3);481 String version = matcher.group(4);482 //TODO: test if generated appcenter download url is valid483 mobileAppPath = AppCenterManager.getInstance().getDownloadUrl(appName, platformName, buildType,484 version);485 } else {486 LOGGER.error("Unable to parse '{}' path using AppCenter pattern", mobileAppPath);487 }488 return mobileAppPath;489 }490 /**491 * Method to update MOBILE_APP path in case if apk is located in s3 bucket.492 */493 private static String updateS3AppPath(String mobileAppPath) {494 // get app path to be sure that we need(do not need) to download app495 // from s3 bucket496 Matcher matcher = S3_BUCKET_PATTERN.matcher(mobileAppPath);497 if (matcher.find()) {498 LOGGER.info("app artifact is located on s3...");499 String bucketName = matcher.group(1);500 String key = matcher.group(2);501 Pattern pattern = Pattern.compile(key);502 // analyze if we have any pattern inside mobile_app to make extra503 // search in AWS504 int position = key.indexOf(".*");505 if (position > 0) {506 // /android/develop/dfgdfg.*/Mapmyrun.apk507 int slashPosition = key.substring(0, position).lastIndexOf("/");508 if (slashPosition > 0) {509 key = key.substring(0, slashPosition);510 S3ObjectSummary lastBuild = AmazonS3Manager.getInstance().getLatestBuildArtifact(bucketName, key,511 pattern);512 key = lastBuild.getKey();513 }514 } else {515 key = AmazonS3Manager.getInstance().get(bucketName, key).getKey();516 }517 LOGGER.info("next s3 app key will be used: " + key);518 // generate presign url explicitly to register link as run artifact519 long hours = 72L*1000*60*60; // generate presigned url for nearest 3 days520 mobileAppPath = AmazonS3Manager.getInstance().generatePreSignUrl(bucketName, key, hours).toString();521 } else {522 LOGGER.error("Unable to parse '{}' path using S3 pattern", mobileAppPath);523 }524 525 return mobileAppPath;526 }527 /**528 * Method to update MOBILE_APP path in case if apk is located in Azure storage.529 */530 private static String updateAzureAppPath(String mobileAppPath) {531 Matcher matcher = AZURE_CONTAINER_PATTERN.matcher(mobileAppPath);532 if (matcher.find()) {533 LOGGER.info("app artifact is located on Azure...");534 String accountName = matcher.group(1);535 String containerName = matcher.group(2) == null ? "$root" : matcher.group(2);536 String remoteFilePath = matcher.group(3);537 LOGGER.info(538 "Account: " + accountName + "\n" +539 "Container: " + containerName + "\n" +540 "RemotePath: " + remoteFilePath + "\n"541 );542 R.CONFIG.put(Parameter.AZURE_ACCOUNT_NAME.getKey(), accountName);543 BlobProperties blobProperties = AzureManager.getInstance().get(containerName, remoteFilePath);544 String azureLocalStorage = Configuration.get(Parameter.AZURE_LOCAL_STORAGE);545 String localFilePath = azureLocalStorage + File.separator + StringUtils.substringAfterLast(remoteFilePath, "/");546 File file = new File(localFilePath);547 try {548 // verify requested artifact by checking the checksum549 if (file.exists() && FileManager.getFileChecksum(FileManager.Checksum.MD5, file).equals(Base64.encodeBase64String(blobProperties.getContentMd5()))) {550 LOGGER.info("build artifact with the same checksum already downloaded: " + file.getAbsolutePath());551 } else {552 LOGGER.info(553 String.format("Following data was extracted: container: %s, remotePath: %s, local file: %s",554 containerName, remoteFilePath, file.getAbsolutePath())555 );556 AzureManager.getInstance().download(containerName, remoteFilePath, file);557 }558 } catch (Exception exception) {559 LOGGER.error("Azure app path update exception detected!", exception);560 }561 mobileAppPath = file.getAbsolutePath();562 // try to redefine app_version if it's value is latest or empty563 String appVersion = Configuration.get(Parameter.APP_VERSION);564 if (appVersion.equals("latest") || appVersion.isEmpty()) {565 Configuration.setBuild(file.getName());566 }567 } else {568 LOGGER.error("Unable to parse '{}' path using Azure pattern", mobileAppPath);569 }570 571 return mobileAppPath;572 }573 protected void skipExecution(String message) {574 CurrentTest.revertRegistration();575 throw new SkipException(message);576 }577 /*578 * Parse TestNG <suite ...> tag and return any attribute579 * @param ISuite suite580 * @param IString attribute581 * @return String attribute value or empty string582 *583 */584 private String getAttributeValue(ISuite suite, String attribute) {585 String res = "";586 587 if (suite.getXmlSuite() == null || suite.getXmlSuite().getFileName() == null) {588 // #1514 Unable to execute the test classes from maven command line589 return res;590 }591 592 File file = new File(suite.getXmlSuite().getFileName());593 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();594 documentBuilderFactory.setValidating(false);595 documentBuilderFactory.setNamespaceAware(true);596 try {597 documentBuilderFactory.setFeature("http://xml.org/sax/features/namespaces", false);598 documentBuilderFactory.setFeature("http://xml.org/sax/features/validation", false);599 documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);600 documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);601 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();602 Document document = documentBuilder.parse(file);603 for (int i = 0; i < document.getChildNodes().getLength(); i++) {604 NamedNodeMap nodeMapAttributes = document.getChildNodes().item(i).getAttributes();605 if (nodeMapAttributes == null) {606 continue;607 }608 // get "name" from suite element609 // <suite verbose="1" name="Carina Demo Tests - API Sample" thread-count="3" >610 Node nodeName = nodeMapAttributes.getNamedItem("name");611 if (nodeName == null) {612 continue;613 }614 if (suite.getName().equals(nodeName.getNodeValue())) {615 // valid suite node detected616 Node nodeAttribute = nodeMapAttributes.getNamedItem(attribute);617 if (nodeAttribute != null) {618 res = nodeAttribute.getNodeValue();619 break;620 }621 }622 }623 } catch (Exception e) {624 LOGGER.warn("Unable to get attribute '" + attribute +"' from suite: " + suite.getXmlSuite().getFileName(), e);625 }626 return res;627 }628 private void setThreadCount(ISuite suite) {629 //Reuse default thread-count value from suite TestNG file if it is not overridden in _config.properties630 /*631 * WARNING! We coudn't override default thread-count="5" and data-provider-thread-count="10"!632 * suite.getXmlSuite().toXml() add those default values anyway even if the absent in suite xml file declaraton.633 * To make possible to parse correctly we had to reuse external parser and private getAttributeValue634 */635 636 if (Configuration.getThreadCount()>= 1) {637 // use thread-count from config.properties638 suite.getXmlSuite().setThreadCount(Configuration.getThreadCount());639 LOGGER.debug("Updated thread-count=" + suite.getXmlSuite().getThreadCount());640 } else {641 String suiteThreadCount = getAttributeValue(suite, "thread-count");642 LOGGER.debug("thread-count from suite: " + suiteThreadCount);643 if (suiteThreadCount.isEmpty()) {644 LOGGER.info("Set thread-count=1");645 R.CONFIG.put(Parameter.THREAD_COUNT.getKey(), "1");646 suite.getXmlSuite().setThreadCount(1);647 } else {648 // reuse value from suite xml file649 LOGGER.debug("Synching thread-count with values from suite xml file...");650 R.CONFIG.put(Parameter.THREAD_COUNT.getKey(), suiteThreadCount);651 LOGGER.info("Use thread-count='" + suite.getXmlSuite().getThreadCount() + "' from suite file.");652 }653 }654 if (Configuration.getDataProviderThreadCount() >= 1) {655 // use thread-count from config.properties656 suite.getXmlSuite().setDataProviderThreadCount(Configuration.getDataProviderThreadCount());657 LOGGER.debug("Updated data-provider-thread-count=" + suite.getXmlSuite().getDataProviderThreadCount());658 } else {659 String suiteDataProviderThreadCount = getAttributeValue(suite, "data-provider-thread-count");660 LOGGER.debug("data-provider-thread-count from suite: " + suiteDataProviderThreadCount);661 if (suiteDataProviderThreadCount.isEmpty()) {662 LOGGER.info("Set data-provider-thread-count=1");663 R.CONFIG.put(Parameter.DATA_PROVIDER_THREAD_COUNT.getKey(), "1");664 suite.getXmlSuite().setDataProviderThreadCount(1);665 } else {666 // reuse value from suite xml file667 LOGGER.debug("Synching data-provider-thread-count with values from suite xml file...");668 R.CONFIG.put(Parameter.DATA_PROVIDER_THREAD_COUNT.getKey(), suiteDataProviderThreadCount);669 LOGGER.info("Use data-provider-thread-count='" + suite.getXmlSuite().getDataProviderThreadCount() + "' from suite file.");670 }671 }672 }673 private String getCarinaVersion() {674 String carinaVersion = "";675 try {676 Class<CarinaListener> theClass = CarinaListener.class;677 String classPath = theClass.getResource(theClass.getSimpleName() + ".class").toString();678 LOGGER.debug("Class: " + classPath);679 Pattern pattern = Pattern.compile(".*\\/(.*)\\/.*!");680 Matcher matcher = pattern.matcher(classPath);681 if (matcher.find()) {682 carinaVersion = matcher.group(1);683 }684 } catch (Exception e) {685 LOGGER.debug(e.getMessage(), e);686 }687 return carinaVersion;688 }689 private void attachTestLabels(ITestResult result) {690 // register testrail cases......

Full Screen

Full Screen

Source:IAbstractTest.java Github

copy

Full Screen

...23import org.testng.annotations.BeforeSuite;24import org.testng.annotations.DataProvider;25import com.nordstrom.automation.testng.LinkedListeners;26import com.qaprosoft.carina.core.foundation.dataprovider.core.DataProviderFactory;27import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;28import com.qaprosoft.carina.core.foundation.listeners.FilterTestsListener;29import com.qaprosoft.carina.core.foundation.report.testrail.ITestCases;30import com.qaprosoft.carina.core.foundation.utils.Configuration;31import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;32import com.qaprosoft.carina.core.foundation.utils.common.CommonUtils;33import com.qaprosoft.carina.core.foundation.utils.factory.ICustomTypePageFactory;34import com.zebrunner.agent.core.registrar.CurrentTest;35import com.zebrunner.agent.testng.listener.TestRunListener;36/*37 * IAbstractTest - base test for UI and API tests.38 */39// https://github.com/zebrunner/carina/issues/95140// reused com.nordstrom.tools.testng-foundation to register ordered listeners41// on start order is FilterTestsListener, TestRunListener and CarinaListener42// on finish reverse order, i.e. CarinaListener, TestRunListener and FilterTestsListener43@LinkedListeners({ CarinaListener.class, TestRunListener.class, FilterTestsListener.class })44public interface IAbstractTest extends ICustomTypePageFactory, ITestCases {45 long EXPLICIT_TIMEOUT = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);46 @BeforeSuite(alwaysRun = true)47 private void onCarinaBeforeSuite() {48 // do nothing49 }50 @BeforeClass(alwaysRun = true)51 private void onCarinaBeforeClass() {52 // do nothing53 }54 @BeforeMethod(alwaysRun = true)55 private void onCarinaBeforeMethod() {56 // do nothing57 }...

Full Screen

Full Screen

Source:AbstractTest.java Github

copy

Full Screen

1package com.solvd.practiceqa;2import com.nordstrom.automation.testng.LinkedListeners;3import com.qaprosoft.carina.core.foundation.IAbstractTest;4import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;5import com.qaprosoft.carina.core.foundation.listeners.CarinaListenerChain;6import com.qaprosoft.carina.core.foundation.listeners.FilterTestsListener;7import com.solvd.practiceqa.web.service.ConfigService;8import com.solvd.practiceqa.web.service.TestDataService;9import com.solvd.practiceqa.web.service.TestListener;10import com.zebrunner.agent.testng.listener.TestRunListener;11import org.testng.annotations.BeforeSuite;12import org.testng.annotations.Listeners;13import org.testng.internal.annotations.ListenersAnnotation;14@LinkedListeners({ CarinaListener.class, TestRunListener.class, FilterTestsListener.class })15@Listeners(TestListener.class)16public abstract class AbstractTest implements IAbstractTest {17 protected ListenersAnnotation listenersAnnotation;18 protected CarinaListenerChain listener;19 @BeforeSuite20 public void beforeSuite() {21 ConfigService.createInstance();22 TestDataService.createInstance();23 listenersAnnotation = new ListenersAnnotation();24 listener = new CarinaListenerChain();25 listener.transform(listenersAnnotation, AbstractTest.class);26 }27}...

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.listeners;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.ITestResult;5public class CarinaListener implements IInvokedMethodListener {6 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {7 System.out.println("beforeInvocation method");8 }9 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {10 System.out.println("afterInvocation method");11 }12}13package com.qaprosoft.carina.core.foundation.listeners;14import org.testng.IInvokedMethod;15import org.testng.IInvokedMethodListener;16import org.testng.ITestResult;17public class CarinaListener implements IInvokedMethodListener {18 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {19 System.out.println("beforeInvocation method");20 }21 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {22 System.out.println("afterInvocation method");23 }24}25package com.qaprosoft.carina.core.foundation.listeners;26import org.testng.IInvokedMethod;27import org.testng.IInvokedMethodListener;28import org.testng.ITestResult;29public class CarinaListener implements IInvokedMethodListener {30 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {31 System.out.println("beforeInvocation method");32 }33 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {34 System.out.println("afterInvocation method");35 }36}37package com.qaprosoft.carina.core.foundation.listeners;38import org.testng.IInvokedMethod;39import org.testng.IInvokedMethodListener;40import org.testng.ITestResult;41public class CarinaListener implements IInvokedMethodListener {42 public void beforeInvocation(IInvokedMethod method, ITestResult test

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1public void beforeMethod(ITestResult result) {2 CarinaListener cl = new CarinaListener();3 cl.onTestStart(result);4}5public void afterMethod(ITestResult result) {6 CarinaListener cl = new CarinaListener();7 cl.onTestSuccess(result);8}9public void afterMethod(ITestResult result) {10 CarinaListener cl = new CarinaListener();11 cl.onTestFailure(result);12}13public void afterMethod(ITestResult result) {14 CarinaListener cl = new CarinaListener();15 cl.onTestSkipped(result);16}17public void afterMethod(ITestResult result) {18 CarinaListener cl = new CarinaListener();19 cl.onTestFailure(result);20}21public void afterMethod(ITestResult result) {22 CarinaListener cl = new CarinaListener();23 cl.onTestFailedButWithinSuccessPercentage(result);24}25public void afterMethod(ITestResult result) {26 CarinaListener cl = new CarinaListener();27 cl.onTestFailedWithTimeout(result);28}29public void afterMethod(ITestResult result) {30 CarinaListener cl = new CarinaListener();31 cl.onConfigurationFailure(result);32}33public void afterMethod(ITestResult result) {34 CarinaListener cl = new CarinaListener();35 cl.onConfigurationSkip(result);36}

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1import org.testng.annotations.Listeners;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;4@Listeners(CarinaListener.class)5public class 1 {6public void test() {7System.out.println("Test case one");8}9}10import org.testng.annotations.Listeners;11import org.testng.annotations.Test;12import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;13@Listeners(CarinaListener.class)14public class 2 {15public void test() {16System.out.println("Test case two");17}18}19import org.testng.annotations.Listeners;20import org.testng.annotations.Test;21import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;22@Listeners(CarinaListener.class)23public class 3 {24public void test() {25System.out.println("Test case three");26}27}28import org.testng.annotations.Listeners;29import org.testng.annotations.Test;30import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;31@Listeners(CarinaListener.class)32public class 4 {33public void test() {34System.out.println("Test case four");35}36}37import org.testng.annotations.Listeners;38import org.testng.annotations.Test;39import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;40@Listeners(CarinaListener.class)41public class 5 {42public void test() {43System.out.println("Test case five");44}45}46import org.testng.annotations.Listeners;47import org.testng.annotations.Test;48import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;5import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;6public class CarinaListenerTest {7 @MethodOwner(owner = "qpsdemo")8 public void test1() {9 Assert.assertEquals(1, 2);10 }11 @MethodOwner(owner = "qpsdemo")12 public void test2() {13 Assert.assertEquals(1, 2);14 }15 @MethodOwner(owner = "qpsdemo")16 public void test3() {17 Assert.assertEquals(1, 2);18 }19}20package com.qaprosoft.carina.demo;21import org.testng.Assert;22import org.testng.annotations.Test;23import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;24import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;25public class CarinaListenerTest {26 @MethodOwner(owner = "qpsdemo")27 public void test1() {28 Assert.assertEquals(1, 2);29 }30 @MethodOwner(owner = "qpsdemo")31 public void test2() {32 Assert.assertEquals(1, 2);33 }34 @MethodOwner(owner = "qpsdemo")35 public void test3() {36 Assert.assertEquals(1, 2);37 }38}39package com.qaprosoft.carina.demo;40import org.testng.Assert;41import org.testng.annotations.Test;42import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;43import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;44public class CarinaListenerTest {45 @MethodOwner(owner = "qpsdemo")46 public void test1() {47 Assert.assertEquals(1, 2);48 }49 @MethodOwner(owner = "qpsdemo")50 public void test2() {51 Assert.assertEquals(1,

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;5import com.qaprosoft.carina.core.foundation.report.testrail.TestRail;6import com.qaprosoft.carina.core.foundation.report.testrail.TestRailCase;7public class CarinaListenerTest {8@TestRail(id = "C123")9public void testCarinaListener() {10Assert.assertEquals(1, 2);11}12}13package com.qaprosoft.carina.demo;14import org.testng.Assert;15import org.testng.annotations.Test;16import com.qaprosoft.carina.core.foundation.report.testrail.TestRail;17import com.qaprosoft.carina.core.foundation.report.testrail.TestRailCase;18public class TestRailListenerTest {19@TestRail(id = "C123")20public void testTestRailListener() {21Assert.assertEquals(1, 2);22}23}24package com.qaprosoft.carina.demo;25import org.testng.Assert;26import org.testng.annotations.Test;27import com.qaprosoft.carina.core.foundation.report.testrail.TestRail;28import com.qaprosoft.carina.core.foundation.report.testrail.TestRailCase;29public class TestNGListenerTest {30@TestRail(id = "C123")31public void testTestNGListener() {32Assert.assertEquals(1, 2);33}34}35package com.qaprosoft.carina.demo;36import org.testng.Assert;37import org.testng.annotations.Test;38import com.qaprosoft.carina.core.foundation.report.testrail.TestRail;39import com.qaprosoft.carina.core.foundation.report.testrail.TestRailCase;40public class TestNGListenerTest {41@TestRail(id = "C123")42public void testTestNGListener() {43Assert.assertEquals(1, 1);44}45}

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo.gui;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.listeners.CarinaListener;4import com.qaprosoft.carina.core.foundation.utils.Configuration;5import com.qaprosoft.carina.core.foundation.utils.R;6public class CarinaListenerDemo {7 public void test1() {8 System.out.println("test1");9 }10 public void test2() {11 System.out.println("test2");12 }13 public void test3() {14 System.out.println("test3");15 }16 public void test4() {17 System.out.println("test4");18 }19 public void test5() {20 System.out.println("test5");21 }22 public void test6() {23 System.out.println("test6");24 }25 public void test7() {26 System.out.println("test7");27 }28 public void test8() {29 System.out.println("test8");30 }31 public void test9() {32 System.out.println("test9");33 }34 public void test10() {35 System.out.println("test10");36 }37 public void test11() {38 System.out.println("test11");39 }40 public void test12() {41 System.out.println("test12");42 }43 public void test13() {44 System.out.println("test13");45 }46 public void test14() {47 System.out.println("test14");48 }49 public void test15() {50 System.out.println("test15");51 }52 public void test16() {53 System.out.println("test16");54 }55 public void test17() {56 System.out.println("test17");57 }58 public void test18() {59 System.out.println("test18");60 }61 public void test19() {62 System.out.println("test19");63 }64 public void test20() {

Full Screen

Full Screen

CarinaListener

Using AI Code Generation

copy

Full Screen

1public class TestClass extends BaseTest {2public void testMethod()3{4}5}6public class TestClass extends BaseTest {7public void testMethod()8{9}10}11public class BaseTest extends TestNGListener implements ITest, IInvokedMethodListener {12private static final Logger LOGGER = Logger.getLogger(BaseTest.class);13private static final String TESTCASE_NAME = "testcase.name";14private static final String TESTCASE_DESCRIPTION = "testcase.description";15private static final String TESTCASE_AUTHOR = "testcase.author";

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful