Disclaimer: Domino’s Pizza did not sponsor this post.
This preposterous idea came about as I was streaming the latest season of Black Mirror while lying on my couch.
I was craving for pizza but placing an online order on a Saturday afternoon took too much effort.
The situation looked grim. On the one hand I was starving but on the other hand I was unwilling to haul my lazy butt out of the couch.
That’s when I started my indefatigable journey to find a solution that can automate my pizza ordering process.
After some Google-fu, I stumbled upon this gem call TagUI and was immediately sold by the intro.
"The goal of UI (user interface) automation is to reproduce cognitive interactions that you have with websites or your desktop, so that your computer can do it for you, based on your schedule or conditions.
TagUI helps you rapidly automate repetitive or time-critical tasks - use cases include digital process automation, data acquisition and testing."
It’s the perfect tool for my slothful habits. Better not let that talent go to waste!
What is Robotic Process Automation (RPA)?
Robotic Process Automation (or RPA for short) is a technology that uses software robots to automate repetitive business processes.
The “robots” are configured to perform repetitive tasks like data entry, filling in web forms, sending predefined emails, updating inventory etc.
Read - "What is Robotic Process Automation?"
I needed to orchestrate a series of events to achieve my goal.
...
// Step 1 - Visit URL
https://www.dominos.com.sg/
// Login variables. Replace with your own.
email = your-email-address
password = your-email-password
// Start order
echo "Start order"
// Step 2 - Login Details
echo "Login"
click login-btn
type login_email as `email`
type login_password as `password`
click //*[@id="sign_in_form"]/div[3]/div[1]/button
...
Click here to view the full code
Execute the script with the following options:
$ ./tagui your-script-folder/dominos chrome quiet
The code works with a huge caveat.
There could be instances where page elements are undetectable due to page rendering or network latency issues.
Thankfully, TagUI has a visible() helper function to detect elements on screen.
All that's needed was a little tweak to the script to make it bulletproof.
...
// Step 3 - Start Delivery Order
echo "Start delivery order"
wait
for n from 1 to infinity
{
// Check for visible element
if visible('/html/body/div[3]/section/div/div[2]/ul[2]/li')
{
select orderDate as 2019/07/03
click /html/body/div[3]/section/div/div[2]/ul[2]/li
wait 2
click btnOrderDelivery
break
}
else
{
// Wait for 2 secs
wait 2
}
}
...
Click here to view the full code
As TagUI has built-in integration with SikuliX, I could simulate sending of emails via the mail app using X, Y coordinates and keystroke combinations.
...
// Step 11 - Send Email Notification
// Click Mail App. Replace X and Y coordinates with your own.
echo "Sending Email"
hover (`57`,`78`)
wait 2
dclick (`57`,`78`)
wait
// Create New Mail
click (`76`,`60`)
wait
keyboard your-email-address
wait
// Enter Subject
vision type(Key.TAB)
vision type(Key.TAB)
wait
keyboard Your Pizza Delivery Details
wait
// Enter Message
vision type(Key.TAB)
wait
keyboard Your pizza will arrive at approximately 12pm.
wait
// Send email
click (`432`,`145`)
wait
// Close mail app
click (`14`, `32`)
...
Using the Pushed app, I was able to send a push notification to my mobile device using Pushed's API.
...
// Step 11 - Send Push Notifications via Pushed API
// Replace 'orderTime' with estimated delivery time from order confirmation page.
// echo "Sending push notification"
app_key = your-app-key
app_secret = your-app-secret
message = "Your pizza will arrive approximately 1 hour after " + orderTime
api_config = {method:'POST', header:[], body:{}}
api https://api.pushed.co/1/push?app_key=`app_key`&app_secret=`app_secret`&target_type=app&content=`message`
...
For the ultimate topping, I created a simple bash script to set up the ordering pipeline.
##!/bin/bash
cd /path-to-tagui/src
./tagui src/dominos-revised chrome quiet