Windows application Test Automation (Part 2)

Kasun Wickramarathna
7 min readJun 27, 2021

--

This is the second article of a series of three. I highly recommend you to visit Windows application Test Automation (Part 1) of this series of articles, in order to gain a better understanding.

In the previous article, I explained what is the essential software that you will need to prepare the test environment for Windows test automation and how to ensure they are installed properly. In this article I’m planning to discuss how to set up the Windows test environment in the way it works only for the instructions provided by the automation script;

Few things to note before we start;

  • This configuration is intended only for single-threaded test executions
  • Execution is only performed on local PC where test scripts and execution-environment both are on the same PC.
  • Even though the executions are conducted for the purpose of testing, the changes are done in real (if you delete a file using the test script, that file is really deleted.) So, I would recommend performing all the executions in an isolated test environment, rather than working PC. Remote execution is one way to do this.

So, Let’s jump right into it !!!

Configuration for test executions

There are mainly 3 ways of doing this, I will explain each way how to do it. There is no best or worst choice, you could choose a method out of three based on your requirement.

  1. Using WinAppDriver
  2. Using Appium
  3. Remote Execution

Using WinAppDriver (Direct start method)

In brief, WinAppDriver is a server, which keeps on listening to the test commands and respond while residing in a particular port.

Some might find this configuration rather easier than the other two, but it’s still worth to refer other two methods to understand what’s best suited for your requirement. If you are a beginner or do not have any particular requirement, this probably is the best choice for the moment.

By this time you must have installed WinAppDriver. If not, do refer to my previous article of this series: Windows application Test Automation (Part 1).

There 2 sub-different methods for doing this in any method fine (Do not run more than one at a time);

WinAppDriver default running conditions are as per below;

Default WinAppDriver location → C:\Program Files (x86)\Windows Application Driver

Default IP address →127.0.0.1

Default port → 4723

Method 1 — with default configuration (probably the easiest among all)

  1. Navigate to WinAppDriver installed location.
  2. Double Click the WinAppDriver.exe
Figure 2.1- After starting the WinAppDriver with the default configuration

Method 2 —with customized configuration

  1. Open Windows Command prompt/Windows PowerShell in Administrator mode
  2. Change directory to WinAppDriver installed location (in our case default installed location)
  3. When providing customized running configuration, it should follow below standard ;

WinAppDriver.exe <IP address> <port>

If your IP address is default and the port needs to be customized, you could only specify the port. Given in the example below;

WinAppDriver.exe 4723

If you want to specify only the IP address you need to add the port as well, even it’s the default port.

WinAppDriver.exe 192.x.x.5 4730
WinAppDriver.exe 192.x.x.5 4529/wd/hub
Figure 2.2- After starting the WinAppDriver with customized configuration

Note: I recommend you to use 127.0.0.1 or your local IP (test execution PC ) as the IP when you set customized options to WinAppDriver.

Run WinAppDriver, in Administrator mode, in the event when you are using a different IP or port other than the default

Verification of WinAppDriver functions

After starting WinAppDriver either using default configuration or customized configuration. There are two different ways to identify whether WinAppDriver is responding ;

  • One way is that it should look like as per Figure 2.1 or Figure 2.2
  • The second way is that, copy the configured IP address (in my case http://10.168.10.161:4730) and paste it into your browser, certainly, there will be an error on the browser side like ‘No webpage was found’. But if WinAppDriver is responding correctly, in the WinAppDriver running window there should be a response stating at the end ‘HTTP 1.1/404 Not found.’ If you see a similar message in Figure 2.3, then you are good to go.
Figure 2.3- WinAppDriver response to the browser request
Figure 2.3- WinAppDriver response to the browser request

However, if you already have a proper test script to test, set the IP address to the configured IP, once successfully connected, response message stating at the end ‘HTTP 1.1/200 OK’ as in Figure 2.4 ;

Figure 2.4- WinAppDriver response to the test script request
Figure 2.4- WinAppDriver response to the test script request

Note : If you are using any customized IP address ,note it down, since it will be needed to include in the test script.

Using Appium

There are two sub-different approaches when starting Appium Server similar to WinAppDriver.

  1. Appium with the default configuration
  2. Appium with customized configuration

Let’s see how to configure in Appium in different ways below;

Note: Appium default running configuration;

Appium default port → 4723

Appium default IP address → 0.0.0.0

1. Appium with the default configuration

This may be the easiest way to invoke the Appium. If you do not need any advanced customizations, probably this is the best way to run Appium.

  1. Open Window Command-line console
  2. Type ‘appium’ and enter
appium

Once it’s successfully started, it should look like Figure 2.5;

Figure 2.5- Appium started with the default configuration

To test the Appium is communicating successfully, open your browser, and enter ‘htttp://127.0.0.1/4723/wd/hub’, of course, you will not see any web page the same as in WinAppDriver, rather as the JSON response in the browser window, like in Figure 2.6.

But in the window where Appium is running (Windows Command prompt), will show a response ‘No route found for …’. This means Appium server is running and communicating successfully (even for the unsupported attempts) as in Figure 2.7. So you are good to go for the next step.

Figure 2.6- “Unknown Command” message displays when attempting to access Appium via browser
Figure 2.7- “No route found” message displays in Appium via when attempt to access server via browser
Figure 2.7- “No route found” message displays in Appium when attempting to access the server via browser

2. Appium with customized arguments

This approach of Appium invoke is, slightly different from the previous one. This can be used where you need to run Appium in a preferred running condition other than the default one.

In here we pass the port as a customized argument (parameter) along with the Appium start command;

  1. Open Window Command-line console
  2. Type ‘appium -p <Port>’ and enter
appium -p 4730
Figure 2.8- Appium started with customized arguments (port)

Not only ports can be passed as arguments, IP address, and many more, you could refer to Appium official document for Appium Command-Line arguments

I added another example with IP address and port for better understanding — Figure 2.9 ;

appium -a <IP address> -p <port>
Figure 2.9- Appium started with customized arguments (IP address and port)

Note : If you have never started Appium using customized IP address or port, you might get a firewall notification . Accept it, otherwise Appium will not run properly. If you already blocked it, go to advance setting in Windows Firewall, and Allow communication with corresponding port.

In general, you will not need, whole a lot of customized arguments to automate Windows. However, if you would like to have a customized environment, please refer to the Appium CLI argument link provided above in this article.

Final Note : It does not matter in which method you decided to start WinAppDriver/Appium ,I urge you to write down started server IP and port since it will be needed to include in the test script in the next article. If you do not know how to extract it, read below;

How to extract the started server IP and port;

If you have started with;

  • WinAppDriver — something similar to below will be displayed in the Command prompt as the response.
Windows Application Driver listening for requests at : http:<Some IP Address>:<some port>/

— — — — — OR — — — — —

  • Appium — something similar to below will be displayed in the Command prompt as the response.
Appium REST http interface listener started on <Some IP Address>:<some port>

Remote Execution

I do not intent to cover this method in this article since it might slightly confuse the reader due to the configuration flow is somewhat different from the local PC setup. Therefore I will cover this in an upcoming article.

(Link will be provided here).

We have completed preparing our testing environment where it will obey our test script commands, also now we have completed configuring all the necessary software and running conditions.

In the next article, I will explain how to initiate a communication between the test script and the test environment with sample code.

Refer following link: Windows application Test Automation (Part 3)

--

--