Best Practice in Creating Workflow

Published at 21 November 2024 #tutorial

by

mgilangjanuar

Workflow is a primary component of Automa. It is used to run a series of blocks in a specific order. We can treat workflow as a result of automation that is built by Automa like JPEG files from Ms. Paint or SVGs from Figma.

Here are some tips for you to build maintainable and sustainable workflows:

1. Don't use the element selector that is impacted by i18n

i18n stands for internationalization. It means that sometimes a web page uses an i18n builder that is impacted by the language that the user is using.

To make your workflow to be maintainable, you should avoid using the element selector that is impacted by i18n. Eg, [arial-label="Search"], [label="Kirim Sekarang"]. Because we never know what the label of the element will be in other languages or devices. And it will make your workflow can't be executed by other people or your other devices.

2. Don't use the element selector with a randomized name

Some of the web pages have a randomized value of the element when it is built. For example, div#312YqV or p.67G1opB. The weakness of this is that it will make your workflow can't be sustained in the future because the element value will be different every it is built.

3. Utilize pseudo-class to match the element

The best way to choose a selector is if there's no good identifier for our workflow we can utilize CSS pseudo-class. If a web element looks like this:

...<div class="messages">  <div>Hello!</div>  <div>Oh hi, this is a message</div>  <div>Yes, this is a message too</div>  <div>And, this is a last message</div></div>

We can get the last message using the nth-last-child pseudo-class, like this: div.messages > div:nth-last-child(1). And, you can select the other message by an index with nth-child that starts from 1, such as div.messages > div:nth-child(1).

4. Utilize the XPath selector

Let's say you face web elements that really have no clue about the identifier they used. And, the only thing you know is the element contains a text you want to click or do something. If the element looks like this:

...<p>  Click on this button: <button>click me!</button></p>

You can select the button with XPath selector like this: //button[contains(text(), 'click me')].

5. Utilize the parameters trigger

There is a new feature in Automa v1.16.0 that allows you to pass parameters to the workflow: https://docs.automa.site/blocks/trigger.html#parameters.

It will be useful when you want to pass custom parameters to the workflow every time you need the workflow to be executed. And, all of these parameters will be included in the workflow's variable. You can access the parameters with {{variables@name}}, {{variables@query}}, or {{variables@id}}.


It's a wrap! We will keep this post updated to make be your guide on creating a workflow in Automa.

**

Cover image: Designed by vectorjuice / Freepik