Automate Solution Publishing

You might have have a need to automatically publish a Outsystems Solution at a desired time (probably overnight when this don’t affect anyone) to be able to start the next day with all modules refreshed.

If you have/had this need, you should also know that Outsystems don’t have this kind of automation.

Let’s take a look on how to achieve it.

What you will need:

  • A computer that is turned on when you need the automation to run
  • WebDriver for your Browser
  • Python and Selenium

Let’s go step-by-step:

  1. Install Python: Download Python and ensure you select the option to “Add Python to PATH” during installation.
  2. Install Selenium: Open Command Prompt and run: pip install selenium
  3. Install WebDriver: I’m using Chrome and Chrome WebDriver can be found here:
    https://googlechromelabs.github.io/chrome-for-testing/#stable
    You just need to download the version that matches your browser version.
    After downloading it, put the WebDriver executable in a folder like C:\webdriver. Add that folder to your system’s PATH environment variable.

Right now you should have the hardware (machine to run the script) and the required software to automate this process.

Next you need to create a file to contain the script, ex: ‘automate-solution-publish.py’ and add the script to the file.

I’ll provide a working example where you must change the configurations for your scenario/infrastructure.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# CONFIGURATIONS

hostname = ''
solution_id = ''
username = ''
password = ''


# Setup options for headless (optional)
chrome_options = Options()
#chrome_options.add_argument("--headless")  # Optional, if you want to run without opening the browser window

# Path to your ChromeDriver
driver_path = "C:/webdriver/chromedriver.exe"  # Change this to the path where you placed your chromedriver

# Setup the driver
service = Service(driver_path)
driver = webdriver.Chrome(service=service, options=chrome_options)

try:
    # Open the login page
    driver.get(hostname + '/ServiceCenter/Home.aspx')

    # Fill in the login form (adjust the element selectors to fit the actual login form)
    username_input = driver.find_element(By.XPATH, "//*[contains(@id, 'wtInput1')]")
    password_input = driver.find_element(By.XPATH, "//*[contains(@id, 'wtInputPass1')]")

    # Input login credentials
    username_input.send_keys(username)
    password_input.send_keys(password)

    # Click the login button
    button = driver.find_element(By.XPATH, "//*[contains(@id, 'wtButton1')]")
    button.click()
    
    # Wait for the page to load
    time.sleep(5)
    
    # Open the solution page
    driver.get(hostname + '/ServiceCenter/Solution_Edit.aspx?SolutionId=' + solution_id)
    
    # Wait for the page to load
    time.sleep(5)
    
    publish_button = driver.find_element(By.XPATH, "//table[contains(@id, 'wtListVersions')]//tr[1]//input[@value='Publish']")
    publish_button.click()
    
    # Wait for the alert and accept it
    try:
        # Wait for the alert to appear (max 10 seconds)
        alert = WebDriverWait(driver, 10).until(EC.alert_is_present())
        
        # Accept the alert (clicks OK)
        alert.accept()

        print("Alert accepted!")
    except:
        print("No alert appeared.")
    
    time.sleep(10)

finally:
    # Close the browser
    driver.quit()

What this script does:

  1. Opens the Service Center login page;
  2. Uses XPath to find the username input. If you inspect HTML, you’ll find that this textbox id ends with ‘wtInput1’
  3. Uses XPath to find the password input. If you inspect HTML, you’ll find that this textbox id ends with ‘wtInputPass1’
  4. Uses the values in the configuration to fill in those inputs
  5. Uses XPath to find the login button. If you inspect HTML, you’ll find that this button id ends with ‘wtButton1’ and clicks the button
  6. We wait for the page to load and next we load the solution page that we want to publish. This also needs the solution id configured.
  7. This might be the trickiest part, but we know that we need to find the ‘Publish’ button that exists in the first row corresponding to the ‘Current Running Version’ of the solution. If we inspect HTML we’ll see that the versions list table id ends with ‘wtListVersions’ and we need the input with value = ‘Publish’
    “//table[contains(@id, ‘wtListVersions’)]//tr[1]//input[@value=’Publish’]”
    and the button needs to be clicked.
  8. When we click the Publish button, an alert message appears that needs to be confirmed, and this is what’s done next.

Important to take in mind:
This script execution relies on finding HTML elements with specific ids and if those ids change, you also need to change them in this script.

Last step is to automate it’s execution and to achieve that you just need to configure it’s execution on windows scheduler.

Multiple solutions exist for the same problem and this is only one of them

Tiago