Bug 908441 - Convenience methods for interacting with HTML5 "date" and "time" input elements. r=automatedtester

This commit is contained in:
Mike Pennisi 2013-08-29 16:10:20 -04:00
parent d7dea82e3f
commit e65e235aaf
5 changed files with 99 additions and 2 deletions

View File

@ -72,8 +72,8 @@ Debugging
.. automethod:: Marionette.get_logs
.. automethod:: Marionette.screenshot
HTMLElement Objects
-------------------
Querying and Modifying Document Content
---------------------------------------
.. autoclass:: HTMLElement
.. autoattribute:: HTMLElement.text
@ -88,6 +88,11 @@ HTMLElement Objects
.. automethod:: HTMLElement.is_displayed
.. automethod:: HTMLElement.value_of_css_property
.. autoclass:: DateTimeValue
.. autoattribute:: DateTimeValue.date
.. autoattribute:: DateTimeValue.time
Action Objects
--------------

View File

@ -0,0 +1,49 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
class DateTimeValue(object):
"""
Interface for setting the value of HTML5 "date" and "time" input elements.
Simple usage example:
::
element = marionette.find_element("id", "date-test")
dt_value = DateTimeValue(element)
dt_value.date = datetime(1998, 6, 2)
"""
def __init__(self, element):
self.element = element
@property
def date(self):
"""
Retrieve the element's string value
"""
return self.element.get_attribute('value')
# As per the W3C "date" element specification
# (http://dev.w3.org/html5/markup/input.date.html), this value is formatted
# according to RFC 3339: http://tools.ietf.org/html/rfc3339#section-5.6
@date.setter
def date(self, date_value):
self.element.send_keys(date_value.strftime('%Y-%m-%d'))
@property
def time(self):
"""
Retrieve the element's string value
"""
return self.element.get_attribute('value')
# As per the W3C "time" element specification
# (http://dev.w3.org/html5/markup/input.time.html), this value is formatted
# according to RFC 3339: http://tools.ietf.org/html/rfc3339#section-5.6
@time.setter
def time(self, time_value):
self.element.send_keys(time_value.strftime('%H:%M:%S'))

View File

@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from marionette_test import MarionetteTestCase
from datetime import datetime
from date_time_value import DateTimeValue
class TestDateTime(MarionetteTestCase):
def test_set_date(self):
test_html = self.marionette.absolute_url("datetimePage.html")
self.marionette.navigate(test_html)
element = self.marionette.find_element("id", "date-test")
dt_value = DateTimeValue(element)
dt_value.date = datetime(1998, 6, 2)
self.assertEqual(element.get_attribute("value"), "1998-06-02")
def test_set_time(self):
test_html = self.marionette.absolute_url("datetimePage.html")
self.marionette.navigate(test_html)
element = self.marionette.find_element("id", "time-test")
dt_value = DateTimeValue(element)
dt_value.time = datetime(1998, 11, 19, 9, 8, 7)
self.assertEqual(element.get_attribute("value"), "09:08:07")

View File

@ -91,3 +91,4 @@ b2g = false
b2g = false
[test_implicit_waits.py]
[test_date_time_value.py]

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<head>
<title>Testing date and time inputs</title>
</head>
<body>
<form>
<input id="date-test" type="date"/>
<input id="time-test" type="time"/>
</form>
</body>
</html>