How to use time method of com.qaprosoft.carina.core.foundation.utils.DateUtils class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.DateUtils.time

Source:AbstractTest.java Github

copy

Full Screen

...105 public void executeBeforeTestSuite(ITestContext context) throws Throwable {106 107 DevicePool.addDevices();108 // Add shutdown hook109 Runtime.getRuntime().addShutdownHook(new ShutdownHook());110 // Set log4j properties111 PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties"));112 // Set SoapUI log4j properties113 System.setProperty("soapui.log4j.config", "./src/main/resources/soapui-log4j.xml");114 try {115 Logger root = Logger.getRootLogger();116 Enumeration<?> allLoggers = root.getLoggerRepository().getCurrentCategories();117 while (allLoggers.hasMoreElements()) {118 Category tmpLogger = (Category) allLoggers.nextElement();119 if (tmpLogger.getName().equals("com.qaprosoft.carina.core")) {120 tmpLogger.setLevel(Level.toLevel(Configuration.get(Parameter.CORE_LOG_LEVEL)));121 }122 }123 } catch (NoSuchMethodError e) {124 LOGGER.error("Unable to redefine logger level due to the conflicts between log4j and slf4j!");125 }126 startDate = new Date().getTime();127 LOGGER.info(Configuration.asString());128 // Configuration.validateConfiguration();129 LOGGER.debug("Default thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());130 context.getCurrentXmlTest().getSuite().setThreadCount(Configuration.getInt(Parameter.THREAD_COUNT));131 LOGGER.debug("Updated thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());132 // update DataProviderThreadCount if any property is provided otherwise sync with value from suite xml file133 int count = Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT);134 if (count > 0) {135 LOGGER.debug("Updated 'data_provider_thread_count' from "136 + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount() + " to " + count);137 context.getCurrentXmlTest().getSuite().setDataProviderThreadCount(count);138 } else {139 LOGGER.debug("Synching data_provider_thread_count with values from suite xml file...");140 R.CONFIG.put(Parameter.DATA_PROVIDER_THREAD_COUNT.getKey(), String.valueOf(context.getCurrentXmlTest().getSuite().getDataProviderThreadCount()));141 LOGGER.debug("Updated 'data_provider_thread_count': " + Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT));142 }143 LOGGER.debug("Default data_provider_thread_count="144 + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());145 LOGGER.debug("Updated data_provider_thread_count="146 + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());147 if (!Configuration.isNull(Parameter.URL)) {148 if (!Configuration.get(Parameter.URL).isEmpty()) {149 RestAssured.baseURI = Configuration.get(Parameter.URL);150 }151 }152 try {153 L10N.init();154 } catch (Exception e) {155 LOGGER.error("L10N bundle is not initialized successfully!", e);156 }157 try {158 I18N.init();159 } catch (Exception e) {160 LOGGER.error("I18N bundle is not initialized successfully!", e);161 }162 try {163 L10Nparser.init();164 } catch (Exception e) {165 LOGGER.error("L10Nparser bundle is not initialized successfully!", e);166 }167 try {168 TestRail.updateBeforeSuite(context, this.getClass().getName(), getTitle(context));169 } catch (Exception e) {170 LOGGER.error("TestRail is not initialized successfully!", e);171 }172 try {173 if (!Configuration.get(Parameter.ACCESS_KEY_ID).isEmpty()) {174 LOGGER.info("Initializing AWS S3 client...");175 AmazonS3Manager.getInstance().initS3client(Configuration.get(Parameter.ACCESS_KEY_ID),176 Configuration.get(Parameter.SECRET_KEY));177 updateS3AppPath();178 }179 } catch (Exception e) {180 LOGGER.error("AWS S3 client is not initialized successfully!", e);181 }182 183 // moved from UITest->executeBeforeTestSuite184 String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);185 if (!customCapabilities.isEmpty()) {186 //redefine core properties using custom capabilities file187 Map<String, String> properties = Configuration.loadCoreProperties(customCapabilities);188 //reregister device if mobile core properties are redefined 189 DevicePool.addDevice(properties);190 }191 }192 193 @BeforeClass(alwaysRun = true)194 public void executeBeforeTestClass(ITestContext context) throws Throwable {195 // do nothing for now196 }197 @AfterClass(alwaysRun = true)198 public void executeAfterTestClass(ITestContext context) throws Throwable {199 if (Configuration.getDriverMode() == DriverMode.CLASS_MODE) {200 LOGGER.debug("Deinitialize driver(s) in UITest->AfterClass.");201 quitDrivers();202 }203 }204 @BeforeMethod(alwaysRun = true)205 public void executeBeforeTestMethod(XmlTest xmlTest, Method testMethod,206 ITestContext context) throws Throwable {207 // do nothing for now208 Spira.registerStepsFromAnnotation(testMethod);209 210 apiMethodBuilder = new APIMethodBuilder();211 }212 213 214 @AfterMethod(alwaysRun = true)215 public void executeAfterTestMethod(ITestResult result) {216 try {217 DriverMode driverMode = Configuration.getDriverMode();218 if (driverMode == DriverMode.METHOD_MODE) {219 LOGGER.debug("Deinitialize driver(s) in @AfterMethod.");220 quitDrivers();221 }222 // TODO: improve later removing duplicates with AbstractTestListener223 //handle Zafira already passed exception for re-run and do nothing. maybe return should be enough224 if (result.getThrowable() != null && result.getThrowable().getMessage() != null225 && result.getThrowable().getMessage().startsWith(SpecialKeywords.ALREADY_PASSED)) {226 // [VD] it is prohibited to release TestInfoByThread in this place.!227 return;228 }229 //handle AbstractTest->SkipExecution230 if (result.getThrowable() != null && result.getThrowable().getMessage() != null231 && result.getThrowable().getMessage().startsWith(SpecialKeywords.SKIP_EXECUTION)) {232 // [VD] it is prohibited to release TestInfoByThread in this place.!233 return;234 }235 String test = TestNamingUtil.getCanonicalTestName(result);236 List<String> tickets = Jira.getTickets(result);237 result.setAttribute(SpecialKeywords.JIRA_TICKET, tickets);238 Jira.updateAfterTest(result);239 // Populate Spira Steps240 Spira.updateAfterTest(result, (String) result.getTestContext().getAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE), tickets);241 Spira.clear();242 // Populate TestRail Cases243 if (!R.ZAFIRA.getBoolean("zafira_enabled")){244 result.setAttribute(SpecialKeywords.TESTRAIL_CASES_ID, TestRail.getCases(result));245 TestRail.updateAfterTest(result, (String) result.getTestContext().getAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE));246 TestRail.clearCases();247 }248 //we shouldn't deregister info here as all retries will not work249 //TestNamingUtil.releaseZafiraTest();250 // clear jira tickets to be sure that next test is not affected.251 Jira.clearTickets();252 Artifacts.clearArtifacts();253 try {254 ThreadLogAppender tla = (ThreadLogAppender) Logger.getRootLogger().getAppender("ThreadLogAppender");255 if (tla != null) {256 tla.closeResource(test);257 }258 } catch (NoSuchMethodError e) {259 LOGGER.error("Unable to redefine logger level due to the conflicts between log4j and slf4j!");260 }261 } catch (Exception e) {262 LOGGER.error("Exception in AbstractTest->executeAfterTestMethod: " + e.getMessage());263 e.printStackTrace();264 }265 }266 @AfterSuite(alwaysRun = true)267 public void executeAfterTestSuite(ITestContext context) {268 try {269 if (Configuration.getDriverMode() == DriverMode.SUITE_MODE) {270 LOGGER.debug("Deinitialize driver(s) in UITest->AfterSuite.");271 quitDrivers(); 272 }273 ReportContext.removeTempDir(); //clean temp artifacts directory274 HtmlReportGenerator.generate(ReportContext.getBaseDir().getAbsolutePath());275 String browser = getBrowser();276 String deviceName = getDeviceName();277 String suiteName = getSuiteName(context);278 String title = getTitle(context);279 TestResultType testResult = EmailReportGenerator.getSuiteResult(EmailReportItemCollector.getTestResults());280 String status = testResult.getName();281 title = status + ": " + title;282 String env = "";283 if (!Configuration.isNull(Parameter.ENV)) {284 env = Configuration.get(Parameter.ENV);285 }286 if (!Configuration.get(Parameter.URL).isEmpty()) {287 env += " - <a href='" + Configuration.get(Parameter.URL) + "'>" + Configuration.get(Parameter.URL) + "</a>";288 }289 ReportContext.getTempDir().delete();290 // Update JIRA291 Jira.updateAfterSuite(context, EmailReportItemCollector.getTestResults());292 // Update Spira293 Spira.updateAfterSuite(this.getClass().getName(), testResult, title + "; " + getCIJobReference(), suiteName, startDate);294 //generate and send email report by Zafira to test group of people295 String emailList = Configuration.get(Parameter.EMAIL_LIST);296 String failureEmailList = Configuration.get(Parameter.FAILURE_EMAIL_LIST);297 String senderEmail = Configuration.get(Parameter.SENDER_EMAIL);298 String senderPassword = Configuration.get(Parameter.SENDER_PASSWORD);299 // Generate and send email report using regular method300 EmailReportGenerator report = new EmailReportGenerator(title, env,301 Configuration.get(Parameter.APP_VERSION), deviceName,302 browser, DateUtils.now(), DateUtils.timeDiff(startDate), getCIJobReference(),303 EmailReportItemCollector.getTestResults(),304 EmailReportItemCollector.getCreatedItems());305 String emailContent = report.getEmailBody();306 307 if (!R.ZAFIRA.getBoolean("zafira_enabled")) {308 //Do not send email if run is running with enabled Zafira309 EmailManager.send(title, emailContent,310 emailList,311 senderEmail,312 senderPassword);313 314 if (testResult.equals(TestResultType.FAIL) && !failureEmailList.isEmpty()) {315 EmailManager.send(title, emailContent,316 failureEmailList,317 senderEmail,318 senderPassword);319 }320 }321 // Store emailable report under emailable-report.html322 ReportContext.generateHtmlReport(emailContent);323 printExecutionSummary(EmailReportItemCollector.getTestResults());324 TestResultType suiteResult = EmailReportGenerator.getSuiteResult(EmailReportItemCollector.getTestResults());325 switch (suiteResult) {326 case SKIP_ALL:327 Assert.fail("All tests were skipped! Analyze logs to determine possible configuration issues.");328 break;329 case SKIP_ALL_ALREADY_PASSED:330 LOGGER.info("Nothing was executed in rerun mode because all tests already passed and registered in Zafira Repoting Service!");331 break;332 default:333 //do nothing334 }335 336 } catch (Exception e) {337 LOGGER.error("Exception in AbstractTest->executeAfterSuite: " + e.getMessage());338 e.printStackTrace();339 }340 }341 private String getDeviceName() {342 String deviceName = "Desktop";343 if (Configuration.get(Parameter.DRIVER_TYPE).toLowerCase().contains(SpecialKeywords.MOBILE)) {344 //Samsung - Android 4.4.2; iPhone - iOS 7345 String deviceTemplate = "%s - %s %s";346 deviceName = String.format(deviceTemplate, Configuration.get(Parameter.MOBILE_DEVICE_NAME), Configuration.get(Parameter.MOBILE_PLATFORM_NAME), Configuration.get(Parameter.MOBILE_PLATFORM_VERSION));347 }348 return deviceName;349 }350 protected String getBrowser() {351 String browser = "";352 if (!Configuration.get(Parameter.BROWSER).isEmpty()) {353 browser = Configuration.get(Parameter.BROWSER);354 }355 if (!browserVersion.isEmpty()) {356 browser = browser + " " + browserVersion;357 }358 return browser;359 }360 protected String getTitle(ITestContext context) {361 String browser = getBrowser();362 if (!browser.isEmpty()) {363 browser = " " + browser; //insert the space before364 }365 String device = getDeviceName();366 String env = !Configuration.isNull(Parameter.ENV) ? Configuration.get(Parameter.ENV) : Configuration.get(Parameter.URL);367 String title = "";368 String app_version = "";369 if (!Configuration.get(Parameter.APP_VERSION).isEmpty()) {370 // if nothing is specified then title will contain nothing371 app_version = Configuration.get(Parameter.APP_VERSION) + " - ";372 }373 String suiteName = getSuiteName(context);374 String xmlFile = getSuiteFileName(context);375 title = String.format(SUITE_TITLE, app_version, suiteName, String.format(XML_SUITE_NAME, xmlFile), env, device, browser);376 return title;377 }378 private String getSuiteFileName(ITestContext context) {379 String fileName = context.getSuite().getXmlSuite().getFileName();380 LOGGER.debug("Full suite file name: " + fileName);381 if (fileName.contains("\\")) {382 fileName = fileName.replaceAll("\\\\", "/");383 }384 fileName = StringUtils.substringAfterLast(fileName, "/");385 LOGGER.debug("Short suite file name: " + fileName);386 return fileName;387 }388 protected String getSuiteName(ITestContext context) {389 String suiteName = "";390 if (context.getSuite().getXmlSuite() != null && !"Default suite".equals(context.getSuite().getXmlSuite().getName())) {391 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? context.getSuite().getXmlSuite().getName()392 : Configuration.get(Parameter.SUITE_NAME);393 } else {394 suiteName = Configuration.get(Parameter.SUITE_NAME).isEmpty() ? R.EMAIL.get("title") : Configuration.get(Parameter.SUITE_NAME);395 }396 String appender = getSuiteNameAppender();397 if (appender != null && !appender.isEmpty()) {398 suiteName = suiteName + " - " + appender;399 }400 return suiteName;401 }402 protected void setSuiteNameAppender(String appender) {403 suiteNameAppender.set(appender);404 }405 protected String getSuiteNameAppender() {406 return suiteNameAppender.get();407 }408 private void printExecutionSummary(List<TestResultItem> tris) {409 Messager.INROMATION410 .info("**************** Test execution summary ****************");411 int num = 1;412 for (TestResultItem tri : tris) {413 String failReason = tri.getFailReason();414 if (failReason == null) {415 failReason = "";416 }417 if (!tri.isConfig() && !failReason.contains(SpecialKeywords.ALREADY_PASSED)418 && !failReason.contains(SpecialKeywords.SKIP_EXECUTION)) {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 private String getCIJobReference() {428 String ciTestJob = null;429 if (!Configuration.isNull(Parameter.CI_URL)430 && !Configuration.isNull(Parameter.CI_BUILD)) {431 ciTestJob = Configuration.get(Parameter.CI_URL)432 + Configuration.get(Parameter.CI_BUILD);433 }434 return ciTestJob;435 }436 /**437 * Redefine Jira tickets from test.438 *439 * @param tickets to set440 */441 @Deprecated442 protected void setJiraTicket(String... tickets) {443 List<String> jiraTickets = new ArrayList<String>();444 for (String ticket : tickets) {445 jiraTickets.add(ticket);446 }447 Jira.setTickets(jiraTickets);448 }449 /**450 * Redefine TestRails cases from test.451 *452 * @param cases to set453 */454 protected void setTestRailCase(String... cases) {455 TestRail.setCasesID(cases);456 }457 @DataProvider(name = "DataProvider", parallel = true)458 public Object[][] createData(final ITestNGMethod testMethod, ITestContext context)459 {460 Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations();461 Object[][] objects = DataProviderFactory.getNeedRerunDataProvider(annotations, context, testMethod);462 return objects;463 }464 @DataProvider(name = "SingleDataProvider")465 public Object[][] createDataSingeThread(final ITestNGMethod testMethod,466 ITestContext context) {467 Annotation[] annotations = testMethod.getConstructorOrMethod().getMethod().getDeclaredAnnotations();468 Object[][] objects = DataProviderFactory.getNeedRerunDataProvider(annotations, context, testMethod);469 return objects;470 }471 /**472 * Pause for specified timeout.473 *474 * @param timeout in seconds.475 */476 public void pause(long timeout) {477 try {478 Thread.sleep(timeout * 1000);479 } catch (InterruptedException e) {480 e.printStackTrace();481 }482 }483 public void pause(Double timeout) {484 try {485 timeout = timeout * 1000;486 long miliSec = timeout.longValue();487 Thread.sleep(miliSec);488 } catch (InterruptedException e) {489 e.printStackTrace();490 }491 }492 protected void putS3Artifact(String key, String path) {493 AmazonS3Manager.getInstance().put(Configuration.get(Parameter.S3_BUCKET_NAME), key, path);494 }495 protected S3Object getS3Artifact(String bucket, String key) {496 return AmazonS3Manager.getInstance().get(Configuration.get(Parameter.S3_BUCKET_NAME), key);497 }498 protected S3Object getS3Artifact(String key) {499 return getS3Artifact(Configuration.get(Parameter.S3_BUCKET_NAME), key);500 }...

Full Screen

Full Screen

Source:AtbBallparkPromotionsPage.java Github

copy

Full Screen

...3import java.util.List;4import java.util.concurrent.TimeUnit;5import org.apache.commons.lang.StringUtils;6import org.apache.log4j.Logger;7import org.joda.time.DateTime;8import org.openqa.selenium.By;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.FindBy;12import com.mlb.qa.atb.model.game_promotion.GamePromotion;13import com.mlb.qa.atb.model.game_promotion.Promotion;14import com.mlb.qa.common.date.DateUtils.Month;15import com.qaprosoft.carina.core.foundation.utils.Configuration;16import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;17import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;18import com.qaprosoft.carina.core.gui.AbstractPage;19@SuppressWarnings("unused")20public class AtbBallparkPromotionsPage extends AbstractPage {21 private static final Logger logger = Logger.getLogger(AtbBallparkPromotionsPage.class);22 // promo item23 private static final String PROMOTION_CONTAINER_LOCATOR = ".//div[@class='promo-details-item']";24 private static final String OFFER_NAME_LOCATOR = ".//h7";25 private static final String DESCRIPTION_LOCATOR = ".//p[not (starts-with(.,'Presented By '))]";26 27 private static final String PRESENTED_BY_LOCATOR = ".//p[starts-with(.,'Presented By ')]";28 // Buy tickets link29 private static final String BUY_TICKETS_LINK_LOCATOR = ".//a[text()='Buy Tickets']";30 private static final String HREF_ATTR = "href";31 // away team32 private static final String OPPONENT_LOCATOR = ".//*[@class='promo-details-opponent']";33 // date34 private static final String DAY_LOCATOR = ".//div[@class='promo-date-number']";35 private static final String PRESENTED_BY = "Presented By ";36 @FindBy(xpath = "//nav[@class='nav-pagination']//li/h5")37 private ExtendedWebElement monthYearLabel;38 // game promotion containers39 @FindBy(xpath = "//*[@id='promotions']/ul/li[not(contains(h6,'Promotion'))]")40 private List<ExtendedWebElement> gamePromotionContainers;41 public AtbBallparkPromotionsPage(WebDriver driver) {42 super(driver);43 }44 45 public AtbBallparkPromotionsPage(WebDriver driver, String url) {46 super(driver); 47 logger.info("Open " + url);48 driver.get(url);49 }50/*51 public static AtbBallparkPromotionsPage open(WebDriver driver, String url) {52 logger.info("Open " + url);53 driver.get(url);54 return new AtbBallparkPromotionsPage(driver);55 }56*/57 public List<GamePromotion> loadListOfGamePromotions() {58 logger.info("Load list of game promotions");59 pause(1);60 // get year and month61 String monthYear = monthYearLabel.getText().trim();62 int year = Integer.parseInt(StringUtils.substringAfter(monthYear, " "));63 int month = Month.getMonthOfYearByFullName(StringUtils.substringBefore(monthYear, " "));64 List<GamePromotion> gamePromotions = new LinkedList<GamePromotion>();65 logger.info("gamePromotionContainers size: " + gamePromotionContainers.size());66 67 for (ExtendedWebElement gamePromotionContainer : gamePromotionContainers) {68 GamePromotion gamePromotion = new GamePromotion();69 int day = Integer.parseInt((new ExtendedWebElement(gamePromotionContainer.getElement().findElement(70 By.xpath(DAY_LOCATOR)))).getText());71 LOGGER.info("gamePromotionContainer text: " + gamePromotionContainer.getText());72 gamePromotion.setGameDate(new DateTime(year, month, day, 0, 0));73 gamePromotion.setAwayNameTeam(StringUtils.substringAfter(74 getTextIfPresent(gamePromotionContainer, OPPONENT_LOCATOR), "vs. "));75 String href = getAttributeIfElementPresent(gamePromotionContainer, BUY_TICKETS_LINK_LOCATOR, HREF_ATTR);76 List<Promotion> promotions = new LinkedList<Promotion>();77 for (WebElement promoItemContainer : gamePromotionContainer.getElement().findElements(78 By.xpath(PROMOTION_CONTAINER_LOCATOR))) {79 LOGGER.info("promoItemContainer text: " + promoItemContainer.getText());80 Promotion promotion = new Promotion();81// promotion.setDescription(getTextIfPresent(new ExtendedWebElement(promoItemContainer),82// DESCRIPTION_LOCATOR));83 promotion.setPresentedBy(StringUtils.substringAfter(84 getTextIfPresent(new ExtendedWebElement(promoItemContainer),85 PRESENTED_BY_LOCATOR), PRESENTED_BY));86 promotion87 .setOfferName(getTextIfPresent(new ExtendedWebElement(promoItemContainer), OFFER_NAME_LOCATOR));88 promotion.setTlink(href);89 promotions.add(promotion);90 }91 gamePromotion.setPromotions(promotions);92 gamePromotions.add(gamePromotion);93 }94 logger.info("Found promotions: " + gamePromotions);95 return gamePromotions;96 }97 private String getTextIfPresent(ExtendedWebElement container, String nestedLocator) {98 String text = "";99 try {100 driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);101 List<WebElement> foundElements = container.getElement().findElements(By.xpath(nestedLocator));102 if (!foundElements.isEmpty()) {103 text = (new ExtendedWebElement(foundElements.get(0))).getText();104 }105 } finally {106 driver.manage().timeouts()107 .implicitlyWait(Configuration.getLong(Parameter.IMPLICIT_TIMEOUT), TimeUnit.SECONDS);108 }109 return text;110 }111 private String getAttributeIfElementPresent(ExtendedWebElement container, String nestedLocator, String attribute) {112 String text = "";113 try {114 driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);115 List<WebElement> foundElements = container.getElement().findElements(By.xpath(nestedLocator));116 if (!foundElements.isEmpty()) {117 text = (new ExtendedWebElement(foundElements.get(0))).getAttribute(attribute);118 }119 } finally {120 driver.manage().timeouts()121 .implicitlyWait(Configuration.getLong(Parameter.IMPLICIT_TIMEOUT), TimeUnit.SECONDS);122 }123 return text;124 }125}...

Full Screen

Full Screen

Source:DateUtilsTest.java Github

copy

Full Screen

...22import java.text.SimpleDateFormat;23import java.util.Date;24public class DateUtilsTest {25 private static final String DATE_FORMAT = R.CONFIG.get("date_format");26 private static final String TIME_FORMAT = R.CONFIG.get("time_format");27 private static final String START_DATE = "05:35:15 2021-01-01";28 @Test29 public void testValidCurrentDate() {30 String currentDateStr = DateUtils.now();31 Assert.assertTrue(isDateValid(currentDateStr, DATE_FORMAT), currentDateStr + " has invalid date format");32 }33 @Test34 public void testValidCurrentTime() {35 String currentTimeStr = DateUtils.time();36 Assert.assertTrue(isDateValid(currentTimeStr, TIME_FORMAT), currentTimeStr + " has invalid date format");37 }38 @Test39 public void testValidTimeDiff() {40 long startDate = getDate(START_DATE).getTime();41 String timeStr = DateUtils.timeDiff(startDate);42 Assert.assertTrue(isDateValid(timeStr, TIME_FORMAT), startDate + " has invalid date format");43 }44 @Test45 public void testValidTimeFormat() {46 long startDate = getDate(START_DATE).getTime();47 String timeStr = DateUtils.timeFormat(startDate);48 Assert.assertTrue(isDateValid(timeStr, TIME_FORMAT), startDate + " has invalid date format");49 }50 private Date getDate(String dateStr) {51 Date date = new Date();52 try {53 date = new SimpleDateFormat(DATE_FORMAT).parse(dateStr);54 } catch (ParseException e) {55 e.printStackTrace();56 }57 return date;58 }59 private boolean isDateValid(String dateStr, String format) {60 SimpleDateFormat sdf = new SimpleDateFormat(format);61 sdf.setLenient(false);62 try {...

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.DateUtils;2import java.util.Date;3public class 1 {4public static void main(String[] args) {5DateUtils.time();6}7}8import com.qaprosoft.carina.core.foundation.utils.DateUtils;9import java.util.Date;10public class 2 {11public static void main(String[] args) {12DateUtils.getDuration();13}14}15import com.qaprosoft.carina.core.foundation.utils.DateUtils;16import java.util.Date;17public class 3 {18public static void main(String[] args) {19DateUtils.getDuration();20}21}22import com.qaprosoft.carina.core.foundation.utils.DateUtils;23import java.util.Date;24public class 4 {25public static void main(String[] args) {26DateUtils.getDuration();27}28}29import com.qaprosoft.carina.core.foundation.utils.DateUtils;30import java.util.Date;31public class 5 {32public static void main(String[] args) {33DateUtils.getDuration();34}35}36import com.qaprosoft.carina.core.foundation.utils.DateUtils;37import java.util.Date;38public class 6 {39public static void main(String[] args) {40DateUtils.getDuration();41}42}43import com.qaprosoft.carina.core.foundation.utils.DateUtils;44import java.util.Date;45public class 7 {46public static void main(String[] args) {47DateUtils.getDuration();48}49}50import com.qaprosoft.carina.core.foundation.utils.DateUtils;51import java.util.Date;52public class 8 {53public static void main(String[] args

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1String date = DateUtils.time("yyyy-MM-dd HH:mm:ss.SSS");2System.out.println(date);3String date = DateUtils.date("yyyy-MM-dd HH:mm:ss.SSS");4System.out.println(date);5String date = DateUtils.timestamp();6System.out.println(date);7String date = DateUtils.timestamp("yyyy-MM-dd HH:mm:ss.SSS");8System.out.println(date);9String date = DateUtils.timestamp("yyyy-MM-dd HH:mm:ss.SSS", 0, 0, 0, 0, 0, 0, 0);10System.out.println(date);11String date = DateUtils.timestamp("yyyy-MM-dd HH:mm:ss.SSS", 0, 0, 0, 0, 0, 0, 0, 0);12System.out.println(date);13String date = DateUtils.timestamp("yyyy-MM-dd HH:mm:ss.SSS", 0, 0, 0, 0, 0, 0, 0, 0, 0);14System.out.println(date);15String date = DateUtils.timestamp("yyyy-MM-dd HH:mm:ss.SSS", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);16System.out.println(date);

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.DateUtils;2import java.util.Date;3import java.text.SimpleDateFormat;4import java.util.TimeZone;5public class 1 {6public static void main(String[] args) {7Date date = new Date();8SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");9sdf.setTimeZone(TimeZone.getTimeZone("UTC"));10System.out.println(sdf.format(date));11System.out.println(DateUtils.time());12}13}14import com.qaprosoft.carina.core.foundation.utils.DateUtils;15import java.util.Date;16import java.text.SimpleDateFormat;17import java.util.TimeZone;18public class 2 {19public static void main(String[] args) {20Date date = new Date();21SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");22sdf.setTimeZone(TimeZone.getTimeZone("UTC"));23System.out.println(sdf.format(date));24System.out.println(DateUtils.time("yyyy-MM-dd'T'HH:mm:ss'Z'"));25}26}27import com.qaprosoft.carina.core.foundation.utils.DateUtils;28import java.util.Date;29import java.text.SimpleDateFormat;30import java.util.TimeZone;31public class 3 {32public static void main(String[] args) {33Date date = new Date();34SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");35sdf.setTimeZone(TimeZone.getTimeZone("UTC"));36System.out.println(sdf.format(date));37System.out.println(DateUtils.time("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC")));38}39}40import com.qaprosoft.carina.core.foundation.utils.DateUtils;41import java.util

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.DateUtils;2import java.util.Date;3public class DateUtilsExample {4 public static void main(String[] args) {5 Date date = new Date();6 String dateStr = DateUtils.format(date);7 System.out.println(dateStr);8 }9}10import com.qaprosoft.carina.core.foundation.utils.DateUtils;11public class DateUtilsExample {12 public static void main(String[] args) {13 String dateStr = DateUtils.getFormattedDate();14 System.out.println(dateStr);15 }16}17import com.qaprosoft.carina.core.foundation.utils.DateUtils;18public class DateUtilsExample {19 public static void main(String[] args) {20 String dateStr = DateUtils.getFormattedDate("dd-MM-yyyy");21 System.out.println(dateStr);22 }23}24import com.qaprosoft.carina.core.foundation.utils.DateUtils;25public class DateUtilsExample {26 public static void main(String[] args) {27 String dateStr = DateUtils.getFormattedDate("dd-MM-yyyy", "yyyy-MM-dd");28 System.out.println(dateStr);29 }30}31import com.qaprosoft.carina.core.foundation.utils.DateUtils;32public class DateUtilsExample {33 public static void main(String[] args) {34 String dateStr = DateUtils.getFormattedDate("dd-MM-yyyy", "yyyy-MM-dd", "GMT");35 System.out.println(dateStr);36 }37}38import com.qaprosoft.carina.core.foundation.utils.DateUtils;39public class DateUtilsExample {40 public static void main(String[] args) {41 String dateStr = DateUtils.getFormattedDate("dd-MM-yyyy", "yyyy-MM-dd", "GMT", "en");42 System.out.println(dateStr);43 }44}

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.DateUtils;2import java.util.Date;3public class 1 {4public static void main(String[] args) {5Date date = DateUtils.time(10, 10, 10);6System.out.println(date);7}8}9import com.qaprosoft.carina.core.foundation.utils.DateUtils;10import java.util.Date;11public class 2 {12public static void main(String[] args) {13Date date = DateUtils.time(10, 10, 10, 10);14System.out.println(date);15}16}17import com.qaprosoft.carina.core.foundation.utils.DateUtils;18import java.util.Date;19public class 3 {20public static void main(String[] args) {21Date date = DateUtils.time(10, 10, 10, 10, 10);22System.out.println(date);23}24}25import com.qaprosoft.carina.core.foundation.utils.DateUtils;26import java.util.Date;27public class 4 {28public static void main(String[] args) {29Date date = DateUtils.time(10, 10, 10, 10, 10, 10);30System.out.println(date);31}32}33import com.qaprosoft.carina.core.foundation.utils.DateUtils;34import java.util.Date;35public class 5 {36public static void main(String[] args) {37Date date = DateUtils.time(10, 10, 10, 10, 10, 10, 10);38System.out.println(date);39}40}41import com.qaprosoft.carina.core.foundation.utils.DateUtils;42import java.util.Date;43public class 6 {44public static void main(String[] args) {45Date date = DateUtils.time(10, 10, 10, 10, 10, 10, 10, 10);

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.utils.DateUtils;4public class Test1 {5public void test1() {6System.out.println(DateUtils.getTime());7}8}9package com.qaprosoft.carina.demo;10import org.testng.annotations.Test;11import com.qaprosoft.carina.core.foundation.utils.DateUtils;12public class Test2 {13public void test2() {14System.out.println(DateUtils.getDate());15}16}17package com.qaprosoft.carina.demo;18import org.testng.annotations.Test;19import com.qaprosoft.carina.core.foundation.utils.DateUtils;20public class Test3 {21public void test3() {22System.out.println(DateUtils.getDate());23}24}25package com.qaprosoft.carina.demo;26import org.testng.annotations.Test;27import com.qaprosoft.carina.core.foundation.utils.DateUtils;28public class Test4 {29public void test4() {30System.out.println(DateUtils.getDate());31}32}33package com.qaprosoft.carina.demo;34import org.testng.annotations.Test;35import com.qaprosoft.carina.core.foundation.utils.DateUtils;36public class Test5 {37public void test5() {38System.out.println(DateUtils.getDate());39}40}41package com.qaprosoft.carina.demo;42import org.testng.annotations.Test;43import com.qaprosoft.carina.core.foundation.utils.DateUtils;44public class Test6 {45public void test6() {46System.out.println(DateUtils.getDate());47}48}

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.DateUtils;2import java.util.Date;3{4public static void main(String[] args)5{6Date date = new Date(DateUtils.getTime());7System.out.println(date);8}9}

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1String time = DateUtils.getTime("HH:mm:ss");2String date = DateUtils.getDate("MM/dd/yyyy");3String date_time = DateUtils.getDateAndTime("MM/dd/yyyy","HH:mm:ss");4String time = DateUtils.getTime("HH:mm:ss");5String date = DateUtils.getDate("MM/dd/yyyy");6String date_time = DateUtils.getDateAndTime("MM/dd/yyyy","HH:mm:ss");7String time = DateUtils.getTime("HH:mm:ss");8String date = DateUtils.getDate("MM/dd/yyyy");9String date_time = DateUtils.getDateAndTime("MM/dd/yyyy","HH:mm:ss");10String time = DateUtils.getTime("HH:mm:ss");11String date = DateUtils.getDate("MM/dd/yyyy");

Full Screen

Full Screen

time

Using AI Code Generation

copy

Full Screen

1import java.util.Date;2import com.qaprosoft.carina.core.foundation.utils.DateUtils;3public class 1 {4public static void main(String[] args) {5Date date = new Date();6System.out.println(DateUtils.getTime(date, "yyyy-MM-dd HH:mm:ss"));7}8}9import java.util.Date;10import com.qaprosoft.carina.core.foundation.utils.DateUtils;11public class 2 {12public static void main(String[] args) {13Date date = new Date();14System.out.println(DateUtils.getTime(date, "yyyy-MM-dd"));15}16}17import java.util.Date;18import com.qaprosoft.carina.core.foundation.utils.DateUtils;19public class 3 {20public static void main(String[] args) {21Date date = new Date();22System.out.println(DateUtils.getTime(date, "HH:mm:ss"));23}24}25import java.util.Date;26import com.qaprosoft.carina.core.foundation.utils.DateUtils;27public class 4 {28public static void main(String[] args) {29Date date = new Date();30System.out.println(DateUtils.getTime(date, "HH:mm"));31}32}33import java.util.Date;34import com.qaprosoft.carina.core.foundation.utils.DateUtils;35public class 5 {36public static void main(String[] args) {37Date date = new Date();38System.out.println(DateUtils.getTime(date, "HH"));39}40}41import

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 Carina automation tests on LambdaTest cloud grid

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

Most used method in DateUtils

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful