after screen.type(pattern., "text") and screen.type(pattern,Key.Tab) focus is set to previous component instead of next

Asked by Hans Steenblok

I recently upgraded from sikuli 1.1.2 to 2.0.5 (and java 8 to java 11) and now my test fail. I have the following code:

org.sikuli.script.Pattern ptrn = new org.sikuli.script.Pattern(filename);

screen.type(ptrn, text);
screen.type(ptrn, Key.TAB);

but after the Key.Tab the focus is not to the next component (in my java form) but in the previous element. It lokes like sikuli is trying to restore the situation and I want to jump to the element according to mij tab order.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Hans Steenblok
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

screen.type(ptrn, text);

searches the pattern, if found clicks the match's middle and then types the given text

In your case, I doubt, that the pattern can still be found with the next screen.type(ptrn, Key.TAB);
If not found. type(pattern, sometext) simply does nothing without any error message.

my suggestion:

screen.type(ptrn, text); // position in the field and write the text
screen.type(Key.TAB); // send a tab to the focused GUI element

Revision history for this message
Hans Steenblok (hanssteenblok) said :
#2

Thank you for the fast response.

The image can be found. The text is placed in the correct GUI element. After the text is entered the focus should go to the next element bij pressing tab but that is nog happening. The focus is returning to the element from before the statement.

In my form I have 15 gui elements. When I start the focus is on element 4. The pattern belongs to element 8.

When the test is at the point of screen.type(ptrn, text), the cursor is going to element 8 and the text is entered in the GUI element. After that the focus returns to element 4 and the next text is entered in element 4. (for that data I don't use an image because it is the next element and no pattern should be needed).

I use sikuli 2.0.5 together with selenium 3.141.59 and testng 7.4.0

Revision history for this message
RaiMan (raimund-hocke) said :
#3

please paste your real code snippet.

Revision history for this message
Hans Steenblok (hanssteenblok) said :
#4

    void type(String text) {
        addScreenShot();
        log(String.format("type \"%s\"", printable(text)));
        screen.type(text);
    }

    void typeFieldTAB(Pattern p, String text) throws NotFound {
        addScreenShot();
        logp("type \"" + text + "\" en TAB uit veld", p);
        long start = now();
        screen.type(p, text);
        screen.type(p, Key.TAB); // screen.type(Key.TAB) makes no difference)
        logm(screen.getLastMatch(), start);
    }

    void typeTAB(String text) {
        addScreenShot();
        log(String.format("type \"%s\" en TAB", printable(text)));
        screen.type(text);
        screen.type(Key.TAB);
    }
    private void addScreenShot() {
        screen.sleep(DELAY_SHORTLY);
        HtmlLogger.addScreenShot(screen.captureLimited(1400, 768), this.getClass().getName());
    }

.
.
// main function
        type("p");
        typeFieldTAB(achternaamPattern, naam);
        typeTAB(voorletters);
        typeTAB(""); // voorvoegsel
        typeTAB(geslacht);
.
.

functions like typeFieldTAB are wrapper functions to add logging and to make a screenshot to check every step)
We create the pattern's at the beginning of the test. We have lots of scenario's. The log* functions only log data.
The code worked perfectly in sikuly 1.1.2 and is not working in sikuli 2.0.5.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

ok, thanks - understood.

The only idea: timing problem - the TAB comes too fast.

try:

screen.type(p, text);
screen.sleep(DELAY_SHORTLY); // adjust the delay
screen.type(Key.TAB)

Revision history for this message
Hans Steenblok (hanssteenblok) said :
#6

I saw that solution someware. I tried it again but it did not solve my problem.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

Ok, then I have no idea.

MayBe something has changed from Java 8 to Java 11 in the AWT Robot implementation.

In my test case on Win10/Java17 I did not have any problems with tabbing through a GUI.

Revision history for this message
Hans Steenblok (hanssteenblok) said :
#8

Instead of adding a delay after screen.type(pattern , text) I added screen.type(Key.ENTER). That solved the problem for me. I think it's because some events in the oracle form are triggered differently in java 11 (I Migrated from java 8). The combination sikuli 2.0.4 (migrated back for an other reason) and java 8 works fine.