Write and test macros#
This page walks through the steps: write a macro, test it in Studio until it works correctly, then paste it into a campaign.
Structure of a macro#
You write the commands directly in the order they should run. You do not need to wrap them in an
async function, and you can use await from the very first line.
Always use await#
Most browser functions are asynchronous and need await in front of them: clicks
(ClickById, ClickBySelector...), typing (Typing, SendKeyPress...), waiting (WaitForLoading,
WaitForElmtBySelector...), reading and writing the page (EvalScript, GetHtml, GetUrl...). A
missing await does not raise an error, but the macro moves on before the action finishes, which
leads to missed clicks or to reading data that is not ready yet.
A few functions return their result right away and do not need await, such as IsMobile,
GetUserAgent, GenerateXpath.
Log for debugging#
Log(...) prints to the Logs panel in Studio and takes several arguments, which makes it easy to
print a label along with a value.
Test in Studio#
Open Studio, paste the macro into Main Script, enter the target URL in the General
tab, then click Run. Watch the Logs panel to see how far the macro gets. If the macro hangs or does
the wrong thing, click Kill Browser, fix it and run it again.
A simple macro example#
The macro below waits for the page to finish loading, prints the URL to the Logs panel, then clicks
a random link.
await WaitForLoading();
Log("Page finished loading:", await GetUrl());
await ClickRandomLink();
Log("Clicked a random link on the page");
Put it in a real campaign#
Once the macro has run correctly over a few tests, paste it unchanged into the Macros tab of the
campaign form: the Main macro box for the main window, the Popup macro box for popups. Do not skip
testing: a macro with a wrong selector still runs for the whole view duration without doing what you
want, and the numbers on the dashboard do not show that problem.