I have a close date field where the date is already populated, and a date creation field which is the actual activity creation date and the logic I want to validate is below -

  1. Validate that the close date field date is within 60 days of the creation date? For example:
    • Creation date - 01/08/2019 (format is dd/mm/yyyy)
    • Close date - 29/09/2019 (should be no more than 60 days after creation date. Format is dd/mm/yyyy)
  2. How do I create a page object method which will get the creation date then check the difference between close date and creation date and fail the test if creation date is more than 60 days before close date?

1 - For the date difference, you can use the Period object:

LocalDate creationDate = ...;
LocalDate closeDate = ...;

Period diff = Period.between(creationDate, closeDate);
int diffInDays = diff.getDays();

2 - For the method, you simply have to use the code above and return a Boolean:

public Boolean checkDateValidity(LocalDate creationDate) {
     LocalDate closeDate = ...;
     return Period.between(creationDate, closeDate).getDays() < 60;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.