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

(fix) WriteRobot::write() to prefer the Scene of the focused window. #239

Merged
merged 1 commit into from
Dec 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.stage.Window;

import com.google.common.collect.Lists;
import org.testfx.api.annotation.Unstable;
Expand Down Expand Up @@ -61,13 +62,15 @@ public WriteRobotImpl(BaseRobot baseRobot,

@Override
public void write(char character) {
pushCharacter(character);
Scene scene = fetchTargetWindow().getScene();
typeCharacterInScene(character, scene);
}

@Override
public void write(String text) {
Scene scene = fetchTargetWindow().getScene();
for (char character : Lists.charactersOf(text)) {
pushCharacter(character);
typeCharacterInScene(character, scene);
sleepRobot.sleep(SLEEP_AFTER_CHARACTER_IN_MILLIS);
}
}
Expand All @@ -76,8 +79,16 @@ public void write(String text) {
// PRIVATE METHODS.
//---------------------------------------------------------------------------------------------

private void pushCharacter(char character) {
Scene scene = windowFinder.targetWindow().getScene();
private Window fetchTargetWindow() {
Window targetWindow = windowFinder.window(window -> window.isFocused());
if (targetWindow == null) {
targetWindow = windowFinder.targetWindow();
}
return targetWindow;
}

private void typeCharacterInScene(char character,
Scene scene) {
KeyCode key = determineKeyCode(character);
baseRobot.typeKeyboard(scene, key, Character.toString(character));
baseRobot.awaitEvents();
Expand Down