Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Currently my team is writing some Selenium-based web tests using Java for our application. One major stumbling block has been centred around testing dates. To me, it seems too awkward to test dates in the UI using Selenium. Formatting, setting and reading dates is difficult with an automated tool.

For example, some fields have a From Date and To Date that are set by using a calendar interface where the user selects the day month and year. Text is read-only, so can't be set directly. Automating such actions is not easy using Selenium (or most UI automation tools, I'd guess).

Apparently, it's also a lot of work for manual testers to execute the same tests.

I'm wondering if dates are better tested at the unit level, by developers using unit or integration tests. What are some good strategies?

share|improve this question
add comment

4 Answers

I have found value from testing date time issues at all layers of an application. Which layer is determined by what I am trying to test. For instance:

Testing Functional Logic:

Assuming for a second that you don't have core logic built into your UI code (Model View Separation or something similar). It is often easier to test the core logic layer by mocking up the UI and dealing with core logic date testing as strict API functional testing. How much testing you do is basically limited by time and resources to automate then.

Using this methodology you can select a test set based on (some examples):

  • Brute Force: Test all valid date range inputs. This is feasible when your date handling logic is fast, or the valid list of date is small (like years as input, excluding months and days).
  • 80% User Scenario: Use data analysis of usage patterns to determine a subset of tests that will keep 80% of your user base happy. This is useful if you are selecting something similar to birthday entry, when your target demographic is tweens. Yes some octogenarians may use the site but your core audience is kept happy.
  • Edge Cases: Leap years, Date Addition (does Jan 30+1 month == Feb 28)?, Time Zone? ect ect ect

Because this list is long and you get better coverage the more per formant the code is, it gets very hard to automate this Functional Logic testing through a UI automation framework.

Testing UI Functionaliy:

I believe in using a UI framework to test basic functionality of the UI (does the UI give information to the backend correctly). These slower, possibly more error prone (sometimes complicated tests) to a minimum also increases your test maintainability (since frequent UI changes don't break you).

Testing UI Date Time Usability

This is something I have never fully been able to automate. This is basically the realm of the manual tester, large beta groups, user research studies, or common sense. Does the date picker make you scroll through every year starting at 1900? That wont get caught until somebody actually has to use it.

share|improve this answer
add comment

1.When you have from date and to date, you can check alerts as 'from date is lesser than to date'. Here the user is not allowed to enter the end date which is lesser than from date.

2.date format can be tested as '01-JAN-2014' as some might give unformatted date into the field as 01-01-2014 or01.01.2014 etc.

I hope this might help you a little.

share|improve this answer
add comment

I runned in similar problem last year and decided to automate the date picker component and created a class to use it when I need it. And the time spend in this work is paid always I run the automated tests. I guess you should automatize the actions and componentize them for reuse. And if you using java you may use Joda Time (http://joda-time.sourceforge.net/), this library has some good methods like 'new DateTime().plusDays(2) '.

share|improve this answer
add comment
  1. Ensure that the date field accept dates in the specified format ie dd/mm/yy or mm/dd/yy or yyyy.
  2. Ensure that the date field does not accept characters.
  3. Ensure that the day field accepts values between 1 and 30/31 according to the month.
  4. Ensure that the day field does not accept any values less than 1 or greater than 31. For example; day field should not accept 0 and 32 or more.
  5. Ensure that the day field does not accept 30/31 for the second month(February).
  6. Ensure that the day field does not accept 29 for the second month(February) unless it is a leap year.
  7. Ensure that the day field and month field accepts the format 1 and 01.
  8. Ensure that the month field accepts value between 1 and 12.
  9. Ensure that the month field does not accept 0 and 13 or more.
  10. Ensure that the year field does not accept 0000.
  11. Ensure that the year field does not accept 'yy' (12) if the required format is 'yyyy'(2012).
  12. Ensure that the day,month and year are separated by – or /.
  13. Ensure that the date field cannot be left blank if the field is set as mandatory.

Further, if the date field is set with a calendar then,

  1. Ensure that a calendar pops up on clicking the date field.
  2. Ensure that the user is able to select the desired date on the calendar.
  3. Ensure that the calendar disappears after a date is selected.
  4. Ensure that the selected date is displayed on the date field.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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