~canonical-platform-qa/snappy-ecosystem-tests/no-ephemeral-containers

« back to all changes in this revision

Viewing changes to snappy_ecosystem_tests/helpers/__init__.py

  • Committer: Heber Parrucci
  • Date: 2017-02-15 13:56:40 UTC
  • mfrom: (6.1.11 snappy-ecosystem-tests)
  • Revision ID: heber.parrucci@canonical.com-20170215135640-slzmv5k54hd71our
Fixing comments on code review.
Fixing pylint issues.
Addind a simple test for login to Store REST API

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest
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
8
 
import storeconfig
9
 
 
10
 
LOGIN_EMAIL, LOGIN_PASSWORD = storeconfig.get_store_credentials()
11
 
STORE_URL = storeconfig.get_store_web_url()
12
 
 
13
 
# default PAGE and ELEMENTS load timeout
14
 
PAGE_LOAD_TIMEOUT = 30
15
 
 
16
 
 
17
 
class UbuntuStoreWebTestsBase(unittest.TestCase):
18
 
 
19
 
    @classmethod
20
 
    def setUpClass(cls):
21
 
        pass
22
 
 
23
 
    def setUp(self):
24
 
        #
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)
29
 
 
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)
34
 
        try:
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")
39
 
 
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)
44
 
        try:
45
 
 
46
 
            find_title = EC.title_is(title)
47
 
            wait.until(find_title)
48
 
 
49
 
        except TimeoutException:
50
 
            print ("Timed out waiting for "+title+ " page")
51
 
 
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)
56
 
        try:
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")
61
 
 
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)
66
 
        try:
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")
71
 
 
72
 
    def login(self):
73
 
        """Login to web interface, following the UI flow which end user would use"""
74
 
        driver = self.driver
75
 
        driver.get(STORE_URL)
76
 
 
77
 
        signin_link = driver.find_element_by_link_text("Sign in or register")
78
 
        signin_link.click()
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)
85
 
        login_form.submit()
86
 
        self.wait_for_element((By.NAME, 'decideform'))
87
 
        decide_form = driver.find_element_by_name("decideform")
88
 
        decide_form.submit()
89
 
        self.wait_for_page_title("Your packages")
90
 
 
91
 
    def logout(self):
92
 
        """Logout of web interface, following the UI flow which end user would use"""
93
 
        driver = self.driver
94
 
        self.wait_for_element((By.CLASS_NAME, "b-dropdown__arrow_light"))
95
 
        #
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")
100
 
        #
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.
104
 
 
105
 
        for t in range(0,2):
106
 
            wait = WebDriverWait(self.driver, 1)
107
 
            try:
108
 
                down_arrow.click()
109
 
                element_present = EC.presence_of_element_located((By.CLASS_NAME, "b-dropdown_open"))
110
 
                wait.until(element_present)
111
 
                break
112
 
            except TimeoutException:
113
 
                print ("Failed to open the accounts dropdown menu card, Trying again")
114
 
 
115
 
 
116
 
        self.wait_for_visible((By.LINK_TEXT, "Log out"))
117
 
        logout_link = driver.find_element_by_link_text("Log out")
118
 
        logout_link.click()
119
 
 
120
 
        self.wait_for_page_title("Sign in to see your packages")
121
 
 
122
 
    def tearDown(self):
123
 
        self.driver.close()
124
 
        self.driver.quit()
125
 
 
126
 
    @classmethod
127
 
    def tearDownClass(cls):
128
 
        pass
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
 
 
3
#
 
4
# Snappy Ecosystem Tests
 
5
# Copyright (C) 2017 Canonical
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#