Automation 360 Tutorial: Car Images background updating Bot

  • 9 November 2020
  • 0 replies
  • 144 views

Userlevel 6
Badge +9

In this tutorial, we will build a bot to change the background for multiple car images. Here is the use case we are addressing: A car dealer has pictures of his car inventory with non-uniform backgrounds. He wants to remove the background for each picture and update it to have a uniform branded background. Let's see how we can build a bot in Automation 360 to update all the images.

This bot can be used to update/remove background images for other use cases such as:

  • Updating employee profile pictures
  • Media houses use images without a background in different editorial sections
  • Marketing teams use it to update image backgrounds to suit different ads based on the context

Here is the data setup required to build this bot:

  • Download the folders with different car images here. Here are the pictures for your reference:
  • Download the background template image here.

Let's start building the bot by following the steps as shared below:

  1. Log in to the Automation 360 Control Room.
  2. Go to BotsMy bots, and click the Create a bot icon.
  3. In the Name field, enter 'Car Images Background Update Bot'
  4. Click Create & Edit.
  5. In the Actions pane, click Variables to create the following new variables:
    1. Name - sURL, Type - String, Default value - https://www.slazzer.com/upload. This is the website we will use to remove the background and add our standard background template image.
    2. Name - dictImageFileTypeDictionary and SubtypeString. - This variable will hold the file names and extension as a key-value pair. You can use the 'name' key to access the file name and 'extension' key to access the file extension.
    3. Name -  sInputFolderPathTypeString. This variable will contain the folder path in your local system which contains folders with pictures of different cars
    4. Name - sFolderName, TypeString. This variable will contain the foldername (sub folder) within the input folder path sInputFolderPath
    5. Name - sBGImagePath, TypeString. This variable will contain the background template image to be added to each car image.
    6. Name - sOutputFolderPath, TypeString. This variable will contain the folder path in your local system created by the bot and will be updated with new uniform car images.
  6. From the Action pane, select BrowserLaunch Website.
    1. In the URL field, enter $sURL$
    2. In Browser field, select Google Chrome
  7. Now we will loop through all the sub-folders folders within the given folder path.
    1. From the Action pane, select Loop.
      1. In the Iterator field, select For each folder in a folder
        1. Enter the folder path as $sInputFolderPath$
        2. In ‘Assign folder name to this variable’ field, select ‘sFolderName - String’
  8. As we are looping through each sub folder, let's create the sub folders with the same name as the car names shown in the data setup) within the output path.
    1. From the Action pane, select Folder - Create. This step will create the folders to store the updated images
      1. In the folder field, Enter the path as $sOutputFolderPath$$sFolderName$. This step will create folders within the output folder path
  9. The next step is to loop through all the files within each folder so that the bot can pick up each image and upload it to Slazzer for updating it with standard background template image.
    1. From the Action pane, select Loop.
      1. In the Iterator field, select For each file in folder
        1. Enter the folder path as $sInputFolderPath$$sFolderName$
        2. In the ‘Assign file name and extension to this variable’ field, select ‘dictImageFile - Dictionary of Strings’
  10. We will add Delays at each step to ensure the website is able to load and process the images.
  11. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  12. While building the bot, I have noticed that the Slazzer retains the image from a previous transaction. To handle this scenario let's add an If condition to click on the ‘X' mark if the earlier image is retained. When the Slazzer is launched the first time with the URL https://www.slazzer.com/upload, it will look like this:

While trying to upload a new image, if the page retains an earlier image, it will look like this. In this case, we want to click on 'X’ to remove the older image.  

  1. From the Action pane, select If
    1. Select Condition - Object
    2. In the Object detail field, click Window and select the Slazzer webpage
    3. Click Capture Object, identify the X symbol as shown above (We just want to check that this object is present)
  2. Within the If loop, From the Action Pane, select Recorder - Capture
    1. In Object detail, Select Window and Identify the browser instance with Slazzer website open
    2. Click on Capture Object and select the X symbol as shown above
    3. Select ActionLeft Click (Double check the properties shown in the screenshot below if you notice if the bot is not performing intended steps)
    4. Click Save.
  3. Now that the earlier image is removed from the display and the page looks like this
    1. From the Actions Pane, select Recorder - Capture, to click on the 'Upload Image' icon. (outside the If loop) but within the inside Loop
      1. In Object detail, Select Window and Identify the browser instance with Slazzer website open
      2. Click on Capture Object and select the Upload Image icon as shown below
      3. Select ActionLeft Click
  4. Add Delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  5. ‘Open Dialog’ is displayed to select the image to be uploaded to the website.From the Actions Pane, select Recorder - Capture, to enter the image path.
    1. In Object detail, Select Window and Identify the Open Dialog
    2. Click on Capture Object and select the Field - File Name text box as shown below
    3. Select ActionSet Text
      1. Enter Keystrokes as $sInputFolderPath$$sFolderName$$dictImageFile{name}$.$dictImageFile{extension}$. This path will fetch one image for each iteration within the loop
  6. Once the path is entered, next step is to click on ‘Open’ button. From the Actions Pane, select Recorder - Capture
    1. In Object detail, Select Window and Identify the Open Dialog
    2. Click on Capture Object and select the Open button as shown below
    3. Select ActionClick
  7. Add a delay of 3 seconds for the image to be loaded to the website. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  8. Image is loaded to the website and the background is removed as seen below, but we still have to add our branded background template image. To add the background image, click on Edit Image button.
    1. From the Actions Pane, select Recorder - Capture
      1. In Object detail, Select Window and identify the slazzer website instance
      2. Click on Capture Object and select the Edit Image button
      3. Select ActionClick
  9. Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  10. Once the Edit Image button is clicked, a dropdown will display as shown below, click ‘Edit Preview’ (Image BG9)
    1. From the Actions Pane, select Recorder - Capture
      1. In Object detail, select Window and identify the slazzer website instance
      2. Click on Capture Object and identify the object Edit Preview. In the attribute, HTML InnerText, retain the text ‘Edit Preview’ and add an asterisk instead of the exact dimension, as they change for different images. So, the attribute value will look this: Edit Preview*
      3. Select Action - Click
  11. Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 5, Time Unit as Seconds
  12. A new modal opens up where you can select the standard background template image.
    1. From the Actions pane, select Recorder - Capture
    2. In Object detail, select Window and identify the slazzer website instance
    3. Click on Capture Object and identify the object Upload Image.
    4. Select ActionLeft Click
  13. Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  14. ‘Open Dialog’ is displayed to select the standard background template image to be uploaded to the website.
    1. From the Actions pane, select Recorder - Capture, to enter the image path.
      1. In Object detail, Select Window and identify the Open Dialog
      2. Click on Capture Object and select the Field - File Name text box as shown below
      3. Select ActionSet Text
        1. Enter Keystrokes as $sBGImagePath$
  15. Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  16. Once the path is entered, the next step is to click on the ‘Open’ button. From the Actions pane, select Recorder - Capture
    1. In Object detail, select Window and identify the 'Open Dialog'
    2. Click on Capture Object and select the Open button
    3. Select ActionClick
  17. Add delays as required to ensure the website is able to keep up with bot execution speed. From the Action pane, select Delay, Delay type - Regular, enter Delay as 3, Time Unit as Seconds
  18. Now you can see our car image has a standard background. Click on the Download button.
    1. From the Actions pane, select Recorder - Capture
      1. In Object detail, select Window and identify the slazzer website instance
      2. Click on Capture Object and select the Download button
      3. Select ActionClick
  19. Now the updated car image is downloaded to your local system. Let’s get the browser back to its initial state before we process the next image. Enter URL https://www.slazzer.com/upload in the address bar and press Enter key.
    1. From the Actions Pane, select Recorder - Capture, to enter the URL mentioned above.
      1. In Object detail, Select Window and identify the Open Dialog
      2. Click on Capture Object and select the Address Bar
      3. Select ActionSet Text
        1. Enter Keystrokes as https://www.slazzer.com/upload[ENTER]
  20. We will add a delay to give the website a few seconds to download the updated image. From the Action pane, select Delay, Delay type - Regular, Enter Delay as 3, Time Unit as Seconds
  21. As the images download to ‘My Downloads’ folder, let's move it to ‘Output folder’ and maintain a similar folder structure as ‘Input folder’ from which we passed the car images to the bot.
    1. From the Actions pane, select File - Copy
      1. Enter the source file as D:<username>My Downloadsslazzer-edit-image.png (Add the correct path according to your settings), replace <username> by your user name
      2. Enter the Destination as $sOutputFolderPath$$sFolderName$$dictImageFile{name}$.png Object detail, This path will create the same folder structure as ‘Input folder’
  22. As the slazzer website downloads all the updated car images with the same name, we want to ensure that we delete the image from ‘My Downloads’ folder.
    1. From the Actions pane, select File - Delete
      1. Enter the file as D:<username>My Downloadsslazzer-edit-image.png (Add the correct path according to your settings), replace <username> by your user name
  23. This will be our final step which is outside the loop. Before we complete the bot, lets close the slazzer website instance.
    1. From the Actions Pane, select Simulate keystrokes- Simulate keystrokes
      1. Enter the file as D:<username>My Downloadsslazzer-edit-image.png (Add the correct path according to your settings), replace <username> by your user name
      2. Select Window and identify the browser instance with slazzer website.
      3. Keystrokes - Enter keystrokes here or use the on-screen keyboard, Enter [CTRL DOWN]w[CTRL UP]
  24. Your car image background update bot is ready.

   


0 replies

Be the first to reply!

Reply