Brandon Short
Brandon Short

Reputation: 13

Converting Date value to a sting that can be used in TestCafe

I'm currently using an Excel spreadsheet to store my data for my regression pack when calling the data in testcafe. This was not able to be typed into the field using .typetext as this was a number. I then tried to convert into a string but got the following value: 44416.

How do I allow Testcafe to take in this date from excel and type it into a field?

How about if my date format is 8/20/2021 in excel? Testcafe doesn't seem to like this

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

    Browser: Chrome 92.0.4515.131 / Windows 10

    85 | .click(Selector('a').withText(data.SupervisorName)) 86 | 87 | await t 88 | .click(staffMembers.startDateField) 89 | .pressKey('delete delete delete delete delete delete delete delete delete delete delete')

    90 | .typeText(staffMembers.startDateField, data.StartDate)

Upvotes: 0

Views: 453

Answers (1)

user16603402
user16603402

Reputation:

Testcafe's .typeText() expects date formatted as yyyy-mm-dd (source).

Depending on the type of the cell the data is in, you might be able to copy it directly from Excel. Excel stores dates as integers, starting from January 1st, 1900. If the cell format is set to Number, it will display the 8th of August 2021 as 44416. Set it to Date to allow correct copying.

If Excel shows Date in a different date format, like 8/20/2021 for example, you'll need to change the format under Format > More Number Formats (Or use the Ctrl + 1 shortcut while having the cells selected), and select 2012-03-14 to choose the correct format.

Upvotes: 2

Related Questions