RoutedEventArgs not generated by User.Click

4 posts, 0 answers
  1. Maylad
    Maylad avatar
    5 posts
    Member since:
    Jan 2019

    Posted 03 Jan Link to this post

    Hello,

    Recently I have started using Testing Framework to test WPF applications (MVVM). Maybe it's the novice's problem but i can't generate RoutedEventArgs on my_button.User.Click(); Operations like TypeText() or Click() should be treated like a normal user actions, aren't they?

     

    I am trying something like this:

     _wpfWindow.Find.ByName(UI_Components.Button_LogIn).User.Click();

    or

     _wpfWindow.Find.ByName(UI_Components.TextBox_Name).User.TypeText(login, 1, 5, true);

     

    During click on LogIn Button (by real mouse)  is activating method, by Click() option not. The same problem I have with generating events for KeyPress:

    private void OnKeyDownPressed(object sender, KeyEventArgs e)
    {
              if (e.Key == Key.Enter)
                      runXXX();
    }

    private void OnLoginButtonClick(object sender, RoutedEventArgs e)
    {
               runXXX();
    }

    How can i fix it or generate KeyEventArgs or RoutedEventArgs. Btw. I couldn't change the code from this both methods, necessary condition.

    Greetings.

  2. Nikolai
    Admin
    Nikolai avatar
    110 posts

    Posted 08 Jan Link to this post

    Hello Michal,

    Thank you for the detailed description provided. 

    The behavior you have faced, may occur sometimes against heavier apps or slower machines. The testing framework extension needs to configure the app in order to trigger the proper event chain.

    A small wait on the test side after the application launches, should fix the issue: 

    this.Manager.LaunchNewApplication(@"C:\Temp\DemoWpfApp.exe");
    System.Threading.Thread.Sleep(5000);

    I'm attaching a DemoWpfApp , which you can use to run the below simple test against:

    this.Manager.LaunchNewApplication(@"C:\Temp\DemoWpfApp.exe");
    System.Threading.Thread.Sleep(5000);           
     
    var button = this.ActiveApplication.MainWindow.Find.ByName<Button>("MyButton");           
    button.User.Click();

    If the "Click()" is successful all the routed events should be triggered:
     1. "PreviewMouseDown"
     2. "PreviewMouseUp"
     3. "Click"

    Please give a try to the proposed solution and let me know if any further assistance will be necessary. 

    Thank you in advance for your cooperation. 

    Regards,
    Nikolai
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Maylad
    Maylad avatar
    5 posts
    Member since:
    Jan 2019

    Posted 14 Jan in reply to Nikolai Link to this post

    Thank you for the answer, I will try and then I let you know
  4. Nikolai
    Admin
    Nikolai avatar
    110 posts

    Posted 16 Jan Link to this post

    Hi Maylad,

    Take your time and if the issue persist please let us know. Additionally, we use Test Studio to automate most of our internal web and desktop apps, so if our internal testers find something similar I'll let you know as well.

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