3

I can't seem to remove the value in an HTML5 date input with TestCafe after it's been set. I've tried typeText and pressKey so far; typeText works for setting a new date but can't input an empty string, while using delete and backspace with pressKey doesn't remove the value as it does when manually performing the same action. I also can't/don't know how to click the x on the field itself.

Is there something I'm missing/doing wrong, or is this not possible?

typeText

test('typeText', async t => {
    await t
        .typeText('#dateField', '', { replace: true });

    await t
        .expect(Selector('#dateField').value).eql('');
});

1) The "text" argument is expected to be a non-empty string, but it was "".

pressKey

test('pressKey', async t => {
    await t
        .click('#dateField')
        .pressKey('delete'); // 'backspace' also does not work

    await t
        .expect(Selector('#dateField').value).eql('');
});

1) AssertionError: expected '2019-05-02' to deeply equal ''

Community
  • 1
  • 1
lostlemon
  • 744
  • 1
  • 6
  • 17
  • Do you by chance have an example website that has the type of Date input you are working with? Is it like a Date picker? Or just a simple text area/box? – TallKU Jun 21 '19 at 15:14
  • @TallKU https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date - the input I want to test is just about identical to that first example. – lostlemon Jun 21 '19 at 15:46

1 Answers1

4

According to TestCafe's typing formats for HTML5 inputs, you can use the typeText action the following way:

test('test', async t => {
    await t
        .typeText('#start', '2017-12-23')
        .expect(Selector('#start').value).eql('2017-12-23')
 
        .typeText('#start', '    -  -  ')
        .expect(Selector('#start').value).eql('');
});
Helen Dikareva
  • 1,026
  • 6
  • 7
  • 2
    Perfect, thank you very much! I hadn't thought that entering the value like that would translate properly. – lostlemon Jun 27 '19 at 12:49