Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Replace calls to FXRobot with Event.fireEvent. #355

Merged
merged 4 commits into from Mar 14, 2017

Conversation

brcolow
Copy link
Collaborator

@brcolow brcolow commented Jan 18, 2017

Ref #228

@brcolow
Copy link
Collaborator Author

brcolow commented Jan 18, 2017

It is really quite interesting. There are currently two failing tests:

keyPressTypeRelease_korean_text and keyPressTypeRelease_english_text.

For some reason the text area text contains everything but the first line (and apparently the first tab character). I am really not sure what would cause this. I tried replacing the Guava Lists.charactersOf usage with a Java 8 lambda but got the exact same result.

@hastebrot
Copy link
Member

hastebrot commented Jan 18, 2017

Review notes. Need to check:

  • signature of KeyEvent.KEY_RELEASED, key, ""
  • signature of KeyEvent.KEY_PRESSED, key, ""
  • signature of KeyEvent.KEY_TYPED, key, character

@brcolow
Copy link
Collaborator Author

brcolow commented Jan 26, 2017

If the tabs are removed from the text like so:

String text = "All in the golden afternoon\n" +
        "Full leisurely we glide;\n" +
        "For both our oars, with little skill,\n" +
        "By little arms are plied;\n" +
        "While little hands make vain pretence\n" +
        "Our wanderings to guide.";

then the text-area contains no text at all.

If a tab character is added at the beginning (so that the tab character is the first character of the text) like so:

String text = "\tAll in the golden afternoon\n" +
        "\tFull leisurely we glide;\n" +
        "For both our oars, with little skill,\n" +
        "\tBy little arms are plied;\n" +
        "While little hands make vain pretence\n" +
        "\tOur wanderings to guide.";

then all the text is there except the initial tab character.

If a tab character is pressed, typed, and released first:

private void typeText(String text) {
    keyPressTypeRelease(KeyCode.TAB, String.valueOf('\t'));
    for (char character : Lists.charactersOf(text)) {
        KeyCode key = KeyCode.UNDEFINED;
        key = (character == '\n') ? KeyCode.ENTER : key;
        key = (character == '\t') ? KeyCode.TAB : key;
        keyPressTypeRelease(key, String.valueOf(character));
    }
    robotAdapter.timerWaitForIdle();
}

then the assertions pass and no tests fail.

I am very confused. Is it possible that maybe the text-area is not focused and tabbing switches focus to it?

Edit: It would seem that my supposition was indeed correct...the TextArea does not have the focus before the typeText method is called. The focus is owned by the TextField. I am not sure how Event.fireEvent fits in to this, need to investigate more.

@brcolow brcolow force-pushed the internal-api branch 2 times, most recently from 07ed404 to 0c23472 Compare January 27, 2017 00:33
@brcolow
Copy link
Collaborator Author

brcolow commented Jan 27, 2017

There is a system property that FXRobot uses to set that it should print debugging hints, fxrobot.verbose. Setting it to true allows us to see the events injected into the event thread by FXRobot. Unfortunately there is actually a bug and key events are printed incorrectly:

PlatformImpl.runLater(() -> {
    out("doKeyEvent: injecting: {e}");
    FXRobotHelper.sceneAccessor.processKeyEvent(target, e);
});

This just prints:

 [FXRobot] doKeyEvent: injecting: {e}

Maybe template Strings like that were a planned feature? Who knows. Anyways, at least we can see the mouse events. I added some debugging statements to the new code that mimic the ones from BaseFXRobot and as far as I can tell the mouse events are identical:

Old code:

org.testfx.service.adapter.impl.JavafxRobotAdapterTest > keyPressTypeRelease_english_text STANDARD_OUT
    [FXRobot] doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1284085598@33ed318d, target = javafx.event.Event$$Lambda$79/1284085598@33ed318d, eventType = MOUSE_MOVED, consumed = false, x = 150.0, y = 213.0, z = 0.0, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    [FXRobot] doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1284085598@33ed318d, target = javafx.event.Event$$Lambda$79/1284085598@33ed318d, eventType = MOUSE_PRESSED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, primaryButtonDown, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    [FXRobot] doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1284085598@33ed318d, target = javafx.event.Event$$Lambda$79/1284085598@33ed318d, eventType = MOUSE_RELEASED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    [FXRobot] doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1284085598@33ed318d, target = javafx.event.Event$$Lambda$79/1284085598@33ed318d, eventType = MOUSE_CLICKED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]

New code:

org.testfx.service.adapter.impl.JavafxRobotAdapterTest > keyPressTypeRelease_english_text STANDARD_OUT
    doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, target = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, eventType = MOUSE_MOVED, consumed = false, x = 150.0, y = 213.0, z = 0.0, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, target = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, eventType = MOUSE_PRESSED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, primaryButtonDown, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, target = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, eventType = MOUSE_RELEASED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]
    doMouseEvent: injecting: MouseEvent [source = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, target = javafx.event.Event$$Lambda$79/1456862715@10bfbd43, eventType = MOUSE_CLICKED, consumed = false, x = 150.0, y = 213.0, z = 0.0, button = PRIMARY, pickResult = PickResult [node = null, point = Point3D [x = 150.0, y = 213.0, z = 0.0], distance = 1.0]

I forgot to add [FXRobot] to the beginning of the print statement so it doesn't line up exactly, but all the numbers appear to be identical.

However what is different is that after the mouse events are run, the old code has the TextArea focused and the new code incorrectly has the TextField focused.

@brcolow brcolow force-pushed the internal-api branch 8 times, most recently from 625239f to 07a3492 Compare January 28, 2017 00:40
@brcolow
Copy link
Collaborator Author

brcolow commented Mar 14, 2017

I still am puzzled by this one difference...but I think it's safe to merge this because the input/outputs are identical...and I don't want to hold up Java 9 support any longer. If this becomes a nightmare of people getting failed tests, I will revert the respective changes.

@brcolow brcolow merged commit 4853801 into TestFX:master Mar 14, 2017
@brcolow brcolow deleted the internal-api branch March 14, 2017 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants