aboutsummaryrefslogtreecommitdiffstats
path: root/services/frontend/fe_checklist_template.py
blob: 09a497f350d6d574269e1350fb657a498b556cbc (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
# under the Apache License, Version 2.0 (the “License”);
# you may not use this software except in compliance with the License.
# You may obtain a copy of the License at
#
#             http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
# Unless otherwise specified, all documentation contained herein is licensed
# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
# you may not use this documentation except in compliance with the License.
# You may obtain a copy of the License at
#
#             https://creativecommons.org/licenses/by/4.0/
#
# Unless required by applicable law or agreed to in writing, documentation
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
from selenium.webdriver.common.action_chains import ActionChains

from services.api.api_virtual_function import APIVirtualFunction
from services.constants import Constants
from services.database.db_checklist import DBChecklist
from services.database.db_user import DBUser
from services.frontend.base_actions.click import Click
from services.frontend.base_actions.enter import Enter
from services.frontend.base_actions.get import Get
from services.frontend.base_actions.wait import Wait
from services.frontend.fe_checklist import FEChecklist
from services.frontend.fe_general import FEGeneral
from services.frontend.fe_overview import FEOverview
from services.frontend.fe_user import FEUser
from services.helper import Helper
from services.logging_service import LoggingServiceFactory
from services.session import session


logger = LoggingServiceFactory.get_logger()


class FEChecklistTemplate:

    @staticmethod
    def basic_admin_navigation():
        FEUser.login(
            Constants.Users.Admin.EMAIL, Constants.Default.Password.TEXT)
        FEUser.go_to_admin()

    @staticmethod
    def click_on_template_name_on_navigation(template_name, text):
        Wait.text_by_name(template_name, text, wait_for_page=True)
        Click.name(template_name, wait_for_page=True)

    @staticmethod
    def click_on_save_and_assert_success_msg():
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SAVE_BTN_ID,
            wait_for_page=True)
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.APPROVE_BTN_ID,
            wait_for_page=True)
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SUCCESS_ID,
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.SUCCESS_SAVE_MSG)

    @staticmethod
    def click_on_disabled_save_and_assert_for_promp_msg():
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SAVE_BTN_ID)
        session.run_negative(
            lambda: Click.id(
                Constants.Dashboard.LeftPanel.
                EditChecklistTemplate.APPROVE_BTN_ID),
            "Ooops modal window is opened although 'Save' " +
            "button should have been disabled")

    @staticmethod
    def save_with_no_changes():
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SAVE_BTN_ID,
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SAVE_BTN)
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SAVE_BTN_ID,
            wait_for_page=True)
        Wait.text_by_name(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.HEAT,
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.HEAT)
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.APPROVE_BTN_TITLE_ID,
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.APPROVE_BTN_TITLE_TEXT)
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.APPROVE_BTN_ID,
            "Yes")
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.APPROVE_BTN_ID,
            wait_for_page=True)
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SUCCESS_ID,
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.CL_TEMPLATE_SAVED_TXT)

    @staticmethod
    def discard_checklist_after_modification():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID,
            wait_for_page=True)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_INPUT_ID,
            "ttttttt",
            wait_for_page=True)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID)
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.REJECT_BTN_ID)
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.APPROVE_BTN_ID,
            wait_for_page=True)
        Wait.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SUCCESS_ID,
            "All changes discarded.")

    @staticmethod
    def edit_template_and_save():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_INPUT_ID,
            "Ros Is My Mentor")
        FEChecklistTemplate.click_on_save_and_assert_success_msg()

    @staticmethod
    def del_lineitem_and_save():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID,
            wait_for_page=True)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_INPUT_ID,
            "Ros Is My Mentor",
            wait_for_page=True)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID)
        FEChecklistTemplate.click_on_save_and_assert_success_msg()

    @staticmethod
    def add_lineitem_and_save():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.ADD_LINE_ITEM_BTN,
            wait_for_page=True)
        Click.xpath("//li[@id='select-lineitem-btn-0.1']/span[2]")
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_NAME,
            "xxx")
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN,
            wait_for_page=True)
        FEChecklistTemplate.click_on_save_and_assert_success_msg()

    @staticmethod
    def edit_description_lineitem_and_save():
        desc = Helper.rand_string("randomString")
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_LINE_ITEM_ID)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_NAME,
            Helper.rand_string("randomString"))
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_DESC)
        editor_element = Get.wysiwyg_element_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.LINE_ITEM_DESC_TEXT_BOX)
        editor_element.clear()
        editor_element.send_keys(desc)
        Wait.page_has_loaded()
        actionChains = ActionChains(session.ice_driver)
        actionChains.double_click(editor_element).perform()
        Wait.page_has_loaded()
        Click.xpath(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.WYSIWYG_BUTTON_BOLD)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN,
            wait_for_page=True)
        isBold = Wait.is_css_exists("b")
        while not isBold:
            Click.id(
                Constants.Dashboard.LeftPanel.
                EditChecklistTemplate.EDIT_LINE_ITEM_BTN,
                wait_for_page=True)
            actionChains.double_click(editor_element).perform()
            Click.xpath(
                Constants.Dashboard.LeftPanel.
                EditChecklistTemplate.WYSIWYG_BUTTON_BOLD,
                wait_for_page=True)
            Click.id(
                Constants.Dashboard.LeftPanel.
                EditChecklistTemplate.EDIT_LINE_ITEM_BTN,
                wait_for_page=True)
            isBold = Wait.is_css_exists("b")
        if isBold:
            FEChecklistTemplate.click_on_save_and_assert_success_msg()
        FEGeneral.refresh()
        Click.name(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.HEAT,
            wait_for_page=True)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_LINE_ITEM_ID,
            wait_for_page=True)
        Wait.css("b")
        Wait.text_by_css("b", desc, wait_for_page=True)

    @staticmethod
    def rollback_add_lineitem_and_save():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.DELETE_LINE_ITEM)
        FEChecklistTemplate.click_on_save_and_assert_success_msg()
        FEChecklistTemplate.rollback_to_heat_teampleate()

    @staticmethod
    def add_lineitem_and_check_db():
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_ID)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.FIRST_SECTION_INPUT_ID,
            "Ros Is My Mentor")
        FEChecklistTemplate.click_on_save_and_assert_success_msg()
        result = DBChecklist.checkChecklistIsUpdated()
        Helper.internal_not_equal(result, None)

    @staticmethod
    def check_cl_after_lineitem_added():
        template_name = Constants.Dashboard.LeftPanel.\
            EditChecklistTemplate.HEAT
        user_content = APIVirtualFunction.create_engagement()
        FEUser.login(
            Constants.Users.Admin.EMAIL, Constants.Default.Password.TEXT)
        vfName = user_content['vfName']
        engagement_id = DBChecklist.fetchEngByVfName(vfName)
        engLeadEmail = DBUser.select_el_email(vfName)
        engagement_manual_id = DBChecklist.fetchEngManIdByEngUuid(
            engagement_id)
        FEOverview.click_on_vf(user_content)
        FEGeneral.re_open(Constants.Default.LoginURL.TEXT)
        FEUser.login(
            engLeadEmail,
            Constants.Default.Password.TEXT,
            engagement_manual_id)
        Click.id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.DASHBOARD_ID)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.SEARCH_ENG_ID,
            vfName)
        Click.id("test_" + vfName)
        checklistName = FEChecklist.create_checklist(
            engagement_id, vfName, None, engagement_manual_id)
        FEUser.go_to_admin()
        result = DBChecklist.fetchChecklistByName(checklistName)
        FEUser.go_to_admin()
        FEChecklistTemplate.click_on_template_name_on_navigation(
            Constants.Dashboard.LeftPanel.EditChecklistTemplate.HEAT,
            template_name)
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_NAME,
            "test_lineitem_added_and_audit_log_on_dupl_cl-NAME")
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.EDIT_LINE_ITEM_BTN)
        FEChecklistTemplate.click_on_save_and_assert_success_msg()
        Click.id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.DASHBOARD_ID)
        Enter.text_by_id(
            Constants.Dashboard.LeftPanel.
            EditChecklistTemplate.SEARCH_ENG_ID,
            vfName)
        Click.id("test_" + vfName)
        Click.id("checklist-" + str(result))
        Helper.internal_assert(
            "1. automation",
            session.ice_driver.find_element_by_xpath("//li[@id='']").text)