@@ -212,7 +212,7 @@ public void InputDateInteractsWithEditContext_NonNullableDateTime()
212
212
Browser . Equal ( "modified valid" , ( ) => renewalDateInput . GetAttribute ( "class" ) ) ;
213
213
214
214
// Can become invalid
215
- ApplyInvalidInputDateValue ( ".renewal-date input" , "11111- 11-11") ;
215
+ renewalDateInput . SendKeys ( " 11-11-11111 \t ") ;
216
216
Browser . Equal ( "modified invalid" , ( ) => renewalDateInput . GetAttribute ( "class" ) ) ;
217
217
Browser . Equal ( new [ ] { "The RenewalDate field must be a date." } , messagesAccessor ) ;
218
218
@@ -236,11 +236,11 @@ public void InputDateInteractsWithEditContext_NullableDateTimeOffset()
236
236
237
237
// Validates on edit
238
238
Browser . Equal ( "valid" , ( ) => expiryDateInput . GetAttribute ( "class" ) ) ;
239
- expiryDateInput . SendKeys ( "01/01/ 2000\t " ) ;
239
+ expiryDateInput . SendKeys ( "01-01- 2000\t " ) ;
240
240
Browser . Equal ( "modified valid" , ( ) => expiryDateInput . GetAttribute ( "class" ) ) ;
241
241
242
242
// Can become invalid
243
- ApplyInvalidInputDateValue ( ".expiry-date input" , "11111- 11-11") ;
243
+ expiryDateInput . SendKeys ( " 11-11-11111 \t ") ;
244
244
Browser . Equal ( "modified invalid" , ( ) => expiryDateInput . GetAttribute ( "class" ) ) ;
245
245
Browser . Equal ( new [ ] { "The OptionalExpiryDate field must be a date." } , messagesAccessor ) ;
246
246
@@ -264,21 +264,14 @@ public void InputDateInteractsWithEditContext_TimeInput()
264
264
Browser . Equal ( "modified valid" , ( ) => departureTimeInput . GetAttribute ( "class" ) ) ;
265
265
266
266
// Can become invalid
267
- ApplyInvalidInputDateValue ( ".departure-time input" , "01:234:56" ) ;
267
+ // Stricly speaking the following is equivalent to the empty state, because that's how incomplete input is represented
268
+ // We don't know of any way to produce a different (non-empty-equivalent) state using UI gestures, so there's nothing else to test
269
+ departureTimeInput . SendKeys ( $ "20{ Keys . Backspace } \t ") ;
268
270
Browser . Equal ( "modified invalid" , ( ) => departureTimeInput . GetAttribute ( "class" ) ) ;
269
271
Browser . Equal ( new [ ] { "The DepartureTime field must be a time." } , messagesAccessor ) ;
270
-
271
- // Empty is invalid, because it's not nullable
272
- departureTimeInput . SendKeys ( $ "{ Keys . Backspace } \t { Keys . Backspace } \t { Keys . Backspace } \t ") ;
273
- Browser . Equal ( "modified invalid" , ( ) => departureTimeInput . GetAttribute ( "class" ) ) ;
274
- Browser . Equal ( new [ ] { "The DepartureTime field must be a time." } , messagesAccessor ) ;
275
-
276
- departureTimeInput . SendKeys ( "07201\t " ) ;
277
- Browser . Equal ( "modified valid" , ( ) => departureTimeInput . GetAttribute ( "class" ) ) ;
278
- Browser . Empty ( messagesAccessor ) ;
279
272
}
280
273
281
- [ Fact ]
274
+ [ Fact ( Skip = "https://github.com/dotnet/aspnetcore/issues/35498" ) ]
282
275
public void InputDateInteractsWithEditContext_MonthInput ( )
283
276
{
284
277
var appElement = MountTypicalValidationComponent ( ) ;
@@ -287,11 +280,11 @@ public void InputDateInteractsWithEditContext_MonthInput()
287
280
288
281
// Validates on edit
289
282
Browser . Equal ( "valid" , ( ) => visitMonthInput . GetAttribute ( "class" ) ) ;
290
- visitMonthInput . SendKeys ( "03\t 2005 \t " ) ;
283
+ visitMonthInput . SendKeys ( $ "03{ Keys . ArrowRight } 2005 \t ") ;
291
284
Browser . Equal ( "modified valid" , ( ) => visitMonthInput . GetAttribute ( "class" ) ) ;
292
285
293
286
// Can become invalid
294
- ApplyInvalidInputDateValue ( ".visit-month input" , "05/1992 ") ;
287
+ visitMonthInput . SendKeys ( $ "11 { Keys . ArrowRight } 11111 \t ") ;
295
288
Browser . Equal ( "modified invalid" , ( ) => visitMonthInput . GetAttribute ( "class" ) ) ;
296
289
Browser . Equal ( new [ ] { "The VisitMonth field must be a year and month." } , messagesAccessor ) ;
297
290
@@ -300,12 +293,13 @@ public void InputDateInteractsWithEditContext_MonthInput()
300
293
Browser . Equal ( "modified invalid" , ( ) => visitMonthInput . GetAttribute ( "class" ) ) ;
301
294
Browser . Equal ( new [ ] { "The VisitMonth field must be a year and month." } , messagesAccessor ) ;
302
295
303
- visitMonthInput . SendKeys ( "05\t 2007\t " ) ;
296
+ visitMonthInput . Clear ( ) ;
297
+ visitMonthInput . SendKeys ( $ "05{ Keys . ArrowRight } 2007\t ") ;
304
298
Browser . Equal ( "modified valid" , ( ) => visitMonthInput . GetAttribute ( "class" ) ) ;
305
299
Browser . Empty ( messagesAccessor ) ;
306
300
}
307
301
308
- [ Fact ]
302
+ [ Fact ( Skip = "https://github.com/dotnet/aspnetcore/issues/35498" ) ]
309
303
[ QuarantinedTest ( "https://github.com/dotnet/aspnetcore/issues/34884" ) ]
310
304
public void InputDateInteractsWithEditContext_DateTimeLocalInput ( )
311
305
{
@@ -319,7 +313,7 @@ public void InputDateInteractsWithEditContext_DateTimeLocalInput()
319
313
Browser . Equal ( "modified valid" , ( ) => appointmentInput . GetAttribute ( "class" ) ) ;
320
314
321
315
// Can become invalid
322
- ApplyInvalidInputDateValue ( ".appointment-date-time input" , "1234/567/89 33:44 FM ") ;
316
+ appointmentInput . SendKeys ( $ "11 { Keys . ArrowRight } 11 { Keys . ArrowRight } 11111 { Keys . ArrowRight } \t ") ;
323
317
Browser . Equal ( "modified invalid" , ( ) => appointmentInput . GetAttribute ( "class" ) ) ;
324
318
Browser . Equal ( new [ ] { "The AppointmentDateAndTime field must be a date and time." } , messagesAccessor ) ;
325
319
@@ -862,21 +856,6 @@ private Func<string[]> CreateValidationMessagesAccessor(IWebElement appElement)
862
856
. ToArray ( ) ;
863
857
}
864
858
865
- private void ApplyInvalidInputDateValue ( string cssSelector , string invalidValue )
866
- {
867
- // It's very difficult to enter an invalid value into an <input type=date>, because
868
- // most combinations of keystrokes get normalized to something valid. Additionally,
869
- // using Selenium's SendKeys interacts unpredictably with this normalization logic,
870
- // most likely based on timings. As a workaround, use JS to apply the values. This
871
- // should only be used when strictly necessary, as it doesn't represent actual user
872
- // interaction as authentically as SendKeys in other cases.
873
- var javascript = ( IJavaScriptExecutor ) Browser ;
874
- javascript . ExecuteScript (
875
- $ "document.querySelector('{ cssSelector } ').value = { JsonSerializer . Serialize ( invalidValue , TestJsonSerializerOptionsProvider . Options ) } ") ;
876
- javascript . ExecuteScript (
877
- $ "document.querySelector('{ cssSelector } ').dispatchEvent(new KeyboardEvent('change'))") ;
878
- }
879
-
880
859
private void EnsureAttributeRendering ( IWebElement element , string attributeName , bool shouldBeRendered = true )
881
860
{
882
861
Browser . Equal ( shouldBeRendered , ( ) => element . GetAttribute ( attributeName ) != null ) ;
0 commit comments