Automation, Java, Loggers, Quality Analyst, Selenium, Testing, Timestamp

Current timestamps in selenium

In this post I will be sharing a function to get current timestamp in selenium?

public static void getCurrentTimeStamp() {

Date dateInstance = new Date();

int date = dateInstance.getDate();

int month = dateInstance.getMonth();

int day = dateInstance.getDay();

int hours = dateInstance.getHours();

int min = dateInstance.getMinutes();

String dayOfWeek = "";

switch (day) {

case 0:

dayOfWeek = "Sun";

break;

case 1:

dayOfWeek = "Mon";

break;

case 2:

dayOfWeek = "Tues";

break;

case 3:

dayOfWeek = "Wedn";

break;

case 4:

dayOfWeek = "Thur";

break;

case 5:

dayOfWeek = "Fri";

break;

case 6:

dayOfWeek = "Sat";

break;

}

String month_name = "";

switch (month) {

case 0:

month_name = "JAN";

break;

case 1:

month_name = "FEB";

break;

case 2:

month_name = "MAR";

break;

case 3:

month_name = "APR";

break;

case 4:

month_name = "MAY";

break;

case 5:

month_name = "JUNE";

break;

case 6:

month_name = "JULY";

break;

case 7:

month_name = "AUG";

break;

case 8:

month_name = "SEP";

break;

case 9:

month_name = "OCT";

break;

case 10:

month_name = "NOV";

break;

case 11:

month_name = "DEC";

break;

}

String timestamp = dayOfWeek + " " + date + " " + month_name + " " + hours + ":" + min;
Loggers.info("Current timestamp is " + dayOfWeek + " " + date + " " + month_name + " " + hours + ":" + min);
property.setProperty("timestamp", timestamp);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s