-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
74 lines (61 loc) · 2.16 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from robocorp.tasks import task
from robocorp import browser
from RPA.HTTP import HTTP
from RPA.Excel.Files import Files
from RPA.PDF import PDF
@task
def robot_spare_bin_python():
"""Insert the sales data for the week and export it as a PDF"""
browser.configure(
slowmo=100,
)
open_the_intranet_website()
log_in()
download_excel_file()
fill_form_with_excel_data()
collect_results()
export_as_pdf()
log_out()
def open_the_intranet_website():
"""Navigates to the given URL"""
browser.goto("https://robotsparebinindustries.com/")
def log_in():
"""Fills in the login form and clicks the 'Log in' button"""
page = browser.page()
page.fill("#username", "maria")
page.fill("#password", "thoushallnotpass")
page.click("button:text('Log in')")
def fill_and_submit_sales_form(sales_rep):
"""Fills in the sales data and click the 'Submit' button"""
page = browser.page()
page.fill("#firstname", sales_rep["First Name"])
page.fill("#lastname", sales_rep["Last Name"])
page.select_option("#salestarget", str(sales_rep["Sales Target"]))
page.fill("#salesresult", str(sales_rep["Sales"]))
page.click("text=Submit")
def download_excel_file():
"""Downloads excel file from the given URL"""
http = HTTP()
http.download(url="https://robotsparebinindustries.com/SalesData.xlsx", overwrite=True)
def fill_form_with_excel_data():
"""Read data from excel and fill in the sales form"""
excel = Files()
excel.open_workbook("SalesData.xlsx")
worksheet = excel.read_worksheet_as_table("data", header=True)
excel.close_workbook()
for row in worksheet:
fill_and_submit_sales_form(row)
def collect_results():
"""Take a screenshot of the page"""
page = browser.page()
page.screenshot(path="output/sales_summary.png")
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")
def log_out():
"""Presses the 'Log out' button"""
page = browser.page()
page.click("text=Log out")