Best Testsigma code snippet using com.testsigma.automator.utilities.TimeUtil
Source:DriverManager.java
...8import com.testsigma.automator.exceptions.AutomatorException;9import com.testsigma.automator.exceptions.TestsigmaNoParallelRunException;10import com.testsigma.automator.runners.EnvironmentRunner;11import com.testsigma.automator.utilities.RuntimeDataProvider;12import com.testsigma.automator.utilities.TimeUtil;13import lombok.Data;14import lombok.extern.log4j.Log4j2;15import org.apache.commons.lang3.StringUtils;16import org.openqa.selenium.remote.RemoteWebDriver;17import java.io.IOException;18import java.time.Instant;19@Log4j220@Data21public abstract class DriverManager {22 public static final String MSG_LAB_MINUTES_EXCEEDED = "Allowed test execution duration on cloud devices/machines exceeded.";23 public static final String MSG_NO_PARALLEL_RUN = "Parallel Executions Limit exceeded.Please upgrade to community edition for more parallel runs.";24 public static final String MSG_OS_NOT_SUPPORTED = "Selected device OS and version combination is no longer supported. Please edit the device and choose a supported OS and Version.";25 public static final String MSG_BROWSER_NOT_SUPPORTED = "Selected browser and version combination is no longer supported. Please edit the device and choose a supported browser and Version.";26 static private ThreadLocal<DriverManager> _driverManager = new ThreadLocal<>();27 private final TestDeviceSettings settings;28 private TestDeviceEntity testDeviceEntity;29 private TestDeviceSettings testDeviceSettings;30 private ExecutionLabType executionLabType;31 private String executionUuid;32 private TestsigmaDriver driver;33 private Boolean restartDriverSession = Boolean.FALSE;34 private Instant sessionStartInstant;35 private Instant sessionEndInstant;36 private String initialSessionId;37 private String restartSessionId;38 private Boolean isRestart = Boolean.FALSE;39 DriverManager() {40 this.executionUuid = EnvironmentRunner.getRunnerExecutionId();41 this.testDeviceEntity = EnvironmentRunner.getRunnerEnvironmentEntity();42 this.executionLabType = testDeviceEntity.getExecutionLabType();43 this.settings = testDeviceEntity.getEnvSettings();44 this.testDeviceSettings = testDeviceEntity.getEnvSettings();45 TestPlanRunSettingEntity executionSettings = testDeviceEntity.getTestPlanSettings();46 this.testDeviceSettings.setElementTimeout(executionSettings.getPageTimeOut());47 this.testDeviceSettings.setPageLoadTimeout(executionSettings.getElementTimeOut());48 }49 public static DriverManager getDriverManager() {50 return _driverManager.get();51 }52 public static void setDriverManager(DriverManager driverManager) {53 _driverManager.set(driverManager);54 }55 public static void getDriverManager(TestDeviceEntity testDeviceEntity,56 WorkspaceType workspaceType, Platform os, Long environmentResultId,57 DriverSessionType driverSessionType) throws AutomatorException {58 DriverManager driverManager = null;59 switch (workspaceType) {60 case WebApplication:61 driverManager = new WebDriverManager();62 break;63 case MobileWeb:64 if (os.equals(Platform.Android)) {65 driverManager = new AndroidWebDriverManager();66 } else {67 driverManager = new IOSWebDriverManager();68 }69 break;70 case AndroidNative:71 driverManager = new AndroidNativeDriverManager();72 break;73 case IOSNative:74 driverManager = new IOSNativeDriverManager();75 break;76 default:77 break;78 }79 if (driverManager != null) {80 DriverManager.setDriverManager(driverManager);81 driverManager.startSession(driverSessionType,82 environmentResultId, Boolean.FALSE);83 }84 }85 public static RemoteWebDriver getRemoteWebDriver() {86 RemoteWebDriver driver = null;87 if (DriverManager.getDriverManager().getDriver() != null) {88 driver = DriverManager.getDriverManager().getDriver().getRemoteWebDriver();89 }90 return driver;91 }92 public boolean isRestart() {93 return this.isRestart;94 }95 public abstract void performCleanUpAction(OnAbortedAction actionType) throws AutomatorException;96 protected abstract RemoteWebDriver createDriverSession() throws AutomatorException, IOException;97 protected void beforeSessionCreateActions() throws AutomatorException {98 log.debug("Executing before create session actions for execution UUID - " + executionUuid);99 sessionStartInstant = Instant.now();100 }101 protected void afterSessionCreateActions()102 throws AutomatorException {103 log.debug("Executing after create session actions for execution UUID - " + executionUuid);104 }105 public void startSession(DriverSessionType driverSessionType, Long entityId, Boolean isRestart) throws AutomatorException {106 RemoteWebDriver remoteWebDriver;107 beforeSessionCreateActions();108 try {109 remoteWebDriver = createDriverSession();110 storeSessionId(driverSessionType, entityId);111 this.isRestart = isRestart;112 if (!isRestart) {113 this.initialSessionId = getSessionId();114 log.info("Initial Session ID:" + this.initialSessionId);115 } else {116 this.restartSessionId = getSessionId();117 log.info("Restarted Session ID:" + this.restartSessionId);118 }119 } catch (Exception e) {120 log.error(e.getMessage(), e);121 String errorMessage = parseErrorMessage(e.getMessage());122 if (StringUtils.isBlank(errorMessage)) {123 errorMessage = AutomatorMessages.EXCEPTION_WEBDRIVER_NOTCREATED + " - " + e.getMessage();124 } else if(e.getMessage().contains("NO_PARALLEL_RUN")){125 errorMessage = AutomatorMessages.NO_PARALLEL_RUNS;126 throw new TestsigmaNoParallelRunException(ErrorCodes.NO_PARALLEL_RUN,errorMessage);127 }else {128 errorMessage = "Unable to create a new Test Session due to unexpected failure(0x537). " + errorMessage;129 }130 endSession();131 throw new AutomatorException(ErrorCodes.DRIVER_NOT_CREATED, errorMessage);132 }133 if (remoteWebDriver != null) {134 log.info("Driver Session ID - " + getSessionId());135 } else {136 throw new AutomatorException(ErrorCodes.DRIVER_NOT_CREATED, AutomatorMessages.EXCEPTION_WEBDRIVER_NOTCREATED);137 }138 afterSessionCreateActions();139 }140 public void endSession() throws AutomatorException {141 try {142 if (getDriver() != null && (getDriver().getRemoteWebDriver() != null)) {143 log.info("Ending session(if exists) with execution UUID - " + executionUuid + " and session ID - "144 + getSessionId());145 RemoteWebDriver driver = getDriver().getRemoteWebDriver();146 try {147 beforeEndSessionActions();148 driver.quit();149 } catch (Exception e) {150 log.error(e.getMessage(), e);151 driver.quit();152 }153 afterEndSessionActions();154 } else {155 log.debug("There is no driver session with executionID - " + executionUuid);156 }157 } catch (Exception e) {158 throw new AutomatorException(e.getMessage(), e);159 }160 }161 protected void beforeEndSessionActions() throws AutomatorException {162 log.debug("Executing before end session actions for execution UUID - " + executionUuid);163 }164 protected void afterEndSessionActions() throws AutomatorException {165 log.debug("Executing after end session actions for execution UUID - " + executionUuid);166 new RuntimeDataProvider().clearRunTimeData(executionUuid);167 getDriver().setRemoteWebDriver(null);168 setDriver(null);169 sessionEndInstant = Instant.now();170 log.info("Total session time - " + TimeUtil.getFormattedDuration(sessionStartInstant, sessionEndInstant));171 }172 private String parseErrorMessage(String errorMessage) {173 String parsedErrorMessage = "";174 try {175 String[] tokens;176 if (errorMessage != null) {177 tokens = errorMessage.split("Original error:");178 if (tokens.length > 1) {179 tokens = tokens[1].split("Build info: version:");180 if (tokens.length > 1) {181 parsedErrorMessage = tokens[0];182 }183 }184 if(errorMessage.contains(SessionErrorType.PLATFORM_OS_NOT_SUPPORTED.name())){...
Source:WebDriver.java
...3import com.testsigma.automator.drivers.TestsigmaDriver;4import com.testsigma.automator.drivers.WebDriverCapability;5import com.testsigma.automator.entity.ExecutionLabType;6import com.testsigma.automator.exceptions.AutomatorException;7import com.testsigma.automator.utilities.TimeUtil;8import lombok.Data;9import lombok.EqualsAndHashCode;10import lombok.extern.log4j.Log4j2;11import org.openqa.selenium.html5.Location;12import org.openqa.selenium.html5.LocationContext;13import org.openqa.selenium.remote.Augmenter;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.LocalFileDetector;16import org.openqa.selenium.remote.RemoteWebDriver;17import java.net.MalformedURLException;18import java.time.Instant;19import java.util.Iterator;20import java.util.List;21@EqualsAndHashCode(callSuper = true)22@Data23@Log4j224public class WebDriver extends TestsigmaDriver {25 private static final String INVALID_GEO_LOCATION_ERROR = "Invalid \"geolocation\" desired capability value provided " +26 "in the execution configuration. For correct format refer to " +27 "https://testsigma.freshdesk.com/solution/articles/32000024808-sample-desired-capabilities";28 protected WebDriverCapability locationCapability;29 public WebDriver() {30 super();31 }32 @Override33 protected void setCapabilities() throws AutomatorException, MalformedURLException {34 super.setCapabilities();35 List<WebDriverCapability> additionalCapabilitiesList = webDriverSettings.getWebDriverCapabilities();36 setCommonCapabilities();37 setPlatformSpecificCapabilities();38 checkForLocationCapability(additionalCapabilitiesList);39 setBrowserSpecificCapabilities(additionalCapabilitiesList);40 setAdditionalCapabilities(additionalCapabilitiesList);41 }42 @Override43 protected void setCommonCapabilities() throws AutomatorException {44 super.setCommonCapabilities();45 capabilities.add(new WebDriverCapability(TSCapabilityType.NAME, executionName));46 capabilities.add(new WebDriverCapability(TSCapabilityType.ACCEPT_SSL_CERTS, Boolean.TRUE));47 capabilities.add(new WebDriverCapability(TSCapabilityType.UNHANDLED_PROMPT_BEHAVIOUR_KEY, TSCapabilityType.UNHANDLED_PROMPT_BEHAVIOUR_VALUE));48 }49 @Override50 protected void setTestsigmaLabCapabilities() throws AutomatorException {51 super.setTestsigmaLabCapabilities();52 }53 @Override54 protected void setHybridCapabilities() throws AutomatorException, MalformedURLException {55 super.setHybridCapabilities();56 }57 protected void setBrowserSpecificCapabilities(List<WebDriverCapability> additionalCapabilitiesList)58 throws AutomatorException {59 }60 protected void checkForLocationCapability(List<WebDriverCapability> additionalCapabilitiesList) {61 if (additionalCapabilitiesList != null) {62 for (Iterator<WebDriverCapability> single = additionalCapabilitiesList.listIterator(); single.hasNext(); ) {63 WebDriverCapability capability = single.next();64 String name = capability.getCapabilityName();65 if (com.testsigma.automator.constants.DesiredCapabilities.GEOLOCATION.equals(name)) {66 single.remove();67 locationCapability = new WebDriverCapability(name, capability.getCapabilityValue());68 }69 }70 }71 }72 @Override73 protected RemoteWebDriver createDriver(DesiredCapabilities desiredCapabilities) throws AutomatorException {74 Instant start = Instant.now();75 createDriverInstance(desiredCapabilities);76 Instant end = Instant.now();77 log.info("Web Driver Session Created in - " + TimeUtil.getFormattedDuration(start, end));78 log.info("Stating with post web driver creation actions");79 setLocation();80 setFileDetector();81 //deleteAllCookies();82 maximizeWindow();83 setTimeouts();84 log.info("Finished post web driver creation actions in ");85 return remoteWebDriver;86 }87 protected void createDriverInstance(DesiredCapabilities desiredCapabilities) throws AutomatorException {88 }89 protected void maximizeWindow() {90 getRemoteWebDriver().manage().window().maximize();91 }...
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2public class 2 {3 public static void main(String[] args) {4 TimeUtil timeUtil = new TimeUtil();5 System.out.println(timeUtil.getDateTime());6 System.out.println(timeUtil.getDateTime("dd-MM-yyyy"));7 System.out.println(timeUtil.getDate());8 System.out.println(timeUtil.getDate("dd-MM-yyyy"));9 System.out.println(timeUtil.getTime());10 System.out.println(timeUtil.getTime("HH:mm:ss"));11 System.out.println(timeUtil.getTimestamp());12 System.out.println(timeUtil.getTimestamp("dd-MM-yyyy HH:mm:ss"));13 System.out.println(timeUtil.getTimestamp("dd-MM-yyyy HH:mm:ss.SSS"));14 }15}16getDateTime()17getDateTime(String format)18getDate()19getDate(String format)20getTime()21getTime(String format)22getTimestamp()23getTimestamp(String format)24getTimestamp(String format, int offset)25getTimestamp(String format, int offset, String date)26getTimestamp(String format, int offset, String date, String time)27getTimestamp(String format, int offset, String date, String time, String timezone)28getTimestamp(String format, int offset, String date, String time, String timezone, String locale)
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2import java.util.Date;3public class 2 {4public static void main(String[] args) {5Date date = new Date();6TimeUtil.getTimeDifference(date);7}8}92. getTimeDifference() method with two dates10public static void getTimeDifference(Date date1, Date date2)11import com.testsigma.automator.utilities.TimeUtil;12import java.util.Date;13public class 3 {14public static void main(String[] args) {15Date date1 = new Date();16Date date2 = new Date();17TimeUtil.getTimeDifference(date1, date2);18}19}203. getTimeDifference() method with two strings21public static void getTimeDifference(String date1, String date2)
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2public class TimeUtilExample {3public static void main(String[] args) {4TimeUtil timeUtil = new TimeUtil();5timeUtil.sleep(10);6}7}8import com.testsigma.automator.utilities.TimeUtil;9public class TimeUtilExample {10public static void main(String[] args) {11TimeUtil.sleep(10);12}13}
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2public class 2 {3public static void main(String[] args) {4String currentTime = TimeUtil.getCurrentTime();5System.out.println("Current Time is : " + currentTime);6}7}8import com.testsigma.automator.utilities.TimeUtil;9public class 3 {10public static void main(String[] args) {11String currentTime = TimeUtil.getCurrentTime();12System.out.println("Current Time is : " + currentTime);13}14}15import com.testsigma.automator.utilities.TimeUtil;16public class 4 {17public static void main(String[] args) {18String currentTime = TimeUtil.getCurrentTime();19System.out.println("Current Time is : " + currentTime);20}21}22import com.testsigma.automator.utilities.TimeUtil;23public class 5 {24public static void main(String[] args) {25String currentTime = TimeUtil.getCurrentTime();26System.out.println("Current Time is : " + currentTime);27}28}29import com.testsigma.automator.utilities.TimeUtil;30public class 6 {31public static void main(String[] args) {32String currentTime = TimeUtil.getCurrentTime();33System.out.println("Current Time is : " + currentTime);34}35}36import com.testsigma.automator.utilities.TimeUtil;37public class 7 {38public static void main(String[] args) {39String currentTime = TimeUtil.getCurrentTime();40System.out.println("Current Time is : " + currentTime);41}42}43import com.testsigma.automator.utilities.TimeUtil;44public class 8 {45public static void main(String[] args) {46String currentTime = TimeUtil.getCurrentTime();47System.out.println("Current Time is : " + currentTime);48}49}50import
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2import java.util.Date;3public class TimeUtilDemo {4public static void main(String[] args) {5Date date = TimeUtil.getCurrentDateTime();6System.out.println("Current date time is : " + date);7Date currentDate = TimeUtil.getCurrentDate();8System.out.println("Current date is : " + currentDate);9Date currentTime = TimeUtil.getCurrentTime();10System.out.println("Current time is : " + currentTime);11long currentTimeInMilliseconds = TimeUtil.getCurrentTimeInMilliseconds();12System.out.println("Current time in milliseconds is : " + currentTimeInMilliseconds);13long currentTimeInSeconds = TimeUtil.getCurrentTimeInSeconds();14System.out.println("Current time in seconds is : " + currentTimeInSeconds);15long currentTimeInMinutes = TimeUtil.getCurrentTimeInMinutes();16System.out.println("Current time in minutes is : " + currentTimeInMinutes);17long currentTimeInHours = TimeUtil.getCurrentTimeInHours();18System.out.println("Current time in hours is : " + currentTimeInHours);19long currentTimeInDays = TimeUtil.getCurrentTimeInDays();20System.out.println("Current time in days is : " + currentTimeInDays);21long currentTimeInYears = TimeUtil.getCurrentTimeInYears();22System.out.println("Current time in years is : " + currentTimeInYears);23String currentTimeInCustomFormat = TimeUtil.getCurrentTimeInCustomFormat("dd-MMM-yyyy HH:mm:ss");24System.out.println("Current time in custom format is : " + currentTimeInCustomFormat);25String currentTimeInCustomFormatWithTimeZone = TimeUtil.getCurrentTimeInCustomFormatWithTimeZone("dd-MMM-yyyy HH:mm:ss", "IST");26System.out.println("Current time in custom format with time zone is : " + currentTimeInCustomFormatWithTimeZone);27String currentTimeInCustomFormatWithTimeZone1 = TimeUtil.getCurrentTimeInCustomFormatWithTimeZone("dd-MMM-yyyy HH:mm:ss", "GMT");28System.out.println("Current time in custom format with time zone is : " + currentTimeInCustomFormatWithTimeZone1);
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2import java.util.Date;3import java.text.SimpleDateFormat;4public class 2{5public static void main(String[] args){6long currentTime = TimeUtil.getCurrentTimeInMilliSeconds();7System.out.println(currentTime);8long currentTimeInSeconds = TimeUtil.getCurrentTimeInSeconds();9System.out.println(currentTimeInSeconds);10String date = "2018-12-01";11long timeInMilliseconds = TimeUtil.getTimeInMilliSeconds(date);12System.out.println(timeInMilliseconds);13long timeInSeconds = TimeUtil.getTimeInSeconds(date);14System.out.println(timeInSeconds);15String currentTimeString = TimeUtil.getCurrentTimeInMilliSecondsAsString();16System.out.println(currentTimeString);17String currentTimeStringInSeconds = TimeUtil.getCurrentTimeInSecondsAsString();18System.out.println(currentTimeStringInSeconds);19String date = "2018-12-01";20String timeInMillisecondsAsString = TimeUtil.getTimeInMilliSecondsAsString(date);21System.out.println(timeInMillisecondsAsString);22String timeInSecondsAsString = TimeUtil.getTimeInSecondsAsString(date);23System.out.println(timeInSecondsAsString);24Date date = TimeUtil.getCurrentDateAndTime();25System.out.println(date);26String dateAsString = TimeUtil.getCurrentDateAndTimeAsString();27System.out.println(dateAsString);28SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");29String dateAsStringWithFormat = TimeUtil.getCurrentDateAndTimeAsString(dateFormat);30System.out.println(dateAsStringWithFormat);31Date date = TimeUtil.getCurrentDate();32System.out.println(date);33String dateAsString = TimeUtil.getCurrentDateAsString();34System.out.println(dateAsString);35SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");36String dateAsStringWithFormat = TimeUtil.getCurrentDateAsString(dateFormat);37System.out.println(dateAsStringWithFormat);38Date time = TimeUtil.getCurrentTime();39System.out.println(time);
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2public class 2 {3public static void main(String[] args) {4System.out.println("Get current date: "+TimeUtil.getCurrentDate());5System.out.println("Get current time: "+TimeUtil.getCurrentTime());6System.out.println("Get current date and time: "+TimeUtil.getCurrentDateTime());7System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("dd-MM-yyyy HH:mm:ss"));8System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss"));9System.out.println("Get current date in custom format: "+TimeUtil.getCurrentDate("dd-MM-yyyy"));10System.out.println("Get current date in custom format: "+TimeUtil.getCurrentDate("yyyy-MM-dd"));11System.out.println("Get current time in custom format: "+TimeUtil.getCurrentTime("HH:mm:ss"));12System.out.println("Get current time in custom format: "+TimeUtil.getCurrentTime("hh:mm:ss"));13System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("dd-MM-yyyy HH:mm:ss"));14System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss"));15System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("dd-MM-yyyy HH:mm:ss"));16System.out.println("Get current date and time in custom format: "+TimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss"));17System.out.println("Get current date in custom format: "+TimeUtil.getCurrentDate("dd-MM-yyyy"));18System.out.println("Get current date in custom format: "+TimeUtil.getCurrentDate("yyyy-MM-dd"));19System.out.println("Get current time in custom format: "+TimeUtil
TimeUtil
Using AI Code Generation
1import com.testsigma.automator.utilities.TimeUtil;2import java.util.Calendar;3public class TestTimeUtil {4public static void main(String[] args) {5System.out.println(TimeUtil.getCurrentTime());6System.out.println(TimeUtil.getCurrentDate());7System.out.println(TimeUtil.getCurrentDateTime());8System.out.println(TimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss"));9System.out.println(TimeUtil.getCurrentDateTime("dd/MM/yyyy hh:mm:ss a"));10System.out.println(TimeUtil.getCurrentDateTime("MM/dd/yyyy HH:mm:ss"));11System.out.println(TimeUtil.getCurrentTime("hh:mm:ss a"));12System.out.println(TimeUtil.getCurrentDate("dd/MM/yyyy"));13System.out.println(TimeUtil.getCurrentDate("yyyy-MM-dd"));14System.out.println(TimeUtil.getCurrentDate("MM/dd/yyyy"));15System.out.println(TimeUtil.getDateTime("dd/MM/yyyy HH:mm:ss", 2018, 7, 1, 10, 30, 45));16System.out.println(TimeUtil.getDateTime("dd/MM/yyyy hh:mm:ss a", 2018, 7, 1, 10, 30, 45));17System.out.println(TimeUtil.getDateTime("yyyy-MM-dd HH:mm:ss", 2018, 7, 1, 10, 30, 45));18System.out.println(TimeUtil.getDateTime("MM/dd/yyyy hh:mm:ss a", 2018, 7, 1, 10, 30, 45));19System.out.println(TimeUtil.getDate("dd/MM/yyyy", 2018, 7, 1));20System.out.println(TimeUtil.getDate("yyyy-MM-dd", 2018,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!