How to set datepicker with current date

I use a simple method to insert the text in a date field. A calendar GUI appears when I do, so I click on another area of the page to have the calendar disappear. Since I use my date throughout the Test Suite, I use a Global Variable to hold it (them).

Date todaysDate = new Date();
GlobalVariable.gFormattedDate = todaysDate.format("M/d/yyyy");
GlobalVariable.gScreenFormattedDate = todaysDate.format("MM/dd/yyyy");
GlobalVariable.gLastWeekDate = todaysDate.plus(-7).format("MM/dd/yyyy");
GlobalVariable.gFutureDate = todaysDate.plus(3).format("MM/dd/yyyy");

"date of initial inquiry"
WebUI.setText(findTestObject('myPage/input_GeneralInfo.DateInitialInquiry'),
	GlobalVariable.gScreenFormattedDate)
"click on another area of the page to let the calendar GUI disappear"
WebUI.click(findTestObject('myPage/textarea_GeneralInfo.Location'))
"verify the date is set"
WebUI.verifyElementAttributeValue(findTestObject('myPage/input_GeneralInfo.DateInitialInquiry'),
	"value", GlobalVariable.gScreenFormattedDate, 10)
1 Like