Orchestration

Orchestrating and managing your Selenium automation

Even if you haven’t built your bots with Python frameworks from BotCity, you can orchestrate the automation you already have running in production using BotCity Maestro. Here is how to do this without needing to code again the bots that already support your business and its processes.

Understand the differences between the BotCity and Selenium frameworks

BotCity has frameworks for developing its automation with Python, such as desktop and web. The last one was built based on Selenium but with improvements and easier command usability for developers.

Here is an example of an implementation where it is necessary to open a browser with Chrome with a loaded profile:

With the Selenium framework:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

# instantiates the ChromeOptions class
options = webdriver.ChromeOptions()

# adds arguments for browser execution
options.add_argument("--user-data-dir=C:\\Users\\lsmac\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--profile-directory=Profile 1')

# configure the webdriver
driver = webdriver.Chrome(executable_path="<chromedriver.exe path>", options=options)

# opens the browser at the defined url
navegador.get("https://botcity.botcity.dev/")

With BotCity’s web framework:

from botcity.web import WebBot, Browser
from botcity.web.browsers.chrome import default_options
from webdriver_manager.chrome import ChromeDriverManager

# instantiate the bot
bot = WebBot()

# define which browser to use
bot.browser = Browser.CHROME

# sets the webdriver to run by passing the Chrome Webdriver path
bot.driver_path = "<chromedriver.exe path>"

# add arguments to browser execution
def_options = default_options(
        user_data_dir=r"C:\Users\lsmac\AppData\Local\Google\Chrome\User Data",  # if you do not inform, a temporary directory will be generated
    )

def_options.add_argument('--profile-directory=Profile 1')
# define these arguments in options
bot.options = def_options

# opens the browser at the defined url
bot.browse("https://botcity.botcity.dev/")

These two examples do the same process, but the BotCity framework, even based on Selenium, synthesizes, organizes, and makes the methods more intuitive for developers than pure Selenium.

However, it is essential to understand that even if you already have automation running in production that was developed directly with the Selenium framework, you can also use the BotCity Maestro orchestrator to manage them.

What is BotCity Maestro?

It is our orchestrator. With Maestro, you can manage your bots in a single platform with logs, alerts, and dashboards, among other features. And they can be the automation of any framework, as is the case with Selenium we are discussing in this article.

Why orchestrate and manage your bots?

Keeping track of how the robots are working, significantly when several of them, can help you monitor your automation. Not just ensuring that they have or have not been executed. But seeing possible errors, at what time each robot should be executed, in what sequence, etc. This makes day-to-day life easier, allows you to act where possible problems might occur, and further improves processes that have already been automated.

Orchestration can involve both the business area and the IT team (or CoE). And some features such as automation scheduling, alert triggers for users (process started, system down, error in request), management of logs from the processes created, integrations with communication systems (Microsoft Teams, Slack, Whatsapp, and E-mail) can guarantee a scalable, centralized, and efficient operation in your company.

How do I use Maestro in my automation built in pure Selenium?

Minimum requirements

In order for you to do this process, it is important to have two basic requirements:

  • bot.py: a file with this name that will be used as input to the BotCity Runner, as if it were the “main” part of your project;
  • requirements.txt: a file with this name that contains the dependencies that are used in the code. BotCity Runner will use this file as a reference to know which packages need to be installed to run your automation code.

Creating the bot.py file

Let’s exemplify creating a bot with pure Selenium that accesses BotCity’s YouTube channel and fetches the number of people subscribed. See the implementation below.

from selenium import webdriver

# sets Chrome as the browser
driver = webdriver.Chrome(executable_path="<chromedriver.exe path>")

# access Google homepage
driver.get("https://google.com")

# search for BotCity YouTube channel
search_bar = driver.find_element_by_name("q")
search_bar.send_keys("BotCity RPA Youtube")

# click in the button "I'm Feeling Lucky"
feeling_lucky_button = driver.find_element_by_xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[2]")
feeling_lucky_button.click()

# identifying the number of people subscribed to the channel
subscribers = driver.find_element_by_id("subscriber-count").text
print(f"Subscribers Count: {subscribers}")

# close the browser
driver.quit()

Creating the requirements.txt file

Create the file with the packages and their versions:

# configure to use a specific package 
selenium==3.141.0

Create a .zip file with the created files

You will get a structure similar to this:

CustomBot.zip
├── bot.py
└── requirements.txt

You can see more about this in our documentation.

Deploying in Maestro

Creating the automation

The first thing to do is to identify the “Easy Deploy” option in the menu located on the left side of the screen. When you click this option, you will have to fill in the name of the automation.

Screenshot of the maestro screen showing the easy deploy option. In the center is the field where the guidelines tell you to name the automation. In the example it is written BotYoutubeDemo.

Adding the bot in Maestro

In the next step, you must attach your robot (the .zip file that you created with the bot.py and requirements.txt files). Next, enter the programming language used to develop the bot, its name, and its version.

Screenshot of the easy deploy screen, showing the second part with an area in the center for attaching the robot. And on the right side, there are three fields to fill in: the technology, which is Python, the bot name, which is BotYoutubeDemo; and the version, which is 1.0.

Choosing where to run

In this step you must choose in which runner your automation should run or create a new one. And then click on “deploy”.

Screenshot in the third step with two fields, and the person must choose one: the first asks to select a runner that already exists, and the second asks to enter the name for a new one. And underneath is the deploy button that you click at the end of the process.

After this, it will load a screen with a message informing you that your deployment was successful.

Screenshot after the whole process with the congratulatory message that the deployment has been completed and giving the option to create a task if you want.

You can find more information about deployment and execution in our documentation.

But with these steps, you already have your automation available to be run, managed, and orchestrated by Maestro, regardless of whether you have created a project built entirely in non-BotCity frameworks.

How about trying out to see how it works – for free?

Click here to create your free account and test these and other features. Join us in our community’s Slack and share your feedback and suggestions.

She/her. I am a Tech Writer and Developer Relations at BotCity. I am also a tech content creator who loves tech communities and people.

Leave a Reply

%d