I am trying to automate my UI tests on my Silverlight App.
I have a datePicker where I can choose one date (but only from "today").
For example, today I recorded a test and I choose the date of tomorow (24-11-2012). To months for now if I play this test, the date od 24.11.2012 won't be available for Test Studio to choose and Test Studio simply ignore this step.
How can I solve this problem?
Thank you.
Best regards,
Maria
4 Answers, 1 is accepted
You can use a Coded Step to read the system's current date, then add or subtract the desired number of days. Then input that value into the DatePicker text box.
I tested this against a Telerik Demo Site. I recorded a standard step of entering text into the DatePicker text box. Then I right clicked that step and selected Customize Step in Code. I changed the code to this:
//Get the current date
System.DateTime today = System.DateTime.Now;
//Use a positive number to add days or a negative number to subtract days
System.DateTime date = today.AddDays(-10);
//Set the DatePicker text box to the newly calculated date
Pages.TelerikExtensionsForASP.DatePickerText.Text = date.ToString(
"d/M/yyyy"
);
Anthony
the Telerik team
First of all I want to thank you for your quick reply.
My problem is that my DatePicker doesn't have any textbox. I can only select a date by clicking on it.
I have a pritnscreen of my datepicker as an attach file.
Is there any way I can do it without a textbox?
Thank you.
Best regards,
Maria
In that case you'll have find the element based on its calculated content, then click on it.
Here are sample test steps I recorded against this Silverlight site:
- Navigate to site.
- Click DatePicker in left column.
- Open picker calendar.
- Coded step.
You'll need to add the Calendar parent element to the Elements Repository by using the Add to Project Elements option from the Elements Menu (see attached screen shot). Now you can reference the Calendar in the coded step:
System.DateTime today = System.DateTime.Now;
//Get tomorrow's date
System.DateTime date = today.AddDays(1);
//Extract just the date digit
string
digit = date.ToString(
"%d"
);
//Search the calendar by the date digit text content and click it
Pages.SilverlightToolkitSamples.SilverlightApp.Calendar.Find.ByTextContent(digit).User.Click();
Kind regards,
Anthony
the Telerik team
Please be aware that my first suggestion is better and more reliable. Test Studio is often able to set the text of a field like this directly through the DOM, even if you cannot edit it through the UI.
So, instead of recording a Set Text step and then converting it to code, you should be able to locate the DatePickerText element in the DOM Explorer, right click it, show the Elements Menu, and add it to the project elements manually. Then you can reference it in a coded step and use the code from my first example.
Anthony
the Telerik team