Forum Stats

  • 3,759,064 Users
  • 2,251,495 Discussions
  • 7,870,478 Comments

Discussions

listeners firing order messes up testing

873434
873434 Member Posts: 5 Employee
edited Mar 18, 2013 11:45AM in Swing
I have encountered the following issue. I have an interactive Swing application. It basically creates a bunch of graphical objects on a canvas. You pick the kind you want to create from a palette (oval, circle, etc.) and click on the canvas. Everything works as expected. Now I want to record a test using Abbot/Costello testing framework. It is pretty simple. Fire up Costello app, create a new script and start recording events. Let's say I want to record this sequence: click on a palette and drop a graphic on canvas. It is natural to expect that testing app would record a click before the canvas component had a chance to process it and added a new graphic. For various reasons I need to capture the app's state before any changes are made to it, not after. It turns out that my app gets first crack at the click event resulting in creation of a new graphic and only after that my testing app receives the event for recording. At this point it is too late for me, the state has been irretrievably changed and I am basically recording a future state and not the state that preceded it.
I understand that this is a result of listeners firing in different order. I also understand that Swing makes no guarantees as to the order of firing listeners. Have I reached limits of possible or there is a solution?

Answers

  • PhHein
    PhHein Member, Moderator Posts: 7,167 Silver Trophy
    Talking about Swing and mentioning Canvas suggests that you're mixing lightweight and heavyweight components, which might already be the reason for those strange results. Never ever mix AWT and Swing components!
  • 873434
    873434 Member Posts: 5 Employee
    By canvas I meant a component area dedicated to drawing graphics, not a Canvas class
  • PhHein
    PhHein Member, Moderator Posts: 7,167 Silver Trophy
    Fine.
    Have you tried disabling/enabling listeners? I have no solution, but that's the first idea that came to my mind.
  • 873434
    873434 Member Posts: 5 Employee
    No, I have not. The listeners fire fine, just not in the order I want them to fire. I'm not sure how enabling/disabling them is going to help it. Also bear in mind that I have no control over the testing app's listeners, I don't add any listeners of my own either. I simply use functionality provided by both applications.
  • PhHein
    PhHein Member, Moderator Posts: 7,167 Silver Trophy
    Have you asked in an Abbot/Costello forum/mailing list? I'm sure you're not the first user having these problems.
  • darrylburke
    darrylburke Member Posts: 18,007
    Alex wrote:
    It turns out that my app gets first crack at the click event resulting in creation of a new graphic and only after that my testing app receives the event for recording. At this point it is too late for me, the state has been irretrievably changed and I am basically recording a future state and not the state that preceded it.
    I would consider that expected behavior, as Swing is single threaded and the listener code and your testing app would all be running on the EDT.

    Are you trying to implement an 'Undo' feature or is this something more complex?

    db
  • 873434
    873434 Member Posts: 5 Employee
    Yes, I did and they acknowledged it to be a problem. No solution though.
  • 873434
    873434 Member Posts: 5 Employee
    No, it is not really an 'Undo' feature. When recording a test script, a reasonable expectation is that actions causing changes would be recorded before the changes take effect, not after. A basic cause and effect assumption. This assumption doesn't hold true under current implementation. This results in recording an incorrect test script that cannot faithfully reproduce and test recorded events.
This discussion has been closed.