In Robotic Process Automation - 2 weeks ago

How to order pizza the RPA way!

Robotic Pizza Automation with Robotic Process Automation

Introduction

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?"

Requirements

  1. A Dominos Pizza account
  2. Download TagUI and follow the instructions to set up on your machine.
  3. Check that Java JDK (64-bit) is installed (enter java -version into the terminal)
  4. Download sikulix.jar and save it into src/sikulix folder. You need this to interact with desktop applications.
  5. Install Pushed app to your mobile device and signup for an account.
  6. An empty stomach

Get your grub on

I needed to orchestrate a series of events to achieve my goal.

  1. Open the browser and go to https://www.dominos.com.sg.
  2. Click the "Start Order" button and enter my login details.
  3. Select my predefined address and click the "Start Delivery Order" button.
  4. Open the Pizza menu.
  5. Select the pizza, pizza size and crust type.
  6. Add the pizza to cart, checkout my order and make payment.
  7. Send a notification to my mobile device upon order confirmation.
  8. Profit!
...
// 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:

  • chrome - run on visible Chrome web browser
  • quiet - run without output except for explicit output (echo / show / check / errors etc)
$ ./tagui your-script-folder/dominos chrome quiet

Perfect crust but not quite

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.

Sending Push Notifications

Option 1 - Automate Email sending with SikuliX

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`)

 

Option 2 - Send push notifications using Pushed

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`

Slice To Meet You

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

 

The entire process in all its wonderful pepperoni glory!

Conclusion

Things I liked about TagUI.
  • Extremely developer friendly.
  • The ability to code the automation flow in human language.
  • Automatic conversion of process steps to JavaScript is fascinating, almost magical.
  • Made in Singapore.
  • Zero cost. More savings means more pizza!
Key Takeaways
  • Always test your automation flow.
  • RPA is not some magical blackbox that can perform tasks at your bidding.
  • Most of the work lies in configuration and testing. To achieve the ideal output takes a fair bit of trial and error.
  • Just like pizza, it is far better to configure and test the automation flow in smaller chunks, as opposed to the entire piece.
  • If you code and eat pizza at the same time, you will have oily keyboard.
  • Pineapples on pizza is a travesty.

blog comments powered by Disqus