XCUITest Element Snapshot Fails Blinking Cursor - xcuitest

We are using FBSnapshottestcase to take snapshots as part of our XCUITest cases. We have a ScrollView that has an UITextField. We type text into the text field and take a snapshot to verify the element behaves appropriately with text entered (a clear button appears). The problem we encounter is that when you type into the text field a blinking cursor appears. The tests will fail or pass depending on the state of the blinking cursor when the snapshot is taken. Is there a way to disable the blinking cursor for a XCUITest?

The devs added this to the AppDelegate file so that when we are running the test scheme it would do this:
#if LOCAL
if CommandLine.arguments.contains("--UITests") {
UITextField.appearance().tintColor = .clear
}
#endif
This hide the cursor then for the tests.
You can then you
app.launchArguments to pass "--UITests"
https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments

It is possible to set an optional parameter tolerance in FBSnapshotVerifyView call.
For example, if it is set to 0.01 and images are equal by 99% (counting in pixels) or more, then test will not fall.

Related

Restricting typing at a distance from the end on an input field

I have an input field, at the end of which i've created a character counter:
The problem is that now, it is possible to type beneath the counter which is no good:
I would like the typing area to be restricted a certain distance before the end of the input field, something like this:
I am aware of maxlenght but since the letters have different lengths i.e. you can fit 183 "i" but only 57 "W", which would make for a really unintuitive typing experience, if your typing is cut off at the middle of the field.
The two possible solutions that occur to me.
1.
Simply shortening the input and positioning the counter next to the input, then styling a common parent element to look like the input. This is the more simple and less error prone solution.
2.
This way is a bit more complicated, but basically what you would do is create a hidden element somewhere (NB not display: none;) with the same font size/weight/family and attach a keydown event handler to the input field.
In this handler you copy the contents on the input to the hidden element, measure the width in pixels and compare that to your input. If the difference is too small, you return false in your input handler, making sure you're not preventing the user from pressing delete or backspace first.
It should be noted however that this method is pretty difficult to get right and I would consider it to be the "dirty" solution.

setText jolts TextButton at inital position for a microsecond or two while movement is happening

I have an actor and I'm moving it by using moveTo(destinationx, destinationy, time).
The problem is that the actor is a TextButton and I need to change the text while the movement is happening and this poses a serious problem. It seems setText calls invalidate and invalidateHierarchy so when the method is called the position of the TextButton is reset to the initial position for a while so that the movement proceeds with a jolt (jump) of the text button position (position set at initialization - .center()).
All the dynamics of my actor movements are running as planned as long as I don't modify the text while Actions.moveTo is still running. If I do modify it then I see a jolt of the text at the moment I call setText.
How can I solve this pb?
I was able to reproduce your problem by placing a Button in a Table and using moveTo actions on the Button. The problem is that when a widget belongs to a Table, the Table is responsible for controlling the widget's position and size, so actions that affect the position will not work correctly.
If you are moving a widget around the screen to arbitrary positions, it doesn't make sense for you to keep it in a static Table anyway. If you add the Button directly to the stage, the problem goes away.
However, I discovered another problem. If the Button doesn't have a Table parent, it doesn't update its own size correctly when its text changes.
I found a solution. Place the Button in a Container and add the Container to the Stage. Use your MoveToActions on the Container that wraps the Button, not the Button itself.

TextField input not working

I am working on a class similar to the standard text field. I actually use the default TextField inside it. My only problem is that the textField does not work correctly. If I set it to textField.type = TextFieldType.INPUT, I can delete the text, but I can't enter new text. Also, the cursor is not being displayed. This is my Class (part of it): http://pastebin.com/LsgQjxpa
The skin is like this: http://pastebin.com/yDhEGHLm
I can't figure out what exactly I am doing wrong. I also have to mention that I am compiling for AIR Mobile and testing directly from Flash Builder
One problem appears to be that you have set the selectable property to false. This makes sense when type is TextFieldType.DYNAMIC. However, it's problematic when the type is TextFieldType.INPUT.
When you disable selection of the text, no cursor is displayed. I am able to still edit the text. However, since the cursor is not visible I cannot change it's position and the text gets added in front of any existing text.

How to Change Text Cursor Color of Text Input Flex 4?

I want to change the blinking text cursor color of Text Input in Flex 4...
How can I change it ?
Is there any way to handle it, or it can be only controlled by Flash Player ???
I had a similar question about this a while ago. I never found a way to update the actual cursor, so I got creative with the solution. My solution was to have two textfields stacked. One input field on top of a dynamic field.
Set the alpha of the input field to 0. Then, add a CHANGE event listener to the input field. In the handler, update the dynamic field and reposition your cursor based on the textWidth.
Not ideal, but it did the job.
I had solved this problem,
Actually there was a problem in skinning of text input.
If we set textinput skin's richeditabletext's alpha to 75 or some down value, flash player makes cursor color white itself.
So by increasing that alpha value, I got the cursor color black.
I change the TextField.textColor = OxFFFFFF, the cursor changes into white as well. Works for my case when I need the same color for the blinking cursor and text.

ActionScript Setting Caret Position In Text Layout Framework

i'm attempting to simply set the caret position at the start of the text flow when it is first displayed, without having to click and activate the text to see the blinking caret.
googling returns that the solution is to do this:
textFlow.interactionManager = new EditManager(new UndoManager());
textFlow.interactionManager.setSelection(0, 0);
however, setSelection() is not a valid function of the selection or edit managers.
1061: Call to a possibly undefined
method setSelection through a
reference with static type
flashx.textLayout.edit:ISelectionManager.
figured it out. for anyone else who ever has to deal with the nightmare that is the text layout framework documentation, you can automatically position and display the blinking caret after the text is displayed by writing this:
textFlow.interactionManager.selectRange(0, 0);
textFlow.interactionManager.setFocus();