Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions scripts/experience_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

echo "Installing Chrome web driver..."
source <(curl -sSL "${DEVX_SKIT_ASSETS_GIT_URL_RAW:-https://raw.githubusercontent.com/IBM/devex-skit-assets/master}/scripts/install_chrome.sh")

echo "Starting Chrome web driver..."
source <(curl -sSL "${DEVX_SKIT_ASSETS_GIT_URL_RAW:-https://raw.githubusercontent.com/IBM/devex-skit-assets/master}/scripts/start_chrome.sh")

echo "Downloading and installing pip..."
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip -V

echo "Installing Selenium Python package..."
pip install selenium

echo "Running UI test using Selenium..."
python3 python_flask.py
34 changes: 34 additions & 0 deletions scripts/python_flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os, time, sys, datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

# Do an action on the app's landing page
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
driver.get(os.environ["APP_URL"]); # Open a browser to the app's landing page
time.sleep(3)

# Verify the expected content is present
title_text = driver.find_elements_by_xpath('//h1')[0].text
if len(title_text) == 0:
sys.exit("Experience Test Failed: no title texts found")
else:
print("The title text is: {}".format(title_text))
if title_text == "Congratulations!":
print("Experience Test Successful")
else:
sys.exit("Experience Test Failed: unexpected subtitle text {}".format(title_text))

subtitle_text = driver.find_elements_by_xpath('//h2')[0].text
if len(subtitle_text) == 0:
sys.exit("Experience Test Failed: no subtitle texts found")
else:
print("The subtitle text is: {}".format(subtitle_text))
if subtitle_text == "You are currently running a Python app built for the IBM Cloud.":
print("Experience Test Successful")
else:
sys.exit("Experience Test Failed: unexpected subtitle text {}".format(subtitle_text))