This is a migrated thread and some comments may be shown as answers.

Dynamic Date at playback actions on datepicker

4 Answers 224 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Maria Isabel
Top achievements
Rank 1
Maria Isabel asked on 23 Nov 2011, 06:45 PM
Hello,


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

Sort by
0
Anthony
Telerik team
answered on 23 Nov 2011, 08:17 PM
Hi Maria Isabel,

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");
 All the best,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Maria Isabel
Top achievements
Rank 1
answered on 24 Nov 2011, 10:56 AM
Hello,

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

 
0
Anthony
Telerik team
answered on 28 Nov 2011, 08:23 PM
Hello Maria Isabel,

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:

  1. Navigate to site.
  2. Click DatePicker in left column.
  3. Open picker calendar.
  4. 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anthony
Telerik team
answered on 28 Nov 2011, 11:31 PM
Hello Maria Isabel,

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.

Best wishes,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Maria Isabel
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Maria Isabel
Top achievements
Rank 1
Share this question
or