Identify controls on page dynamically and fill data into it

5 posts, 0 answers
  1. Blessy Antony
    Blessy Antony avatar
    6 posts
    Member since:
    Feb 2010

    Posted 15 May 2013 Link to this post

    Hi,

    I'm using the Telerik test studio to create tests for my Silverlight application.
    Running into a scenario where I'm unsure how to proceed.

    Now - my application has dynamically generated dataforms. Meaning, I've created the data entry forms dynamically using Class properties. To show/hide columns I've used data annotations - [Display(AutogenerateField=True)], I'm reading through each class properties and generating controls like RadMaskedTextBox, checkbox, RadComboBox, RadDateTimePicker (mostly telerik) controls etc.
    I have a lot of forms like these. To test these forms, I do not want to create an object for each of these controls in each form in the telerik test application.
    Instead I want to dynamically identify the following controls on whichever form i navigate to:
    1. Required fields (in my case properties with [Required] attribute on it), whose labels appear in bold
    2. Different types of controls like RadDateTimePicker (properties of type datetime/datetime?), Checkbox (properties of type boolean), RadComboBox, RadMaskedTextBox, RadMaskedCurrencyInput, UserControl (customized to display radio buttons, browse control, upload controls)

    #1 is on priority since I can get my Add new to work without validation errors.
    #2 is necessary for Add/Edit forms and add/modify values in various controls.

    Once I can get these controls dynamically in my test application I should be able to fill data into it and perform save operation.

    Till now I was able to record my form filling activity in the test application. But this approach creates an object for each control of each form in the project. The project is quite large and I don't wanna end up making n number of objects in my test application. I want to be able to reuse the tests for the forms which are generated dynamically thus reducing application size, time and effort spent to create tests.

    Attached find a zip file with 2 sample projects -
    1. Sample Silverlight project where i have implemented a part of our project's structure i.e. Dynamically generated 2 forms based on class properties. Used a common view and 2 different view models.
    2. Sample Telerik Test Project in which I recorded the actions done on my SL project.
    Then I customized each step in code to check what exactly occurred.
    As you can see in the sample - A different object was created for each control - the textbox, date time control, combobox etc for each form. Although the controls are actually the same..

    I need a way to 1. dynamically load these controls and fill data into it or 2. have only one instance of this control object in my test application and still be able to access it for any form.

    Kindly help.
  2. Blessy Antony
    Blessy Antony avatar
    6 posts
    Member since:
    Feb 2010

    Posted 15 May 2013 Link to this post

    Unable to upload my zip file onto this post. Its 1.49mb in size. Please let me know where to upload this file.
  3. Ivaylo
    Admin
    Ivaylo avatar
    782 posts

    Posted 16 May 2013 Link to this post

    Hello Blessy,

    I am sorry you are not able to attach the project, I have shared a dropbox folder and send an invitation to your email address. Please upload the project there so we can take a look.
    In the mean time you can take a look at this article where you can find out how to merge page nodes.

    Looking forward to hearing from you.

    Kind regards,
    Ivaylo
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  4. Blessy Antony
    Blessy Antony avatar
    6 posts
    Member since:
    Feb 2010

    Posted 17 May 2013 Link to this post

    Hi Ivaylo,

     I have uploaded the project into the dropbox. Please take a look.

    Also, I think the article you mentioned talks about merging page nodes. My scenario is that the Silverlight forms are being generated automatically during Add / Edit using the same set of controls. The issue I'm facing is that I was not able to identify these controls dynamically - using code. While trying to do this for some static Radbutton controls in my application - I was able to identify and click some buttons. Here is how I did this:

     
    (Pages.Page1.SilverlightApp.Find.ByTextContent("My Button") as  FrameworkElement).User.Click(MouseClickType.LeftClick);


    This way I did not have to add MyButton control onto my telerik Test application.I need to be able to find my RadMaskedTextBox, checkbox, RadComboBox, RadDateTimePicker (mostly telerik) controls like this.But since the controls are dynamically generated - I'm not able to get their names, or rather unable to figure out what exactly to search for.Searched the DOM to find that on clicking textbox - the DOM takes me to a TextboxView tag. Similarly for Datetime control, it seems like the whole style element is generated in the DOM.Hope this additional info helps.
    Kindly suggest a way to achieve this.

  5. Ivaylo
    Admin
    Ivaylo avatar
    782 posts

    Posted 17 May 2013 Link to this post

    Hello Blessy,

    In order to achieve the scenario you would like you will have to edit the find logic of the elements to use identical filters. For example you have two elements in the elements repository Item0Radcombobox and Item0Radcombobox0. Both elements are using XamlPath in the find logic and the path is different as you can see from the image attached. That is why you have the element added ending with 0. In order to merge these elements into one and reuse it you will have to edit the find logic as shown in this short video
    Please proceed the same way with the other elements like EnterDateRaddatetimepicker/EnterDateRaddatetimepicker0. Configured this way you will be able to reuse your coded steps. 
    Another way you can proceed is with data binding and test as step when filling the form, you can slightly modify the coded step and add the common steps in test as step. When you are filling the form just you can call the Test as step instead. Here is a short video on how to proceed.

    Hope that helps.

    Regards,
    Ivaylo
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top