3

I am looking for a way to use python to run automated tests for one of our C# applications at work, but am not sure what tools to use.

I have researched and tried pywinauto, but I am unable to automate any of the MenuItems which appears to be an issue for many people. Unfortunately, the menu options are essential to this application.

Is there a python framework or some other tool that I can use to automate winforms applications, including the menu strips?

2
  • 1
    If you can live without Python, there is nothing better than autoitscript.com/site/autoit for doing this.
    – Mawg
    Commented Jun 3, 2015 at 7:26
  • 1
    @Mawg I will definitely look into that. Python is not a requirement, but something I am interested in working with. Thanks!
    – AdamMc331
    Commented Jun 3, 2015 at 13:10

1 Answer 1

1

Further to comment above, stating that Python is "nice to have", rather than "must have", I strongly urge you to use AutoIt.

Much as I enjoy Python coding myself, I always use AutoIt for Windows GUI automation tasks.

You can use it as a macro recorder/playback functionality. You can tell it to click x=75, y=100, then click x=150, y=250.

But the beauty is that you can code things like (this is pseudo-code)
- wait for a window with the title "notepad" to appear
- when it does, look for a menu called "File" and activate it
- look for a sub-menu1 titled "Open" and click it
- simulate keyboard input for "myfile.txt" and find and click the "Ok" button

The beauty of this is that your GUI layout can change and the scripts will still work.

You can also use the IDE to design GUIs for your AutoIt apps.

It is a mature, well tested, well documented system, and easy to learn. There is even an O'Reilly book.

It's free, and:

Easy to learn BASIC-like syntax
Simulate keystrokes and mouse movements
Manipulate windows and processes
Interact with all standard windows controls
Scripts can be compiled into standalone executables
Create Graphical User Interfaces (GUIs)
COM support
Regular expressions
Directly call external DLL and Windows API functions
Scriptable RunAs functions
Detailed helpfile and large community-based support forums
Compatible with Windows XP / 2003 / Vista / 2008 / Windows 7 / 2008 R2 / Windows 8 / 2012 R2
Unicode and x64 support
Digitally signed for peace of mind
Works with Windows Vista’s User Account Control (UAC)

Here's a simple sample script from the website:

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Save")
;WinWaitActive("Notepad", "Do you want to save") ; When running under Windows XP
Send("!n")

4
  • 1
    This is very nice. So far I've been able to open our application and log in in only six lines of code, which is always cool to me. Thank you so much for the recommendation!
    – AdamMc331
    Commented Jun 3, 2015 at 14:35
  • 1
    Glad to have been of help. The more you do with it, the more impressed you will become. Don't worry, there's still plenty of opportunity for Python ,-)
    – Mawg
    Commented Jun 3, 2015 at 14:44
  • Do you have any examples of automating menu selection? I found this, but it also says it only works on standard menus.
    – AdamMc331
    Commented Jun 3, 2015 at 15:19
  • 1
    Actually, I found this useful answer: stackoverflow.com/a/8926518/3131147
    – AdamMc331
    Commented Jun 3, 2015 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.