update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / ra / pytest / ns / gui_tests / test_launchpad_ui.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18
19 import gi
20
21 from selenium.webdriver.support.ui import WebDriverWait
22 from selenium.webdriver.support import expected_conditions as EC
23 from selenium.webdriver.common.by import By
24
25
26 gi.require_version('RwUserYang', '1.0')
27 gi.require_version('RwProjectYang', '1.0')
28 gi.require_version('RwConmanYang', '1.0')
29
30 from gi.repository import (
31 RwUserYang,
32 RwProjectYang,
33 RwConmanYang
34 )
35
36 gi.require_version('RwKeyspec', '1.0')
37 from gi.repository.RwKeyspec import quoted_key
38
39
40 class TestGUI(object):
41 """TestGUI."""
42
43 def click_element_and_wait(self, driver, key_word, wait=True):
44 """Click and wait for that element to appear."""
45 path = "//a[text()={}]".format(quoted_key(key_word))
46 driver.find_element_by_xpath(path).click()
47 if wait is True:
48 WebDriverWait(driver, 10).until(
49 EC.presence_of_element_located((
50 By.XPATH, path)))
51
52 def click_button(self, driver, key_word):
53 """Click a button."""
54 path = "//div[text()={}]".format(quoted_key(key_word))
55 driver.find_element_by_xpath(path).click()
56
57 def input_value(self, driver, data_reactid, value):
58 """Input values to field."""
59 path = "//input[@data-reactid={}]".format(quoted_key(data_reactid))
60 driver.find_element_by_xpath(path).send_keys(value)
61
62 def test_basic_checks(
63 self, driver, logger, rw_project_proxy, rw_user_proxy):
64 """test_basic_checks."""
65 logger.debug('Check access to all basic pages.')
66 basic_pages = (
67 ['Accounts', 'Catalog', 'Launchpad', 'ADMINISTRATION',
68 'PROJECT: default', 'admin'])
69 for key_word in basic_pages:
70 self.click_element_and_wait(driver, key_word)
71
72 logger.debug('Create a test project.')
73 self.click_element_and_wait(driver, 'ADMINISTRATION')
74 self.click_element_and_wait(driver, 'Project Management', wait=False)
75 self.click_button(driver, 'Add Project')
76 self.input_value(driver, '.0.4.0.1.0.4.0.0.1.0.1', 'test_project')
77 self.click_button(driver, 'Create')
78
79 logger.debug('Verify test project is created in ui.')
80 path = "//div[text()={}]".format(quoted_key('test_project'))
81 WebDriverWait(driver, 10).until(
82 EC.presence_of_element_located((
83 By.XPATH, path)))
84
85 logger.debug('Verify test project is created in config.')
86 project_cm_config_xpath = '/project[name={}]/project-state'
87 project_ = rw_project_proxy.get_config(
88 project_cm_config_xpath.format(
89 quoted_key('test_project')), list_obj=True)
90 assert project_
91
92 logger.debug('Create a test user.')
93 self.click_element_and_wait(driver, 'ADMINISTRATION')
94 self.click_element_and_wait(driver, 'User Management', wait=False)
95 self.click_button(driver, 'Add User')
96 self.input_value(driver, '.0.4.0.1.1.0.4.0.0.1.0.1', 'test_user')
97 self.input_value(driver, '.0.4.0.1.1.0.4.0.3.1.0.1', 'mypasswd')
98 self.input_value(driver, '.0.4.0.1.1.0.4.0.3.1.1.1', 'mypasswd')
99 self.click_button(driver, 'Create')
100
101 logger.debug('Verify test user is created in ui.')
102 path = "//div[text()={}]".format(quoted_key('test_user'))
103 WebDriverWait(driver, 10).until(
104 EC.presence_of_element_located((
105 By.XPATH, path)))
106
107 logger.debug('Verify test user is created in config.')
108 user_config_xpath = (
109 '/user-config/user[user-name={user_name}][user-domain={domain}]')
110 user_ = rw_user_proxy.get_config(
111 user_config_xpath.format(
112 user_name=quoted_key('test_user'),
113 domain=quoted_key('system')))
114 assert user_