I'm familiar with doing RPA with UiPath, so I wanted to try out other tools for automation. Robot Framework is really popular and you can use Python with it, so that was a natural selection for me. The scope of this article is just the finished product and tips for my pitfalls.
The finished robot:
#/devdata/env.json
{"RPA_SECRET_MANAGER": "RPA.Robocorp.Vault.FileSecrets",
"RPA_SECRET_FILE": "vault.json"
}
#tasks.robot
*** Settings ***
from a csv-file, produce receipts and a summary ZIP
Documentation Insert orders to system /kalletolonen
... Author: www.github.comfor this excersise: https://robocorp.com/docs/courses/build-a-robot#rules-for-the-robot
... Source from the author: https://www.kalletolonen.com
... More
=${FALSE}
Library RPA.Browser.Selenium auto_close
Library RPA.PDF
Library RPA.HTTP
Library RPA.Tables
Library OperatingSystem
Library DateTime
Library Dialogs
Library Screenshot
Library RPA.Archive
Library RPA.Robocorp.Vault
*** Variables ***
= ${OUTPUT_DIR}${/}receipts/
${receipt_directory}= ${OUTPUT_DIR}${/}images/
${image_directory}= ${OUTPUT_DIR}${/}
${zip_directory}
*** Tasks ***
and a summary ZIP
Insert orders to system, produce receipts
Get csv url
Open the order sitein the order form using the data from the csv file
Fill and make the ZIP
Name
Delete original imagesand close the browser
Log out
*** Keywords ***
Get csv url= Get Secret cert2address
${csv_url}file ${csv_url}[value]
Download the csv
file
Download the csv
[Arguments] ${csv_url}=True
Download ${csv_url} overwrite
Open the order site//robotsparebinindustries.com/#/robot-order
Open Available Browser https:
Click OKclass:alert-buttons
Wait Until Page Contains Element
Click Button OK
Make order
Click Button Orderid:receipt
Page Should Contain Element
Return to order formid:order-another
Wait Until Element Is Visible id:order-another
Click Button
1 order
Fill out
[Arguments] ${orders}
Click OKclass:form-group
Wait Until Page Contains Element
Select From List By Index head ${orders}[Head]
Select Radio Button body ${orders}[Body]//html/body/div/div/div[1]/div/div[1]/form/div[3]/input ${orders}[Legs]
Input Text xpath:
Input Text address ${orders}[Address]
Click Button Preview
Wait Until Keyword Succeeds 2min 500ms Make order
Save order detailsid:receipt
Wait Until Element Is Visible = Get Text //*[@id="receipt"]/p[1]
${order_id}
Set Local Variable ${receipt_filename} ${receipt_directory}receipt_${order_id}.pdf= Get Element Attribute //*[@id="receipt"] outerHTML
${receipt_html}=${receipt_html} output_path=${receipt_filename}
Html To Pdf content
id:robot-preview-image
Wait Until Element Is Visible
Set Local Variable ${image_filename} ${image_directory}robot_${order_id}.pngid:robot-preview-image ${image_filename}
Screenshot with robot image to a PDF ${receipt_filename} ${image_filename}
Combine receipt
in the order form using the data from the csv file
Fill = Read table from CSV path=orders.csv
${orders}@{orders}
FOR ${order} IN 1 order ${order}
Fill out
Save order details
Return to order form
END
with robot image to a PDF
Combine receipt
[Arguments] ${receipt_filename} ${image_filename}
Open PDF ${receipt_filename}@{pseudo_file_list}= Create List
... ${receipt_filename}=center
... ${image_filename}:align
False}
Add Files To PDF ${pseudo_file_list} ${receipt_filename} ${
Close Pdf ${receipt_filename}
and close the browser
Log out
Close Browser
Delete original images
Empty Directory ${image_directory}
Empty Directory ${receipt_directory}
and make the ZIP
Name = Get Current Date exclude_millis=True
${date}= Get Value From User Give the name for the zip of the orders:
${name_of_zip}
Log To Console ${name_of_zip}_${date}
Create the ZIP ${name_of_zip}_${date}
Create the ZIP
[Arguments] ${name_of_zip}
Create Directory ${zip_directory} Archive Folder With Zip ${receipt_directory} ${zip_directory}${name_of_zip}
My local “Vault”:
#vault.json
{"cert2address": {
"key": "address",
"value": "https://robotsparebinindustries.com/#/robot-order"
} }
You can grab the whole repo at my Github.
I had some challenges:
1. Firefox doesn’t allow you to copy the whole Xpath, so I used Chrome
2. My local Vault didn’t work with Assistant, so I hardcoded my info
3. “Try-Catch” was really easy to do with Wait Until Keyword Succeeds
4. Appending to a PDF had to be done by a list
Your comment may be published.