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

Clicking button to trigger more code (like onClick)

2 Answers 90 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dren
Top achievements
Rank 1
Dren asked on 16 Nov 2011, 02:09 AM
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 Answers, 1 is accepted

Sort by
0
Dren
Top achievements
Rank 1
answered on 18 Nov 2011, 05:21 AM
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!
0
Plamen
Telerik team
answered on 21 Nov 2011, 03:10 PM
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.
Tags
General Discussions
Asked by
Dren
Top achievements
Rank 1
Answers by
Dren
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or