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

RichTextBox questions

6 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shashi
Top achievements
Rank 1
Shashi asked on 10 Apr 2014, 03:19 AM

Hello,

I am writing a test to work on a RichTextBox (Silverlight) which has several hundred Text Box elements.  Tasks include both typing in as well as content verification.  I have run into a couple of issues - hoping someone can help.

a) I am trying to type in a string at a specific location (for example, in between two text elements).  I have written a coded step (clicks on one of the text boxes) that gets the cursor to the correct position.  I then have a Type Text statement (tried both recorded as well as a coded step) that types in a string.  I am expecting the string to be typed in at the cursor position - however, the text shows up somewhere above the cursor (on a different line). 

Is there anything I can do to get the test to type in at the desired location?

Here is the relevant code:

// LeftClick on Textblock10
RashOnTheTextblock2.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 73, 43, ArtOfTest.Common.OffsetReference.TopLeftCorner, ArtOfTest.Common.ActionPointUnitType.Percentage, ((System.Windows.Forms.Keys)(0)));
 
// Type 'upperarm' into RichTextEditorClinicalNoteRichtextbox5
RichTextEditorClinicalNoteRichtextbox5.User.TypeText("upperarm", 10, 100, true);



b) Is there a fast way to collect all the text boxes in the RichTextBox into an IList or another collection element and/or to find all TextBlocks matching a certain text or another property?  

Here is my current code:

IList<TextBlock> rtbCurrentPNLines;
 
// Get all lines in the current progress note.
// NOTE:  The array will contain lines that are empty or are not visible to the eye in the Progress Note ("Spelling Suggestions", "Name:", "Url" - these are the last 3 lines in the array).
rtbCurrentPNLines = rtbNote.Find.AllByType<TextBlock>();

 

// Get all instances of multiply occurring text (that this test will use)
// 'PROBLEM '
PROBLEMTextBlocks = PNContents.Where<TextBlock>((a_) => (a_).Text.Equals("PROBLEM ")).ToList<TextBlock>();

The problem with both the above is that it takes several seconds to execute each of the above - the first one takes 20+ seconds for about 600+ Text Blocks.    Further, I have to do this multiple times as the contents are changing during the test and verifications have to be done after those changes.  So, as you can imagine, running time of the test is increasing dramatically as the test is further developed. 

NOTE:  None of the text boxes have x:Names or Automation IDs and there are several duplicates - so simple recorded steps for text block verifications does not work.  Content of the note is dynamically generated (they are not in a xaml file).  GIven current release schedules, it is highly unlikely that devs will have time to modify the code to assign x:Names or Automation IDs for us to reference elements directly.

Any help for the above questions would be greatly appreciated.  By the way, I need solutions that will work with the version of TS that I am using (see my signature below).  We do plan to upgrade to a more recent version- but that won't be for a couple of months (at least). Again, the app is a Silverlight application.

Thanks,
Shashi
Test Studio 2012.2.1420.0

6 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 15 Apr 2014, 08:00 AM
Hi Shashi,

I am a little confused. The step clicks on TextBlock10, however the second one types the text in RichTextEditorClinicalNoteRichtextbox5. Where it should type the text, in which text field?

You can directly use this code

RichTextEditorClinicalNoteRichtextbox5.User.TypeText("upperar", 10, 100, true, true);
 
without the clicking step. This constructor clicks on the richtextbox also.

Regarding the collecting of all rich textboxes, this is probably the best way which C# allows how to collect them.

Hope this helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Shashi
Top achievements
Rank 1
answered on 15 Apr 2014, 10:45 AM
Hi Boyan,

Let me clarify:
a) The RichTextBox already has a lot of existing text - which are represented as 600+ TextBox elements (all of which are descendant elements of the RichTextBox) in the DOM.
b) I am trying to type in text at a specific location which is usually between 2 text boxes - not at the start or at the end of the RichTextBox.

The first click is intended to place the cursor at the location where I want to insert the text and the subsequent TypeText is to actually type in the new text.  Problem is that the cursor seems to appear at the correct position but the text appears somewhere above it. 

You said that the TypeText statement clicks on the RichTextBox.  Question is where does it click?  It looks like it ignores the cursor position and there is no way to configure this (no parameters to specify cursor position).  Is there a way to get it to click at a specific location - or another Type statement that would enable me to do this?  Again, the scenario is that we are adding text to a RichTextBox with pre-existing content - which is NOT typed in by the test.

Thanks,
Shashi 
0
Boyan Boev
Telerik team
answered on 18 Apr 2014, 06:35 AM
Hello Shashi,

I am not sure if I understand you correctly.

Please send me a video or a screen shot of the location where you want to type the text or the whole scenario.

Jing is great for this.

Looking forward to hearing from you.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Shashi
Top achievements
Rank 1
answered on 30 Apr 2014, 12:10 AM
Sorry for the delay in responding.

Take a look at the attached screen shot.  You can see a RichTextbox control on the left with a couple of lines of text.  The panel on the right shows part of the corresponding DOM (picture from First Floor's Silverlight Spy).  The selected text box in the DOM is the text highlighted in red in the RichTextBox control.  What I want to do is to record steps to place the cursor between the "*" and the ">>" text blocks and type in more text - the new text would then become a new TextBox in the RichTextBox control's DOM located between the two text blocks. 

NOTE:  I am looking for a solution which will work for typing in between any two text boxes - not just the ones above.

I think I have solved the problem - the code at the end of this post seems to be working and doing what I want to do.  First statement clicks at the end of the first text block (uses RenderSize.Width and RenderSize.Height) and the second statement types in the string starting from that position.  Please let me know if you see any issues or if you know of a better way.

Thanks,
Shashi

    // LeftClick at the end of the first text block
    FirstTextBlock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, (int)FirstTextBlock.RenderSize.Width, (int)FirstTextBlock.RenderSize.Height, ArtOfTest.Common.OffsetReference.TopLeftCorner, ArtOfTest.Common.ActionPointUnitType.Percentage, ((System.Windows.Forms.Keys)(0)));
 
    FirstTextBlock.User.TypeText(stringToType, 10, 100, true);
}




0
Shashi
Top achievements
Rank 1
answered on 01 May 2014, 04:46 PM
Boyan,

Upon further testing, I found that my solution above gets me most of the way but there is still a small issue.  The vertical position of the typed text is correct (i.e. it appears on the correct line) but its horizontal position is not (it either appears too far to the right or it appears to the left of FirstTextBlock) - I need it to appear next to the right edge of FirstTextBlock.

Can you see any issue with the above code which would explain what I am seeing?  If so, what do I need to do to fix it?

Thanks,
Shashi
0
Konstantin Petkov
Telerik team
answered on 05 May 2014, 06:37 AM
Hello Shashi,

This looks like you will have to deduct the width value in your Click method call so that it can click on the exact position you need.

Another approach would be to operate with the exact element rectangle in order to click on the right position. Again you may have to adjust the actual point to click via some offset according to your needs. Here is a sample code that should represent the idea:

/// <summary>
/// Triggers mouse click from the given type on a text box position calculated
/// with the given offset from the top left or right of the text box.
/// </summary>
/// <param name="clickType">The mouse click type.</param>
/// <param name="offset">The offset to calculate the click point from.</param>
/// <param name="offsetFromLeft">Whether to add the offset from the bottom left or bottom right of the text box.</param>
public void MouseClick(MouseClickType clickType, int offset, bool offsetFromLeft)
{
    System.Drawing.Rectangle textBoxRectangle = this.GetScreenRectangle();
    int x = 0;
    if (offsetFromLeft)
    {
        x = textBoxRectangle.Left + offset;
    }
    else
    {
        x = textBoxRectangle.Right - offset;
    }
     
    int y = textBoxRectangle.Y + ((textBoxRectangle.Bottom - textBoxRectangle.Y) / 2);
    System.Drawing.Point clickPoint = new System.Drawing.Point(x, y);
 
    this.Application.Desktop.Mouse.Click(clickType, clickPoint);
}


Regards,
Konstantin Petkov
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Shashi
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Shashi
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Share this question
or