Ajax Calendar - Random date selection

4 posts, 1 answers
  1. Riglet
    Riglet avatar
    8 posts
    Member since:
    May 2011

    Posted 04 Jul 2011 Link to this post

    Hi,

    I encounter some trouble with testing a specific part of our application. I try to test the calendar availability during the purchase path. I made a logical step "while" there is no availability -> switch to next month.

    This works, but I also want to book for a random day if there is availability.
    For example, on this page, the calendar at the bottom :
    http://www.weekendesk.fr/week-end/4398/week-end-a-Courseulles-sur-Mer-Normandie-Week-ends_gourmands

    One of your Solutions Consultant told that it has to be a coded step. Can someone help me ?
     
    Thanks,

    Pierre
  2. Answer
    Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 04 Jul 2011 Link to this post

    Hello Riglet,
          yes, this sounds like something that can only be done in code. I've put together a working example for the calendar at the bottom of your page. Keep in mind that there's more than one possible solution to this automation task and it's quite possible that there's a simpler (i.e. better) way to do it.
    Also it seems that currently your application is never well equipped for UI Automation. Check out this article:
    http://blogs.telerik.com/daniellevy/posts/11-03-01/best_practices_element_identification_with_id_and_automationid.aspx

    I took a close look at the DOM Tree of the app in order to determine the best way to distinguish between available and unavailable dates. It seems that the easiest way is based on the class (screenshot 1).

    Here's the code I used along with comments explaining how it works:
    Pages.WeekEndCourseullesSurMer.WeekendFormFormTag.ScrollToVisible(ScrollToVisibleType.ElementBottomAtWindowBottom); //We scroll to the date picker so that we can see the click occuring
     
                HtmlUnorderedList calendar = Find.ByExpression<HtmlUnorderedList>(new HtmlFindExpression("class=days")); //The Date Picker is actually an HTML List. We use the class name days to locate it. Both calendars have the same class name so this returns the first one. You can Find.AllByExpression to get the second one. The logic is applicable for both of them.
     
                LinkedList<HtmlListItem> availableDates = new LinkedList<HtmlListItem>(); //We initalize a collection to store all "available" (i.e. green of purple) dates from the calendar
     
                foreach (HtmlListItem i in calendar.Items) //Go through all the dates in the calendar. The dates are actually HTML List items
                {
                    if (i.CssClass.Equals("promotion") || i.CssClass.Equals("active")) //Green dates belong to class "promotion" while the purple one belongs to class "active"
                    {
                        availableDates.AddLast(i); //If the date checks out as "available" we added to the list
                    }
     
                }
     
                Random r = new Random();
                int randomNum = r.Next(availableDates.Count); //We generate a random number which will corespond to an item in our list
                LinkedListNode<HtmlListItem> l = availableDates.First; //l will be the date we're going to select in the Calendar
     
                while (randomNum != 0) //This loop moves up the linked list until we reach the node that coresponds to our randomly generated number
                {
                    l = l.Next;
                    randomNum--;
                }
     
                l.Value.MouseClick(); //Click on the node after we reach it in the list

    I've attached a fully functional test to this post. Let me know if you need any further assistance on this task.

    All the best,
    Stoich
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?
  3. Riglet
    Riglet avatar
    8 posts
    Member since:
    May 2011

    Posted 04 Jul 2011 Link to this post

    Hello,

    Thanks for the reply.

    I tried to launch your test in Test studio to see how this works. But I get this error :
    Compilation Failed - 1/1 coded steps failed to compile.
     
    And the details in the log :
    d:\Users\priglet\Documents\Test Studio Projects\282644_WebTest3\WebTest3.tstest.cs: Line 14: (CS0234) The type or namespace name 'WebAii' does not exist in the namespace 'Telerik' (are you missing an assembly reference?)
    d:\Users\priglet\Documents\Test Studio Projects\282644_WebTest3\WebTest3.tstest.cs: Line 15: (CS0234) The type or namespace name 'WebAii' does not exist in the namespace 'Telerik' (are you missing an assembly reference?)

    Do I have to re-do the test case ? Or is it a setting ?

    Thanks,

    Pierre

  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 04 Jul 2011 Link to this post

    Hi Riglet,
          this is a know issue. We haven't fixed it yet because we're unable to reliably reproduce it. It appears seemingly randomly. You can resolve the problem easily by adding the necessary references. You need to add project references to all the DLLs located in this folder:
    C:\Program Files (x86)\Telerik\WebUI Test Studio 2010.3\Bin\Translators
    Here's a Jing video demonstrating how this is done:
    http://www.screencast.com/users/TelerikTesting/folders/Jing/media/ecd4fe86-1318-4b0f-b2db-f750215f6106

    Greetings,
    Stoich
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?
Back to Top