forked from IBM/python-flask-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperience_test.py
executable file
·35 lines (32 loc) · 1.39 KB
/
experience_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os, time, sys, datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
# 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))