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

TypeText only sends a few letters to TextBox

2 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Sep 2016, 09:37 AM

Hi,

I am quite new to Telerik and I am trying to set up automated tests for our WPF application. Whenever I try to use 'bar.User.TypeText("SomeText", 200)' to a framework element (found using 'FrameworkElement bar= foo.MainWindow.Find.ByAutomationId("New_Proj_Text_Box");') it sends a couple of letters to the TextBox, but then it cuts stops sending text.

 

I think that this may be something to do with the window loading as the TextBox is in a Modal window and when you open the modal window mmanually (rather than using the link via Telerik) SendText sends all the text to to the TextBox.

 

I have tried to introduce an "ensureClickable", changed the times for the "keyPressTime" and changing the clickFirst argument (trying both True and False). Unfortunately none of these seem to work.

 

I have placed my test below. Unfortunately there are no helpful errors in the logs.

 

Any help on this would be hugely appreciated.

 

Many thanks in advance,

 

David

 

 

using ArtOfTest.WebAii.Controls.Xaml.Wpf;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Wpf;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject2
{
    /// <summary>
    /// Summary description for TelerikNUnitTest1
    /// </summary>
    [TestClass]
    public class TelerikNUnitTest1 : BaseWpfTest
    {

        private TestContext testContextInstance;

        public WpfApplication foo { get; private set; }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>

        [TestMethod]
        public void Open_Application()
        {
            
            Settings mySettings = new Settings();
            mySettings.ClientReadyTimeout = 60000;

            /// Use my Settings object to construct my Manager object
            Manager myManager = new Manager(mySettings);
            myManager.Start();

            // Launch the application instance from its location in file system
            WpfApplication fubar = myManager.LaunchNewApplication(@"C:\Users\e-ddcr\Documents\appLocation\Fubar.Startup.exe");

            /// Validate the title of the homepage
            ArtOfTest.Common.UnitTesting.Assert.IsTrue(fubar.MainWindow.Window.Caption.Equals("MainWindow"));
            //TestContext.WriteLine("Validated window");

            ///Click the new project button
            FrameworkElement newProjButton = fubar.MainWindow.Find.ByTextContent("New project...");
            newProjButton.User.Click();

            ///Send keys to the project name textbox
            FrameworkElement projNameTextBox = fubar.MainWindow.Find.ByAutomationId("New_Proj_Text_Box");
            projNameTextBox.EnsureClickable();
            projNameTextBox.User.Click();
            projNameTextBox.User.TypeText("PokeMoon", 100);
                 
        }

    }

}

2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 20 Sep 2016, 09:55 AM
I managed to fix this by using a 'projNameTextBox.Wait.ForNoMotion(5000);' before clicking the TextBox Element. Other 'Wait.For' methods did not seem to work.
0
Georgi
Telerik team
answered on 21 Sep 2016, 12:50 PM

Hello David,

Usually when there is some animation playing or some other action that needs to be waited indeed Wait.ForNoMotion is the method to go to. Please note that you can set initial wait, time interval on which the framework to check if the element is in motion, and timeout like this:

element.Wait.ForNoMotion(250, 250, 30000)

Also here are some other tips that you might find useful:

   - When opening a new window (dialog as well) you might want to tap in to that window and search only in it by using the WaitForWindow method.

   - When searching you can use the generic find methods and pass the control type as parameter. This way you can work with the properties and methods that are specific to the control and are not present for the FrameworkElement class. For example instead of using Framewokrelement.User.TypeText method you can use TextBox.SetText method which provides more parameters for different needs. This is very helpful when working with RadControls as they would provide you with helpful suit of properties and methods like ComboBox SelectItem(string itemText, bool openDropDown) method.

var combo = Application.Find.ByAutomationId<RadComboBox>(comboId);
combo.SelectItem("PokeMoon item", true);

   - Use Refresh methods when needed. More information you can find here.
 
   - You might find helpful using Find.AllBy methods with LINQ:

var menuItem= Application.Find.AllByType<RadMenuItem>().Where(item => item.TextBlockContent == "File").FirstOrDefault();

Hope this would be helpful.


Regards, Georgi
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or