[1.0.1] Intermittent Problem with Paste Function in SIkuli

Bug #1195259 reported by RaiMan
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
SikuliX
Fix Released
Undecided
RaiMan

Bug Description

Hello,
 If I run a script that loads data from a CSV, assigns text from the rows to variables and pastes the variables into certain cells of an application that I am automating , I experience an intermittent error, where the application forgets to paste the data:
it however over the field and pastes nothing into it.
I tried it in two ways.
 Manually howering, clicking and pasting it all separately.
I also tried to do Region.paste.

Both work, however in certain points the application does not paste anything into the cell.

I have sufficient time outs set up, which indicates to me that it might not be related to a time out.
Also I have set up the IDE to print the data in the variables to console to make sure that python is assigning the data correctly and it seems that python is fine.

Therefore I think there might be some issue with the paste function when using it to paste multiple chunks of data, from different variables over a long period of time.

Sometimes it also mixes up data which it is pasting and pastes a value of a previously called variable over the value of a currently called variable.

Tags: fkt-paste
RaiMan (raimund-hocke)
Changed in sikuli:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
tags: added: fkt-paste
summary: - Intermittent Problem with Paste Function in SIkuli
+ [1.0] Intermittent Problem with Paste Function in SIkuli
Revision history for this message
Philippe Trounev (ptrounev) wrote : Re: [1.0] Intermittent Problem with Paste Function in SIkuli

Hello,
 We have resolved this bug by implementing a custom paste class.

The root cause of the problem here is the Windows clipboard locking as windows locks clipboard after too many consequential uses.

A way to reproduce this error is load a csv file with 1000 variables

Do a simple script to open notepad

and paste all of those variables using for each option in row

You will see that once over 30 variables have been pasted the tool will experience problems where it will miss the paste, because the memory will clear but since clipboard is locked it will prevent a new object from entering into it thus breaking paste function.

Hope this is of help.

Regards.
P.T.

Revision history for this message
RaiMan (raimund-hocke) wrote :

Are you willing to share the code for your paste class?

summary: - [1.0] Intermittent Problem with Paste Function in SIkuli
+ [1.0.1] Intermittent Problem with Paste Function in SIkuli
Revision history for this message
Philippe Trounev (ptrounev) wrote :

Sure,
Here you go, it still has a few bugs in it (it pastes the comma for the comma separated values, but it works fine for me)

from java.awt import Robot
from java.awt import Toolkit
from java.awt.event import KeyEvent

from java.awt.datatransfer import Clipboard
from java.awt.datatransfer import ClipboardOwner
from java.awt.datatransfer import DataFlavor
from java.awt.datatransfer import StringSelection
from java.awt.datatransfer import Transferable

class mClipboard(ClipboardOwner):
    _clipboard = []
    _robot = []
    def __init__(self):
        toolkit = Toolkit.getDefaultToolkit()
        self._clipboard = toolkit.getSystemClipboard()
        self._robot = Robot()

    def regainOwnership(self,tr):
        contents = self.get()
        self._clipboard.setContents(tr, self)

    def set(self, ct):
        strsel = StringSelection(ct)
        try:
            self._clipboard.setContents(strsel, self)
        except java.lang.IllegalStateException:
            wait (5)
            print "IllegalStateException"
            self.regainOwnership(strsel)

    def get(self):
        t = self._clipboard.getContents(self)
        try:
            if t.isDataFlavorSupported(DataFlavor.stringFlavor):
                return t.getTransferData(DataFlavor.stringFlavor)
        except:
            print "Unexpected error in get():"
            print sys.exc_info()[0]
        return null

    def doPaste(self,ct):
        self.set(ct)
        self._robot.delay(50)
        self._robot.keyPress(KeyEvent.VK_CONTROL)
        self._robot.keyPress(KeyEvent.VK_V)
        self._robot.keyRelease(KeyEvent.VK_V)
        self._robot.keyRelease(KeyEvent.VK_CONTROL)

    def keyPress(self,key):
        self._robot.keyPress(key)
        self._robot.keyRelease(key)

    def delay(self,sec):
        self._robot.delay(sec)

Usage is:

        mclipboard.doPaste("" + VariableName + "")
        mclipboard.keyPress(KeyEvent.VK_COMMA)

Revision history for this message
RaiMan (raimund-hocke) wrote :

@ Philippe
Thanks for sharing.

I will check against the implementation of the clipboard and paste features and Sikuli and hopefully find something I can fix.

Changed in sikuli:
importance: Medium → High
RaiMan (raimund-hocke)
Changed in sikuli:
status: In Progress → Fix Committed
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 1.1.0 → 2.0.0
importance: High → Medium
RaiMan (raimund-hocke)
Changed in sikuli:
status: Fix Committed → Fix Released
importance: Medium → Undecided
milestone: 2.0.0 → none
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.