1

I have one scenario in which I have to book appointment. The limitation is that I can't book appointment in past. I have to automate this scenario.

Is this possible to check the current time and set book appointment time "currenttime +1" in protractor?

Rashmi Chauhan
  • 135
  • 2
  • 12

2 Answers2

3

Sure, this is still JavaScript, you can get the tomorrow's date via Date():

var date = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();

var tomorrowDate = day + "/" + month + "/" + year;

Then, for example, you can send this tomorrowDate string into the appropriate input:

element(by.id("appointmentDate")).sendKeys(tomorrowDate);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

There is a way to set the current date in your date picker.

var pickerDue = element(by.model("model of your date picker"));

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
   dd='0'+dd
} 

if(mm<10) {
   mm='0'+mm
} 

today = yyyy+'-'+mm+'-'+dd;

pickerDue.clear();
pickerDue.sendKeys(today);

This code works for me. If you have a problem, do not hesitate to ask.

Hope this helps. :)

Manuli
  • 1,203
  • 4
  • 20
  • 43