Katalon WebUI.SetMaskedText() randomly wrapping text - testing

I have a field in a popup to enter a phone number with masked text: "( _ _ _ ) _ _ _ - _ _ _ _".
(Masked text means that we are using jquery to automatically format the text being entered. You can learn more here.) The underscores above are just to represent the spaces for the digits of the phone number. :)
Results
The code randomly wraps the text when entering. I've tried using the string as '8015558245' and masked as '(801)555-8245', both wrap randomly with the results:
(015)558-2458
(155)582-4580
(555)824-5801
The only suggestion I found on my many searches of the internets was to double click the element first, which doesn't effect the results. Each time I run the test in incognito mode. Occassionally it works, the rest of the time it fails.
Code
Here is my code:
TestObject enterPhoneNumber = findTestObject('path/PhoneNumberObject')
WebUI.doubleClick(enterPhoneNumber)
WebUI.setMaskedText(enterPhoneNumber, '8015558245')
Specs
I am using Katalon v5.9.1, but it wasn't working on earlier versions either.
Chrome is the browser.

I think this might be happening because WebUI.doubleClick() is targeting the middle of the element so it starts typing somewhere behind the ().
Maybe try using WebUI.clickOffset(enterPhoneNumber,x,y) with a small value of x and y (5 px for example - calculated from the top left corner of the element) so you are sure click will land somewhere near the first (_ _ _ digit place.
Another option is using
WebUI.click(enterPhoneNumber)
WebUI.sendKeys(enterPhoneNumber, Keys.chord(Keys.HOME))
WebUI.setMaskedText(enterPhoneNumber, '8015558245')
with
import org.openqa.selenium.Keys
imported.

The answer was a combination of things:
First: I needed to set the cursor to the left of the masked text right at the opening parenthesis. To guarentee this, I used the suggested clickOffset(enterPhoneNumber, 40, 5). [Thanks #Matt Mrse for your suggestion!]
This didn't fix the text wrapping when using WebUI.setMaskedText(..), but it allowed for the next part to work reliably, and that is:
Second: Text entered into the box manually was always entered in correctly. So instead of WebUI.setMaskedText(..), I just sent the whole string as if it were typed by using WebUI.sendKeys(..).
The final code, that worked reliably (all other previous attempts failed within 1-2 attempts) after five test runs in five different tests is this:
WebUI.clickOffset(enterPhoneNumber, 40, 5)
WebUI.sendKeys(enterPhoneNumber, '8015558245')
WebUI.delay(1) //For humans to be able to see that text was entered correctly
That's it!
Hope this helps anyone else with this issue!

I think there are something you need to double check:
- are the () be added automatically when you typing the phone number?
- setMaskText() is used to enter text as '**************'
I am not sure if I understand the case clearly. Normally, I deal with this case by using sendKeys keyword, which will demostrate the typing action so the phone format can be added correctly.

Related

Add text box at specific location in report base on value

I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated.
Thanks,
Dave
I played around with the monospace font idea. It isn't as pretty as I would like but I'm getting closer.
The issue is that I cannot keep the text in the same spot in each box. There is one line lower on the page that pushes the number almost out the right side of the box.
Sample Output
This code is functional but I'm looking at the cosmetics. I'm inserting spaces between my values using the following function:
Private Function InsertSpaces(CutLen, PieceLen) As String
MaxChar = 50 ' 6 inch 14pt Courier text box
cutchar = Int(CutLen / PieceLen * MaxChar)
Cutcharcount = Len(Str(CutLen))
cutchar = cutchar - Cutcharcount + 1
For i = 1 To cutchar
InsertSpaces = InsertSpaces + " "
Next
End Function
I'm just trying to clean it up. CreateReportControl was giving me a error because I wasn't in design mode. I'm guessing that is because it ran as part of OnFormat of the Detail section.

How can I output tabs in the console?

When I used to code in python there was a \t function when printing to leave a gap x amount of spaces until it reaches the next tab line, this was very useful for displaying tables in the console as all the bars would line up even when the data was of varying length. I've looked but can't seem to find a corresponding function in vb, wondering if anyone knew of one?
Thanks to #previousbetine and #Anu6is
Use VbTab and review this docs page regarding other ControlChars such as VbCrLf.
Thanks to #dbasnett for finding this docs page as well.

Searching for specific text in SmarTerm via VBA

I'm looking to search for a specific line of text in a SmarTerm application window opened via VBA and then copy the rest of the row of data into a cell in a worksheet. Previously this was accomplished using a reflection session but I now have no option other than to use SmarTerm.
The code that worked with reflection is:
Found = Session.FindText("SEARCH TEXT", 0, 0)
If Found Then
str_get_string_from_reflection = .GetText(Session.FoundTextRow, 19, Session.FoundTextRow, 60)
Trim (str_get_string_from_reflection)
rng_range_constants_col_A.Offset(0,3).Value = "Search Text: " & str_get_string_from_reflection
End If
Sadly this doesn't work with the SmarTerm solution, I've tried using the Session.StringWait.MatchString command but this doesn't seem to search in the entire visible screen.
Any help that can be offered here will be very much appreciated
I've tried using the SmarTerm Macro Guide (http://www.esker.com/fm/others/eval-smarterm/bin1211/macro.pdf) but can't locate anything other than StringWait.MatchString or StringWait.MatchStringExact that supports searching in the available text. Sadly this only seems to search on the last line of the text, rather than on the whole visible screen.
You could use Session.ScreenText(row, col, page, chars)

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Working with Unicode in VBA StrConv

I have an Excel file and a userform where user can type in students' details and the form will check for duplication and then add the info onto the last line of a table. I want to improve it further by making the form capitalize the first letter of each name using this code:
Me.Surname.Value = StrConv(Me.Surname.Value, vbProperCase)
Me.Surname.Value is the input of the form, mostly Vietnamese such as Trần, Nguyễn, Thảo, etc. However, they are changed into something like Tr?n, Nguy?n, Th?o after going through StrConv. I read some suggestions and change my locale to Vietnamese but the problem persists.
Do you have any suggestion to fix this? I am thinking of converting the inputs into hex value and then write them down using ChrW(), but I can't find a way to do that.
I played a bit with this and the culprit seems to be StrConv.
It works for me if instead of using StrConv I explicitely set the proper case:
Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(Surname.Text, 2)
or even more precise:
Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(LCase(Surname.Text), 2)