White Library tutorial for windows application automation
Quick overview
- Python
- Robot framework
- White library
Reference to the keywords
If you need to know how to use robot framework - check this blog
White Library keywords - click here
How to find element locators so we can use them in this automation
Basic script
*** Settings ***
Documentation Notepad automation using WhiteLibrary.
Library WhiteLibrary
*** Variables ***
${APPLICATION_LOCATION} C:/Windows/notepad.exe
*** Test Cases ***
Open Notepad And Create A File
Launch Application ${APPLICATION_LOCATION}
Sleep 3s #wait time to notepad launch
Attach Window Untitled - Notepad
Input Text To Textbox text=Text Editor This is a sample text file
Click Item text=File
Wait Until Item Exists text=Save 5s
Click Item text=Save
Sleep 3s
@{windows}= Get Application Windows
Attach Window ${windows[1]}
Input Text To Textbox text=File name: temp.txt
Click Button text=Save
Close Application
Code explanation
- Firstly we have imported the White Library so that we can refer the keywords from the it.
- Then we have declared the exe path of the application we want to automate, in this case it's path of the notepad exe.
- Then we start with the actual test where there are commands in the pattern of keyword and the parameter for the keyword to perform the test action.
- Attach window is a keyword of the type context, and is very important in "windows application" automation. We need to attach any window that is getting opened during our test.
- We can only access the window elements if we have attached the window to the context(Attach window keyword does it for us.)
- I think all other keywords are self explanatory like Click Item, Input text to the textbox.
- To find out which window we can attach there is one keyword "Get Application Windows", when a new window open is expected within the same application, we can use this keyword and it will return a list of windows available.
- I have used window index to attach it to the context ex. ${windows[1]}, so here the index of the window I want to attach is 1, which is Save As window. 0th window is Untitled-Notepad.
- You can find the order of the windows in the text execution report at the line @{windows}= Get Application Windows. I have attached the screenshot of the report, and you can see the first window and second window names here.