RPA Framework, base on ‘robotframework’ Homepage: https://www.github.com/robocorp/rpaframework/ Documentation: https://rpaframework.org/ PyPI: https://pypi.org/project/rpaframework/ Release notes: https://rpaframework.org/releasenotes.html RSS feed: https://rpaframework.org/releases.xml

Robocorp company make this. https://robocorp.com/docs

pip install rpaframework pip install rpaframework-recognition

GET STARTED

https://robocorp.com/docs

IDE

Install Visual Code

Install VS code extension. https://marketplace.visualstudio.com/items?itemName=robocorp.robocorp-code

打开命令行输入窗口: Windows: Shift + Ctrl + P

创建项目: Robocorp: Create Task Package (Robot)

  • Select Python - Minimal.
  • Select Use workspace folder.

Then , you will see the files.

.gitignore
conda.yaml
LICENSE
README.md
robot.yaml
tasks.py

Open tasks.py, then it create python env automatically.

Run Task

Then you can run the task.py like below.

You can also run task with command line panel:

Shift + Ctrl: Robocorp: Run Task Package (Robot)

Check output log

Then you can find the log file in the output directory.

Or, after you install an extention named “open in browser”

browser

browser goto

from robocorp.tasks import task
from robocorp import browser
 
@task
def minimal_task():
    """Insert the sales data for the week and export it as a PDF"""
    browser.configure(
	    browser_engine="msedge",
        # By setting a higher value for slowmo we can slow down the robot execution even further. 
        # This number represent the number of miliseconds the robot waits for between 2 actions.
        slowmo=1000,
    )
    open_the_intranet_browser()
 
def open_the_intranet_browser():
    """Open the intranet browser and navigate to the sales data page"""
    browser.goto("https://www.baidu.com")
 
    

browser input & click

from robocorp.tasks import task
from robocorp import browser
 
@task
def minimal_task():
    """Insert the sales data for the week and export it as a PDF"""
    browser.configure(
        # By setting a higher value for slowmo we can slow down the robot execution even further. 
        # This number represent the number of miliseconds the robot waits for between 2 actions.
        slowmo=300,
    )
    open_the_intranet_browser()
    type_in_something()
 
def open_the_intranet_browser():
    """Open the intranet browser and navigate to the sales data page"""
    browser.goto("https://www.baidu.com")
 
def type_in_something():
    """Type in something"""
    page = browser.page()
    page.fill("#kw", "热点新文")
    page.click("input:text('百度一下')")

page.screenshot

def collect_results():
    """Take a screenshot of the page"""
    page = browser.page()
    page.screenshot(path="output/sales_summary.png")

page.locator

https://playwright.dev/python/docs/locators#locate-by-role

Find something with id.

page.locator("#con-ceiling-wrapper").inner_html()
page.locator("#con-ceiling-wrapper").inner_text()

RPA.HTTP

from RPA.HTTP import HTTP
 
def download_excel_file():
    """Downloads excel file from the given URL"""
    http = HTTP()
    http.download(url="https://robotsparebinindustries.com/SalesData.xlsx", overwrite=True)

RPA.PDF

from RPA.PDF import PDF
# Export HTML as PDF
def export_as_pdf():
    """Export the data to a pdf file"""
    page = browser.page()
    sales_results_html = page.locator("#sales-results").inner_html()
 
    pdf = PDF()
    pdf.html_to_pdf(sales_results_html, "output/sales_results.pdf")
    

Selenium

*** Settings ***

Library  RPA.Browser.Selenium

*** Variables ***

${URL}              https://www.baidu.com

${BROWSER}          Chrome

${search_input}     css=input[name=wd]

${search_button}   css=input[id=su]

${search_content}  我是超人1

*** Test Cases ***

Baidu Search

    attach chrome browser  9022

    go to  https://www.baidu.com/

    input text  name:wd    小星星

    click element  id:su

   sleep  5

    go to  https://www.baidu.com/

    input text  name:wd    我是你爸爸1

    click element  id:su

   sleep  5

    screenshot

Capture Page ScreenShot

https://robocorp.com/docs/libraries/rpa-framework/rpa-browser/keywords#capture-page-screenshot

Takes a screenshot of the current page and embeds it into a log file.

*** Settings ***

Library    RPA.Browser.Selenium

*** Variables ***

${target}      https://www.baidu.com

*** Tasks ***

Baidu Search

    Attach Chrome Browser   9022

    Go To   ${target}

    Input Text    name:wd    小星星

    Click Element    id:su

    Sleep   5    Wait page complete

    Set Screenshot Directory    /Users/dcq/Desktop

    Capture Page Screenshot    selenium-screenshot-{index}.png

RPA.Browser

RPA.HTTP

https://robocorp.com/docs/libraries/rpa-framework/rpa-http https://robocorp.com/docs/libraries/rpa-framework/rpa-http/keywords#get https://robocorp.com/docs/development-guide/http/http-examples

GET

*** Settings ***
Library    RPA.HTTP
Library    RPA.JSON
*** Variables ***
${API}      http://localhost:8080/api/v2
*** Tasks ***
Test POST API
Test API Request
   ${params}=    Create Dictionary   opportunity=123   attachment=456
   ${Result}=    get params=${params} url=${API}
    Log   ${Result.json()['name']}
    Save JSON to file   ${Result.json()}    a.json

POST multipart/form-data

*** Settings ***
Library    RPA.HTTP
Library    RPA.JSON
*** Variables ***
${API}      http://localhost:8080/api/v2/testPost
*** Tasks ***
Test POST API
${params}= Create Dictionary signature=DD timestamp=20221116 content=I am your father.
${header}= Create Dictionary Content-Type=multipart/form-data
${res}= POST url=${API} data=${params} headers=${header}
Save JSON to file ${res.json()} a.json

RPA.Windows

Windows系统使用的包

*** Settings ***
_Library_     RPA.Windows
***** Tasks *****
**_Test for Study_**
    # 启动指定exe程序
    # Windows Run   NotePad
    # list Windows
    ${windows}=  List Windows
    FOR  ${window}  IN  @{windows}
        Log  Window title:${window}[title]
        Log  Window process name:${window}[name]
        Log  Window process id:${window}[pid]
        Log  Window process handle:${window}[handle]
    END
    # 切换到指定的Windows,subname 是标题里面保函的字符串
    [[Control]] Window  subname:微信
    Windows Search  DingTalk  0.5
    Control Window  subname:Code  foreground:True  0.8
    Control Window  subname:DingTalk  foreground:True  0.8
    Send Keys    keys={Ctrl}{Shift}{F}
    Send Keys    keys=代数民
    Send Keys    keys={Enter}
    Control Window  subname:DingTalk  foreground:True  0.8
    @{elements}=    Get Elements  control:Windows
    FOR    ${element}    IN    @{elements}
        Log To Console    ${element.name}
    END
    # 键盘输入操作
    [[Send]] Keys  keys={Ctrl}{T}
    [[Send]] Keys  keys={F6}
    [[Send]] Keys  keys=代数民 # 直接输入内容
    [[Send]] Keys  keys={F6}

RPA**.Desktop**

跨平台的桌面环境使用的包。

*** Settings ***
Library RPA.Desktop
*** Variables ***
${URL} https://www.baidu.com
${BROWSER} edge
${search_input} css=input[name=wd]
${search_button} css=input[id=su]
${ROBOT_ROOT} /Users/dcq/Documents/Project/RPA/test2
*** Test Cases ***
Test DingTalk
# Start every time!!
# Open Application /Applications/DingTalk.app/Contents/MacOS/DingTalk
# 图像识别,点击指定的图像位置
Click image:${ROBOT_ROOT}/images/dingtalk.png
Click image:${ROBOT_ROOT}/images/dingtalk_search.png
Type Text 叶宗兴
Sleep 2s
Press Keys enter
Sleep 1s
# 当前的鼠标位置
${position}= Get mouse position
Log Current mouse position is ${position.x}, ${position.y}
# 移动到当前相对位置
Move Mouse offset:-570,40
Sleep 1s
Click offset:0,0
Sleep 1s
Move Mouse image:${ROBOT_ROOT}/images/click_and_see.png
Sleep 1s
Click offset:0,0
Sleep 1s
Move Mouse offset:-100,0
${position}= Get Mouse Position
${region}= Define Region ${position.x - 100} ${position.y - 20} ${position.x + 100} ${position.y +20}
${text}= Read Text ${region}
Log 电话号码是${text}