Sunday, November 1, 2015

New Code Generator in SWAPY

Pywinauto is a great tool for those who have some experience in Python. But what is about the beginners or those who are not yet familiar with Python and/or GUI automation?

SWAPY is a GUI helper for objects hierarchy inspection. Generally it looks like similar tools from Microsoft (Spy++, Inspect.exe), but it's designed specifically for Pywinauto users. It's especially helpful for getting started with Pywinauto library.

SWAPY can recognize every control that is visible to Pywinauto. So you may check quickly whether Pywinauto is suitable for your application. If this is the case, SWAPY can help with prototyping your automation scripts using the Code Generator feature.

The Code Generator is significantly renovated in the SWAPY 0.4.8.

How does it work? Just start looking for the controls hierarchy. If you want to do some action, right click on the control item in the tree and choose a method to call.



Code Generator automatically inserts the code into the Editor pane. The action is also performed simultaneously in the application. All the generated code can be saved to *.py file.




Now the Editor pane supports unlimited "Undo" steps including the whole code reset. Of course an action cannot be undone in the application so use the "Undo" carefully.

An additional useful option is switching between Start and Connect methods. If you believe the application is already started when your script is supposed to run, you can right click on the top level window item ("Common Controls Sample" in the given example) and choose Application.Connect method instead of Start one.

Feel free to propose new features in the SWAPY issues section or tell us your opinion on the Gitter chat room.

There is a known problem: if Win8.1 or Win10 denies you to run SWAPY executable, just click "More info" link on the warning window and then choose "Run anyway". The binaries are not digitally signed yet.

10 comments:

  1. Hi thanks for this wonderful tool I have been using it some of my automation requirements.

    I had one query i.e. is it possible to run automation script in a scheduler ? which means I will not be RDP'ing to the machine all the time will the script keep running?as I have noticed that as soon as I close my RDP session the automation stops.Is that by design?
    Thanks in advance.
    Thanks.

    ReplyDelete
    Replies
    1. Hi Varenya!

      Unfortunately this behavior is the same for all GUI automation tools & languages because there are no GUI context available to the script.

      There is one simple workaround. RDP window can be safely out of focus. Just run the script inside RDP window (switch off full screen mode before) and quickly switch to another window on the local machine. Now you can work on the local machine, and the script runs in RDP simultaneously.

      GUI automation tasks can also be scheduled with Jenkins. But this way you need more efforts. This thread on StackOverflow can be useful.

      Currently I'm trying an approach suggested by maQ (answer with current rating == 2). It doesn't require Windows auto logon. I hope it helps.

      Delete
    2. One more interesting moment is that running Jenkins task under LOCAL_SYSTEM account allows you an access to a user desktop without administrator privileges. If you need both desktop and administrator access simultaneously (for installer/uninstaller testing for example), setting up auto logon is the only way.

      Delete
  2. TSpeedButton is not showing in swapy just for that i use reserved enginering to change button to tbutton pls fix

    ReplyDelete
    Replies
    1. SWAPY is not currently maintained. But as I understand, TSpeedButton should be detected correctly as `ButtonWrapper` in pywinauto. If it's not so, please report an issue on GitHub with more details. Also it would be nice to have demo app (binaries) with TSpeedButton. So that I can take a look deeper into this case.

      Delete
  3. I want to save my notepad file using "file ->Save as " menu option in different location but i am unable to edit the Address path in the "SaveAs window" .How to edit the Address path so that i can set the New address path using this swapy tool.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. I am using the swapy32.exe and testing an application for automation purpose, the swapy browser the application successfully but its object browser is not showing the controls belongs to that window.

    ReplyDelete
    Replies
    1. SWAPY is not maintained any more, so it doesn't support latest features in pywinauto. It supports only legacy "win32" backend. More up-to-date "uia" backend supports more applications. See Getting Started Guide for pywinauto for more details: https://pywinauto.readthedocs.io/en/latest/getting_started.html or use py_inspect: https://github.com/pywinauto/py_inspect (it can browse app using both backends).

      Delete
  6. why my application i not expanding(plus symbol not coming) in swapy.

    ReplyDelete