1

I am validating a drop down box that contains years.

Below is my code to validate the drop-down box. However protractor still returns an error message for that line of code. I am not sure why its returning an error message.

var EachYear = element.all(by.id("Years"));               
expect(EachYear.getText()).toBe(['Year\n2017\n2018\n2019\n2020\n2021\n2022\n2023']);

Error message

Expected [ 'Year 2017 2018 2019 2020 2021 2022 2023' ] to be [ 'Year 2017 2018 2019 2020 2021 2022 2023' ].✗

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
James
  • 129
  • 2
  • 11
  • Do you actually care about the format of this string of bytes, or do you care that the earliest year available is the current year, that there are 7 options, and that the list is consecutive and in ascending order, etc.? – lotyrin Feb 05 '18 at 04:07

1 Answers1

1

New line character in browsers is CR LF(\r\n), not \n. Changing your code like below can fix the problem.

expect(EachYear.getText()).toBe(['Year\r\n2017\r\n2018\r\n2019\r\n2020\r\n2021\r\n2022\r\n2023']);

Reference: What character represents a new line in a text area

tenshi
  • 56
  • 5