flowchart LR
0((start))
1{get_transaction_data}
2[process_data]
3[[end]]
0-->1
1-->|True|2
1-->|False|3
2-->1
Robot-framework is an RPA frame written in Python, it is designed for an easy and fast development of RPA automations. You can connect your developments with the robot manager console to use cloud features or execute your process locally.
visit https://ibott.io/Academy/robot-manager to learn more about the robot manager features.
Find the robot files in the robot directory.
Robot class:
This class is used to design the main structure of the robot. It contains all the methods to be executed by the robot. Heritages from Bot class to use predefine features and attributes.
Example:
from robot.robot import Bot
class Robot(Bot):
def __init__(self,**kwargs):
super().__init__(**kwargs)
def start(self):
print("I'm the first method")
def second(self):
print("I'm the second method")
def last(self):
print("I'm the last method")
Arguments:
Robot class can receive some arguments to establish connection with the robot manager console. These arguments are sent automatically from the robot manager console to initialize Bot class and establish the connection. You can also set the variables in debug.json file to use some console features while debugging your code.
- robotId: The robot's ID.
- ExecutionId: The execution ID.
- url: The url of the iBott API.
- username: The username of iBott account.
- password: The password of iBott account.
- orchestrator_parameters: Additional parameters sent from the robot manager console.
Decorators:
@RobotFlow is a decorator class that creates the flow of the bot. It grabs all decorated functions from the Robot class to create the workflow.
Example:
from robot.robot import Bot
from iBott import RobotFlow
from robot.flow import Nodes
class Robot(Bot):
def __init__(self):
super().__init__()
@RobotFlow(Nodes.StartNode)
def start(self):
print("I'm the fitst method")
Arguments: To instance Nodes classes and register them in the flow.
- Nodes: Nodes class that contains the nodes of the flow read more in flow.py .
- parents: *optional - Defines the ancestors of the current node in the flow.
- condition: *optional - Defines the condition of the current node for conditional nodes.
BusinessException & SystemException
Default exception classes for the robot. You must define your own process_exception method in file robot/exceptions.py if you want to use them.
- BusinessException: Exception raised when the robot fails due to a Business error like input errors, data validation etc.
- SystemException: Exception raised when the robot fails due to a System error like connection errors, etc.
Arguments:
- Robot: Robot class
- Message: Exception message
- next_action: method from robot class to be executed after the exception occurs. like retry, restart, skip, etc.
Here You can create your custom node classes for your workflow. New node classes must heritage from the base class RobotNode and be registered in the enum class Nodes.
Run function:
You can also override function run for default framework nodes.
Example:
from iBott.robot_activities.nodes import *
from enum import Enum
class CustomNode(RobotNode):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Override default run method
def run(self, robot, *args):
print("I'm the run funtion")
# Register custom nodes
class Nodes(Enum):
CustomNode = CustomNode
Here you can define the actions your process must do when exceptions are raised.
SystemException: This class Heritages from RobotException and is used to handle exceptions caused by system errors.
BusinessException: This class Heritages from RobotException and is used to handle exceptions caused by Business errors.
RobotException class has 3 default actions to handle the exception:
- retry: Retry the current node.
- restart: Restart the current node.
- go_to_node: Go to a specific node.
- skip: Skip the current node.
- stop: Stop the current flow.
Example:
from iBott.robot_activities.exceptions import RobotException
class SystemException(RobotException):
def __init__(self, *args, **kwargs):
super.__init__(*args, **kwargs)
def process_exception(self):
# send log to robot manager console.
self.robot.Log.business_exception(self.message)
# Process exception
if self.next_action == "retry":
self.retry(3)
elif self.next_action == "restart":
self.restart(3)
elif self.next_action == "go_to_node":
self.go_to_node("end", 3)
elif self.next_action == "skip":
self.skip()
elif self.next_action == "stop":
self.stop()
else:
raise Exception("Invalid next_action")
class BusinessException(RobotException):
def __init__(self, *args, **kwargs):
super.__init__(*args, **kwargs)
def process_exception(self):
self.robot.Log.business_exception(self.message)
self.stop()
Here you can define all the constants you are going to use during the process.
"""Email settings"""
EMAIL_ACCOUNT = None
EMAIL_PASSWORD = None
SMTP_HOST = None
SMTP_PORT = None
IMAP_HOST = None
IMAP_PORT = None
Here you can find pre made activities for your rpa developments.
Here you can find ChromeBrowser class. This class is used to create a browser object. It Heritages from the Chrome class and implements some custom methods to make browser automation easier.
- driver_path: path to the driver
- undetectable: if True, the browser will not be detected by antispam systems.
- driver_path: path to the driver
- undetectable: if True, the browser will not be detected by antispam systems.
- chrome_version: version of chrome
- options: options for the browser
- open(): open the browser and load defined options.
- ignore_images(): ignore images in the browser.
- ignore_popups(): ignore popups in the browser.
- ignore_notifications(): ignore notifications in the browser.
- ignore_errors(): ignore errors in the browser.
- headless(): open the browser in headless mode.
- save_cookies(): save the cookies of the browser.
- load_cookies(): load the cookies of the browser.
- set_proxy(proxy): set a proxy for the browser.
- set_user_agent(user_agent): set a user agent for the browser.
- set_profile(path): set a profile for the browser.
- scrolldown(h): scroll down to % height of the page .
- scrollup(h): scroll up to % height of the page .
- scroll_to_element(element): scroll to the element.
- set_download_folder(folder): set the download folder.
- element_exists(element): check if the element exists.
- add_tab(): add a new tab.
- get_tabs(): get the tabs of the browser.
- close_tab(): close the current tab.
- switch_to_tab(tab_number): switch to the tab.
- wait_for_element(element, timeout): wait for the element to appear.
- wait_for_element_to_disappear(element, timeout): wait for the element to disappear.
- wait_for_element_to_be_clickable(element, timeout): wait for the element to be clickable.
Here you can find FirefoxBrowser class. This class is used to create a browser object. It Heritages from the Firefox class and implements some custom methods to make browser automation easier.
driver_path: path to the driver undetectable: if True, to hide bot info in the browser.
- driver_path: path to the driver
- undetectable: if True, to hide bot info in the browser.
- open(): This method opens firefox browser to start the navigation. Set Custom options before using this method.
- ignore_images(): This method ignores images in the browser.
- ignore_popups(): This method ignores popups in the browser.
- ignore_notifications(): This method ignores notifications in the browser.
- ignore_errors(): This method ignores errors in the browser.
- headless(): This method ignores
- save_cookies(): This method saves cookies in the browser.
- load_cookies(): This method loads cookies in the browser.
- set_proxy(): This method sets proxy in the browser.
- set_user_agent(): This method sets user agent in the browser.
- set_profile(): This method sets profile in the browser.
- set_download_folder(): This method sets download folder in the browser.
- scrolldown(): This method scrolls down the browser.
- scrollup(): This method scrolls up the browser.
- scroll_to_element(): This method scrolls to the element in the browser.
- element_exists(): This method checks if the element exists in the browser.
- add_tab(): This method adds a new tab in the browser.
- get_tabs(): This method gets all the tabs in the browser.
- switch_tab(): This method switches to the tab in the browser.
- wait_for_element(): This method waits for the element in the browser.
- wait_for_element_to_disappear(): This method waits for the element to disappear in the browser.
- wait_for_element_to_be_clickable(): This method waits for the element to be clickable in the browser.
Custom WebElement class to add custom methods to WebElement class.
- double_click() : Double click on the element.
- enter(): Enter text in the element.
- tab(): Tab on the element.
- escape(): Escape on the element.
- backspace(): Backspace on the element.
- write(text): Write text in the element.
- clear(): Clear the element.
- get_text(): Get text from the element.
- get_link(): Get link from the element.
- get_attribute(attribute): Get attribute from the element.
Mail class, used to send and read email messages. Arguments:
- email: str
- password: str
- smtp_server: str
- smtp_port: int
- imap_server: str
- imap_port: int
Attributes:
- username: username of the mail account
- password: password of the mail account
- smtp_server: smtp server of the mail account
- smtp_port: smtp port of the mail account
- imap_server: imap server of the mail account
- imap_port: imap port of the mail account
Methods:
- send(send_to, subject, text=None, html=None, files=None): send mail
- fetch(folder, Query) : fetch mail list from mailbox use Query object and return MailMessage list
- find more information about Mail and Query objects here: https://pypi.org/project/imap-tools/0.16.1/#id2
Class to handle files. Arguments:
- file_path (str): path to the file
Attributes:
- file_path (str): path to the file
- exists (bool): whether the file exists
- file_name (str): name of the file
- byte_size (int): size of the file in bytes
- creation_datetime (datetime): datetime of the file's creation
- modification_datetime (datetime): datetime of the file's last modification
Methods:
- rename(new_file_name): renames the file
- move(new_location): moves the file to a new location
- remove(): removes the file
- copy(new_location): copies the file to a new location
- wait_for_file_to_exist(timeout=10): waits for the file to exist
Class to handle folders. If folder doesn't exist it automatically creates a new one. Arguments:
- path (str) -- path to folder to be instanced.
Attributes:
- path (str) -- path to folder to be instanced.
- name (str) -- name of folder
Methods:
- rename(new_folder_name) : Rename folder
- move(new_location): move folder to new location
- remove(allow_root=False, delete_read_only=True) : remove folder and all files and folders inside
- empty(allow_root=False): delete all files and folders in folder, receives allow_root as parameter
- copy(new_location=None) : Copy folder to new location
- subfolder_list(): list of subfolders
- file_list(): list of files in folder
- download_file(url, name=None): downloads file from url
Image Class, heritates from File class Attributes:
- size {tuple}: size of image
- format {str}: format of image
Methods:
- rotate(): rotate image
- resize(): resize image
- crop(): crop image
- mirrorH(): mirror image horizontally
- mirrorV(): mirror image vertically
PDF Class Heritates from File Class Arguments:
- file_path (str): Path of the file
Attributes:
- file_path (str): Path of the file
- pages (int): number of pages in the file
- info (str): info of the file
Methods:
- read_pages(page_num, encoding=None): Returns a string with the text in the page
- append(pdf_document2,merge_path): Appends a pdf document to the current document
- split(): split pdf into several pdfs.
This class is used to perform OCR on a pdf or an image file. It uses tesseract technology to convert images to text. Arguments:
- path (engine): The path to the OCR engine .
Methods:
- set_config(config): Sets the config for the OCR engine.
- read_picture(file_path, lang): Reads a picture and returns the text.
- read_pdf(file_path, scale, lang): Reads a pdf and returns the text.
- to_grayscale(file_path): Converts an image to grayscale.
- remove_noise(file_path): Removes noise from an image.
- thresholding(file_path): Thresholds an image.
- canny(file_path): Performs canny edge detection on an image.
- deskew(file_path): Deskews an image.
- opening(file_path): Performs an opening on an image.
- erode(file_path): Erodes an image.
- dilate(file_path): Dilates an image.
- opening(file_path): Performs an opening on an image.
Screen Class finds and interacts with Bitmap elements on the screen. Attributes:
- screen_size (tuple): The size of the screen.
- mousePosition (tuple): The position of the mouse.
Methods:
- click(clicks, button) - Perform click action on the screen.
- move_mouse_to(pos) - Move mouse to the specified position.
- drag_mouse_to(pos) - Drag mouse to the specified position.
- find_element(image_path) - Find the specified element on the screen.
- write(text) - Write text to the screen.
- click_image(image_path) - Click the specified image on the screen.
- shoot(image_path) - Take a screenshot of the screen.
Excel Class, receives path of excel file as parameter If Excel file doesn't exist it will be created automatically Arguments:
- path {str} -- path of excel file
Attributes:
- workbook {openpyxl.workbook.workbook.Workbook} -- workbook of excel file
Methods:
- open() -- open excel file
- save() -- save excel file
- add_sheet() -- add new worksheet to current workbook
- remove_sheet() -- remove sheet name
- rename_sheet() -- rename sheet name
- get_sheets() -- get a list of sheets in current workbook
- read_cell() -- read cell value.
- read_row_col() -- write cell value.
- write_cell() -- write cell value.
- write_row_col() -- write cell value.
Class to manage Word files it heritages from File class Arguments:
- file_path (str): path to the file
Attributes:
- document (docx.Document): document object
Methods:
- open(): open the file
- save(path): save the file
- add_heading(text, level): add a heading to the document '
- add_paragraph(text, style): add a paragraph to the document
- add_picture(path, size): add a picture to the document
- add_table(matrix): add a table to the document
- read(): read the file and return the text
- convert_to_pdf(path): convert the file to pdf