2
from selenium import webdriver
3
from selenium.webdriver.common.keys import Keys
4
from selenium.webdriver.support.ui import WebDriverWait
5
from selenium.webdriver.support import expected_conditions as EC
6
from selenium.common.exceptions import TimeoutException
7
from selenium.webdriver.common.by import By
10
LOGIN_EMAIL, LOGIN_PASSWORD = storeconfig.get_store_credentials()
11
STORE_URL = storeconfig.get_store_web_url()
13
# default PAGE and ELEMENTS load timeout
14
PAGE_LOAD_TIMEOUT = 30
17
class UbuntuStoreWebTestsBase(unittest.TestCase):
25
# TODO - add support for multiple type browsers including Chrome, FF and IE
26
options = webdriver.ChromeOptions()
27
options.add_argument("--start-maximized")
28
self.driver = webdriver.Chrome(chrome_options=options)
30
def wait_for_element(self, locator, timeout=PAGE_LOAD_TIMEOUT):
31
"""Wait of element to be loaded for the given timeout,
32
default timeout is as per PAGE_LOAD_TIMEOUT variable"""
33
wait = WebDriverWait(self.driver, timeout)
35
element_present = EC.presence_of_element_located(locator)
36
wait.until(element_present)
37
except TimeoutException:
38
print ("Timed out waiting for "+locator[1]+" page")
40
def wait_for_page_title(self, title, timeout=PAGE_LOAD_TIMEOUT):
41
"""Wait for the target page title for given timeout,
42
default timeout is as per PAGE_LOAD_TIMEOUT variable"""
43
wait = WebDriverWait(self.driver, timeout)
46
find_title = EC.title_is(title)
47
wait.until(find_title)
49
except TimeoutException:
50
print ("Timed out waiting for "+title+ " page")
52
def wait_for_visible(self, locator, timeout=PAGE_LOAD_TIMEOUT):
53
"""Wait for the element to be visible for given timeout,
54
default timeout is as per PAGE_LOAD_TIMEOUT variable"""
55
wait = WebDriverWait(self.driver, timeout)
57
element_visible = EC.visibility_of_element_located((By.XPATH, "/html/body/nav/div/div[1]/span"))
58
wait.until(element_visible)
59
except TimeoutException:
60
print ("Timed out waiting for element to be visible")
62
def wait_for_clickable(self, locator, timeout=PAGE_LOAD_TIMEOUT):
63
"""Wait for the element to be visible for given timeout,
64
default timeout is as per PAGE_LOAD_TIMEOUT variable"""
65
wait = WebDriverWait(self.driver, timeout)
67
element_clickable = EC.element_to_be_clickable((By.XPATH, "/html/body/nav/div/div[1]/span"))
68
wait.until(element_clickable)
69
except TimeoutException:
70
print ("Timed out waiting for element to be clickable")
73
"""Login to web interface, following the UI flow which end user would use"""
77
signin_link = driver.find_element_by_link_text("Sign in or register")
79
self.wait_for_element((By.ID, 'login-form'))
80
login_form = driver.find_element_by_id("login-form")
81
email = login_form.find_element_by_id("id_email")
82
email.send_keys(LOGIN_EMAIL)
83
password = login_form.find_element_by_id("id_password")
84
password.send_keys(LOGIN_PASSWORD)
86
self.wait_for_element((By.NAME, 'decideform'))
87
decide_form = driver.find_element_by_name("decideform")
89
self.wait_for_page_title("Your packages")
92
"""Logout of web interface, following the UI flow which end user would use"""
94
self.wait_for_element((By.CLASS_NAME, "b-dropdown__arrow_light"))
96
# extremely ugly way to reach the desired element by xpath, a bug will be
97
# raised to uniquely identify the dropdown arrows
98
self.wait_for_clickable((By.XPATH, "/html/body/nav/div/div[1]/span"))
99
down_arrow = driver.find_element_by_xpath("/html/body/nav/div/div[1]/span")
101
# There is a bug with Firefox webdriver when clicking elements,
102
# as sometime click doesn't have any effect, to workaround that
103
# multiple attempts are made. However everything works fine with chrome webdriver.
106
wait = WebDriverWait(self.driver, 1)
109
element_present = EC.presence_of_element_located((By.CLASS_NAME, "b-dropdown_open"))
110
wait.until(element_present)
112
except TimeoutException:
113
print ("Failed to open the accounts dropdown menu card, Trying again")
116
self.wait_for_visible((By.LINK_TEXT, "Log out"))
117
logout_link = driver.find_element_by_link_text("Log out")
120
self.wait_for_page_title("Sign in to see your packages")
127
def tearDownClass(cls):
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# Snappy Ecosystem Tests
5
# Copyright (C) 2017 Canonical
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.