Automation of desktop applications is different than the automation on the web. So, the techniques are also different.

For desktop applications you can use:

  • .Net UI automation
  • AutoIt

and for web you can use

  • Watin

These are the most widely used softwares.

Note: You can automate the almost every kind of softwares that range from the old VB6 projects with custom /third party controls to the latest .Net controls.

Let us quickly jump on the main thing.

Automating things is not that easy and i have learnt it after doing various experiments and projects. The outcome of that was a DLL yeshhh!!. I made a DLL/wrapper to exclude all the complexity and i few lines you will be able to automate a calculator or whatever you want . See the following Image.

 

 

 

 

 

 

 

 

 

 

 

 

 

All of the Automation DLL’s are not required i just added them so you know what .Net provides us.

Lets now look at the code.

In order to automate a calculator we need to follow the following steps:

  • Start the calculator
  • Access the calculator window
  • Find the Automation ID’s if required
  • Click the buttons
  • Repeat the process if required
  • Close the window

In the first line of the code above, i am starting the calculator

  1. Wrapper object is the object of my wrapper DLL.
  2. calc.exe is the named of the calculator (If you go to run and write calc you will see that a calculator will pop up. In the same way you can open notepad and other things also.)
  3. testing is the Error message returned by my DLL. (It is empty in case we donot get any error)

In the second line i am accessing the window.

  1. Calculator is the windows title (There are many ways to access it but accessing things by window name is the easiest. You can find more ways by exploring my DLL)
  2. GetForm is my wrapper function that accesses the form by title.

In the 3rd,4th, 5th and 6th line i am accessing buttons on the form using either the text or the automation id (doing simple addition)

  1. calc is the object that contains the details about the window and the wrapper function will access the button from this window
  2. “2” is the text of the button that i have to access if i am pressing the 2 button

Following is my code to close the window

Where calc or calc.exe is the process name that we have to kill. You can get this name from the task manager.

 

Here was a quick demo of automation. The project is attached with the post. You can review it if you want. There are almost 19 functions in my DLL that can help you in accessing different controls. I am also attaching the DLL code. enjoy. Happy coding!

CCAutoProject
Calculator Automation