Windows desktop application robot tutorial

Tutorial for creating a software robot for interacting with a Windows desktop application using RPA Framework.

This software robot opens the Spotify desktop application, searches for the given song, and plays the song. This tutorial demonstrates the basic Windows-automation capabilities of the RPA Framework, using keyboard navigation.

Using Windows search to find the Spotify desktop application

Song playing in the Spotify Windows desktop application

Prerequisites

This tutorial currently works only on Windows. To complete this tutorial, you need to have the Spotify desktop application (Windows) installed on your machine. The robot expects the user to be already logged in when it launches the application.

Set up your development environment.

Initialize the software robot directory

Navigate to your projects directory in the terminal or the command prompt. Initialize the software robot directory:

robo init windows-desktop-application-robot

Navigate to the directory:

cd windows-desktop-application-robot

Robot task file

Paste the following Robot Framework code in the tasks/robot.robot file:

*** Settings ***
Documentation     Spotify Windows desktop application robot. Opens the Spotify
...               desktop application, searches for the given song, and plays the
...               song. Demonstrates the basic Windows-automation capabilities of
...               the RPA Framework, using keyboard navigation.
Library           RPA.Desktop.Windows
Resource          keywords.robot

*** Tasks ***
Open Spotify desktop application and play a song
    Open the Spotify desktop application
    Search for the song
    Select the song
    Play the song
    [Teardown]    Close All Applications

Robot keywords file

Paste the following Robot Framework code in the resources/keywords.robot file:

*** Settings ***
Variables         variables.py

*** Keywords ***
Open the Spotify desktop application
    Open From Search    ${EXECUTABLE_NAME}    ${EXECUTABLE_NAME}

Search for the song
    Send Keys To Input    ^l
    Send Keys To Input    ${SONG_NAME}

Select the song
    Send Keys To Input    {TAB}{TAB}{TAB}

Play the song
    Send Keys To Input    {ENTER}    with_enter=False
    Sleep    10

Variables file

Paste the following Python code in the variables/variables.py file:

EXECUTABLE_NAME="Spotify"
SONG_NAME="Monody"

Wrap the robot

robo wrap

Run the robot

Windows:

robo run entrypoint.cmd

Robot script explained

This sections explains some of the keywords used in this robot script.

Open From Search    ${EXECUTABLE_NAME}    ${EXECUTABLE_NAME}

The Open From Search keyword is provided by the RPA.Desktop.Windows library. The keyword opens the application using the Windows search dialog.

Send Keys To Input    ^l

The Send Keys To Input (from RPA.Desktop.Windows library) sends given keys to Windows and automatically sends an {ENTER} after the input by default. The ^l means Ctrl+L on Windows. See pywinauto documentation for the available key codes.

Send Keys To Input    {TAB}{TAB}{TAB}

Multiple keys can be sent at the same time.

Send Keys To Input    {ENTER}    with_enter=False

with_enter=False is used here to prevent sending a double {ENTER}, since Send Keys To Input defaults to automatically sending it.

Summary

You executed a simple software robot that interacts with a Windows desktop application. Congratulations!

During the process, you learned some basic features of the RPA Framework.