1
votes

I am writing a selenium automated test where I have to verify that the dates on the x-axis of the graph (shown) are correct. These dates change based on a drop down we have in the web application. (Ignore the arrow :))

enter image description here

I'm trying to generate the date in the MMM, YYYY format and compare it with the date elements in the graph

I have the following code so far:

 string circleDate2 = date.Month.ToString("MMM") + ", " + date.Year.ToString("YYYY");

however this just outputs MMM, YYYY on the console.

How do I generate the date in MMM, YYYY format and then add or subtract another month so I can verify all the date elements on the page?

1
I see that you are new to SO so please be careful when asking a question to put only the tags that are relevant to the question asked. selenium, testing, and automation aren't really relevant here. C# and maybe date should be good enough.JeffC

1 Answers

3
votes

To get the format you want use

string formattedDate = date.ToString("MMM, yyyy");

To add/subtract a month use DateTime.AddMonth, for example

DateTime previousMonth = date.AddMonths(-1);