Clicking button to trigger more code (like onClick)

3 posts, 0 answers
  1. Dren
    Dren avatar
    10 posts
    Member since:
    Aug 2011

    Posted 15 Nov 2011 Link to this post

    Hi,

    I'm using the Telerik Testing Framework to create an automation framework to test our Silverlight application. There are a few instances where clicking a button requires a wait for another element on the screen to become usable. I wrap the button controls like so:

    public class Button
        {
            public RadButton Control;
             
            public Button() { }
     
            public Button(string automationId)
            {
                AutomationId = automationId;
                Control = Manager.Current.ActiveBrowser.SilverlightApps()[0].Find.ByAutomationId<RadButton>(automationId);
            }
     
            public string AutomationId { get; set; }
     
            public void Click()
            {
                this.Control.User.Click();
            }
    ....
    }

    In some cases, however, clicking on a particular button requires a wait for some other control. The test script should have no idea that it needs to wait for another control after clicking a particular button. So, where I'm initialising the button instance itself, I am thinking to pass in a string of a method which contains the code in order to wait for another control on the screen to become usable (or whatever other code it needs) - and will need to overload Button.

    But I'm not really sure what the best way is of doing this - I've had a look at InvokeMethod, maybe that will help?

    Is someone able to point me in the right direction?

    Thanks :)
  2. Dren
    Dren avatar
    10 posts
    Member since:
    Aug 2011

    Posted 17 Nov 2011 Link to this post

    Me again...
    Where I said:
    "So, where I'm initialising the button instance itself, I am thinking to pass in a string of a method which contains the code in order to wait for another control on the screen to become usable (or whatever other code it needs) - and will need to overload Button.
    But I'm not really sure what the best way is of doing this - I've had a look at InvokeMethod, maybe that will help?"

    - I've discovered that InvokeMethod invokes methods on the actual control itself (this information took me forever to discover) and not custom methods that I can write.

    Let me revise my question:

            public void Click()
            {
                Control.User.Click();
     
                if (_onClickMethod != null)
                {
    // ................ execute a custom method with the name _onClickMethod
                }
            }

    I need to be able to execute different code for different instances of my class (which happens to be called Button). I plan to pass this in as a string in _onClickMethod (on constructor). I thought InvokeMethod was the answer but as described above it's not what I'm looking for.

    Thanks!
  3. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 21 Nov 2011 Link to this post

    Hi Dren,

    I'm sorry for the delay getting back to you.

    If you haven't done so already, please check this article from our Code Samples section on "Wait for Element to Exist in Code". Near the bottom of this article you will find a simple example of how to wait for a Silverlight element to exist. Here is the code:
    CheckBox cbox = Pages.SilverlightGridControl.SilverlightApp.Get<CheckBox>(Pages.SilverlightGridControl.SilverlightApp.Expressions.Item0Checkbox, true, 33000);
    Note that the marked argument here is the XamlFindExpression. You can pass strings with the find expressions to its arguments. Here is an example:
    CheckBox cbox = Pages.SilverlightGridControl.SilverlightApp.Get<CheckBox>(new XamlFindExpression("AutomatioId=checkBox"), true, 33000);
    Also check this article for more information.

    Hope this helps!

    Greetings,
    Plamen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top