Dynamic Date at playback actions on datepicker

5 posts, 0 answers
  1. Maria Isabel
    Maria Isabel avatar
    5 posts
    Member since:
    Nov 2011

    Posted 23 Nov 2011 Link to this post

    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
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 23 Nov 2011 Link to this post

    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
  3. Maria Isabel
    Maria Isabel avatar
    5 posts
    Member since:
    Nov 2011

    Posted 24 Nov 2011 Link to this post

    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

     
  4. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Nov 2011 Link to this post

    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
  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Nov 2011 Link to this post

    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
Back to Top