Windows desktop application robot

This robot is included in our downloadable example robots. You can also find the code at the example robots repository.

This software robot opens the Spotify desktop application, searches for the given song, and plays the song. The robot 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

Run this robot locally in Robocorp Lab

This robot currently works only on Windows. 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.

You can run this robot on your local machine using Robocorp Lab:

  1. Set up your development environment.
  2. Download the example robots.
  3. Open the windows-desktop-app-robot example.
  4. Open the tasks.robot file and run it.

Robot script

*** 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

*** Variables ***
${EXECUTABLE_NAME}=    Spotify
${WINDOW_TITLE}=    Spotify Premium
${SONG_NAME}=     Monody

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

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

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

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

*** 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 script explained

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

Open From Search    ${EXECUTABLE_NAME}    ${WINDOW_TITLE}

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.