Commit 001ae27dbe026f7fa0dec336d571d5ffa9ff2ad4

Authored by Oleksandr Iskryzhytskyi
1 parent fa5393b2

common

- optimized: "get is element exist" keyword with JS help
- added: "generate_dictionary_from_field_path_and_value" keyword
plans
- added: updating plan by field key and value
@@ -9,4 +9,6 @@ __pycache__/ @@ -9,4 +9,6 @@ __pycache__/
9 /*.egg-info/ 9 /*.egg-info/
10 *.egg 10 *.egg
11 11
12 -/.idea  
  12 +/.idea
  13 +test.robot
  14 +/test_output
@@ -38,6 +38,10 @@ Resource playtender_plan. @@ -38,6 +38,10 @@ Resource playtender_plan.
38 [Arguments] ${user} ${plan_data} 38 [Arguments] ${user} ${plan_data}
39 [Documentation] Створити план з початковими даними plan_data. Повернути uaid створеного плану. 39 [Documentation] Створити план з початковими даними plan_data. Повернути uaid створеного плану.
40 40
  41 + # check buyers
  42 + ${buyers_count} = get length ${plan_data['data']['buyers']}
  43 + run keyword if ${buyers_count} != 1 fail Buyer must be one
  44 +
41 open new plan form 45 open new plan form
42 fill plan form ${plan_data['data']} 46 fill plan form ${plan_data['data']}
43 submit form and check result ${plan_form_submit_btn_locator} ${plan_form_submit_success_msg} ${plan_created_checker_element_locator} 47 submit form and check result ${plan_form_submit_btn_locator} ${plan_form_submit_success_msg} ${plan_created_checker_element_locator}
@@ -52,8 +56,18 @@ Resource playtender_plan. @@ -52,8 +56,18 @@ Resource playtender_plan.
52 open plan page by uaid ${plan_uaid} 56 open plan page by uaid ${plan_uaid}
53 57
54 Пошук плану по ідентифікатору 58 Пошук плану по ідентифікатору
55 - [Arguments] ${username} ${uaid}  
56 - [Documentation] Знайти план за вказаним uaid. 59 + [Arguments] ${username} ${plan_uaid}
  60 + [Documentation] Знайти план за зазначеним plan_uaid.
57 61
58 open plan search form 62 open plan search form
59 - input to search form and wait results ${plan_search_form_query_input_locator} ${uaid} ${plan_search_form_result_locator_tpl}  
  63 + input to search form and wait results ${plan_search_form_query_input_locator} ${plan_uaid} ${plan_search_form_result_locator_tpl}
  64 +
  65 +Внести зміни в план
  66 + [Arguments] ${username} ${plan_uaid} ${fieldname} ${fieldvalue}
  67 + [Documentation] Змінити значення поля fieldname на fieldvalue для плана із зазначеним plan_uaid.
  68 +
  69 + ${plan_data} = generate dictionary from field path and value ${fieldname} ${fieldvalue}
  70 + open plan form by uaid ${plan_uaid}
  71 + fill plan form ${plan_data}
  72 + submit form and check result ${plan_form_submit_btn_locator} ${plan_form_submit_success_msg} ${plan_created_checker_element_locator}
  73 + wait until page does not contain element with reloading ${plan_sync_element_locator}
@@ -79,6 +79,13 @@ click visible element @@ -79,6 +79,13 @@ click visible element
79 __private__set_element_visible_in_browser_area ${locator} 79 __private__set_element_visible_in_browser_area ${locator}
80 click element ${locator} 80 click element ${locator}
81 81
  82 +click visible element and wait until page contains element
  83 + [Arguments] ${locator} ${checker_element_locator} ${waiting_timeout}=30s ${waiting_error}=Another element was not shown after clicking on specific element
  84 + [Documentation] перевіряє видимість і клікає по елементу
  85 +
  86 + click visible element ${locator}
  87 + wait until page contains element ${checker_element_locator} ${waiting_timeout} ${waiting_error}
  88 +
82 input text to visible input 89 input text to visible input
83 [Arguments] ${locator} ${text} 90 [Arguments] ${locator} ${text}
84 [Documentation] перевіряє чи елемент видимий у вікні браузера, після чого заповнює його 91 [Documentation] перевіряє чи елемент видимий у вікні браузера, після чого заповнює його
@@ -202,6 +209,8 @@ submit current visible popup @@ -202,6 +209,8 @@ submit current visible popup
202 click visible element ${popup_opened_last_submit_btn_locator} 209 click visible element ${popup_opened_last_submit_btn_locator}
203 sleep ${popup_transaction_time} 210 sleep ${popup_transaction_time}
204 ${popup_last_locator} = set variable id=${popup_last_id} 211 ${popup_last_locator} = set variable id=${popup_last_id}
  212 + ${popup_exists} = __private__get_is_element_exist ${popup_last_locator}
  213 + return from keyword if ${popup_exists} == ${False}
205 wait until page does not contain element ${popup_last_locator} 30s Current popup was not hidden 214 wait until page does not contain element ${popup_last_locator} 30s Current popup was not hidden
206 215
207 submit form and check result 216 submit form and check result
@@ -289,7 +298,8 @@ __private__get_is_element_exist @@ -289,7 +298,8 @@ __private__get_is_element_exist
289 [Arguments] ${locator} 298 [Arguments] ${locator}
290 [Documentation] повертає чи елемент присутній на сторінці 299 [Documentation] повертає чи елемент присутній на сторінці
291 300
292 - ${result} = run keyword and return status page should contain element ${locator} 301 + ${result} = get is element exist ${locator}
  302 +# ${result} = run keyword and return status page should contain element ${locator}
293 [Return] ${result} 303 [Return] ${result}
294 304
295 __private__get_element_attribute 305 __private__get_element_attribute
@@ -9,6 +9,13 @@ open new plan form @@ -9,6 +9,13 @@ open new plan form
9 9
10 open page and wait element by locator ${broker_baseurl}/plan/create ${plan_form_locator} 10 open page and wait element by locator ${broker_baseurl}/plan/create ${plan_form_locator}
11 11
  12 +open plan form by uaid
  13 + [Arguments] ${plan_uaid}
  14 + [Documentation] відкриття сторінки редагування плану
  15 +
  16 + open plan page by uaid ${plan_uaid}
  17 + click visible element and wait until page contains element ${plan_edit_btn_locator} ${plan_form_locator}
  18 +
12 open plan page by uaid 19 open plan page by uaid
13 [Arguments] ${uaid} 20 [Arguments] ${uaid}
14 [Documentation] відкриває сторінку з планом 21 [Documentation] відкриває сторінку з планом
@@ -24,10 +31,6 @@ fill plan form @@ -24,10 +31,6 @@ fill plan form
24 [Arguments] ${data} 31 [Arguments] ${data}
25 [Documentation] заповнення форми з масива даних 32 [Documentation] заповнення форми з масива даних
26 33
27 - # check buyers  
28 - ${buyers_count} = get length ${data['buyers']}  
29 - run keyword if ${buyers_count} != 1 fail Buyer must be one  
30 -  
31 # hidden inputs 34 # hidden inputs
32 ${budget_id} = get from dictionary by keys ${data} budget id 35 ${budget_id} = get from dictionary by keys ${data} budget id
33 run keyword if condition is not none ${budget_id} input text to hidden input ${plan_form_budget_id_input_locator} ${budget_id} 36 run keyword if condition is not none ${budget_id} input text to hidden input ${plan_form_budget_id_input_locator} ${budget_id}
@@ -65,7 +68,11 @@ fill plan form items @@ -65,7 +68,11 @@ fill plan form items
65 [Documentation] заповнення номенклатури плану 68 [Documentation] заповнення номенклатури плану
66 69
67 :FOR ${item_attributes} IN @{item_attributes_array} 70 :FOR ${item_attributes} IN @{item_attributes_array}
68 - \ click visible element ${plan_form_add_item_btn_locator} 71 + \ ${item_update_index} = get from dictionary by keys ${item_attributes} list_index
  72 + \ ${item_update_index_string} = convert to string ${item_update_index}
  73 + \ ${open_form_btn_locator} = replace string ${plan_form_update_item_btn_locator_tpl} %index% ${item_update_index_string}
  74 + \ run keyword if condition is not none ${item_update_index} click visible element ${open_form_btn_locator}
  75 + \ run keyword if condition is none ${item_update_index} click visible element ${plan_form_add_item_btn_locator}
69 \ wait until popup is visible 76 \ wait until popup is visible
70 \ fill item form in opened popup ${item_attributes} 77 \ fill item form in opened popup ${item_attributes}
71 \ submit current visible popup 78 \ submit current visible popup
1 # -*- coding: utf-8 - 1 # -*- coding: utf-8 -
2 from robot.libraries.BuiltIn import BuiltIn 2 from robot.libraries.BuiltIn import BuiltIn
3 from iso8601 import parse_date 3 from iso8601 import parse_date
  4 +import re
4 5
5 6
6 def get_library(): 7 def get_library():
@@ -18,12 +19,18 @@ def get_variable_is_none(variable): @@ -18,12 +19,18 @@ def get_variable_is_none(variable):
18 return False 19 return False
19 20
20 21
21 -# check if condition is not none type and run specified keyword 22 +# run specified keyword if condition is not none type
22 def run_keyword_if_condition_is_not_none(condition, name, *args): 23 def run_keyword_if_condition_is_not_none(condition, name, *args):
23 if get_variable_is_none(condition) == False: 24 if get_variable_is_none(condition) == False:
24 BuiltIn().run_keyword(name, *args) 25 BuiltIn().run_keyword(name, *args)
25 26
26 27
  28 +# run specified keyword if condition is none type
  29 +def run_keyword_if_condition_is_none(condition, name, *args):
  30 + if get_variable_is_none(condition) == True:
  31 + BuiltIn().run_keyword(name, *args)
  32 +
  33 +
27 # return value for *keys (nested) in `element` (dict). 34 # return value for *keys (nested) in `element` (dict).
28 def get_from_dictionary_by_keys(element, *keys): 35 def get_from_dictionary_by_keys(element, *keys):
29 if not isinstance(element, dict): 36 if not isinstance(element, dict):
@@ -40,6 +47,33 @@ def get_from_dictionary_by_keys(element, *keys): @@ -40,6 +47,33 @@ def get_from_dictionary_by_keys(element, *keys):
40 return _element 47 return _element
41 48
42 49
  50 +# returns if element exists on page. optimization
  51 +def get_is_element_exist(locator):
  52 + jquery_locator = convert_locator_to_jquery(locator)
  53 + if get_variable_is_none(jquery_locator) == False:
  54 + jquery_locator = jquery_locator.replace('"', '\\"')
  55 + length = get_webdriver_instance().execute_script('return $("' + jquery_locator + '").length;')
  56 + return length > 0
  57 +
  58 + try:
  59 + get_library()._element_find(locator, None, True)
  60 + except Exception:
  61 + return False
  62 + return True
  63 +
  64 +
  65 +# convert locator to jquery locator
  66 +def convert_locator_to_jquery(locator):
  67 + locator_params = locator.split('=', 1)
  68 + if locator_params[0] == 'id':
  69 + return '#' + locator_params[1]
  70 + if locator_params[0] == 'jquery':
  71 + return locator_params[1]
  72 + if locator_params[0] == 'css':
  73 + return locator_params[1]
  74 + return None
  75 +
  76 +
43 # set scroll to element in view 77 # set scroll to element in view
44 def set_element_scroll_into_view(locator): 78 def set_element_scroll_into_view(locator):
45 element = get_library()._element_find(locator, None, True) 79 element = get_library()._element_find(locator, None, True)
@@ -141,3 +175,24 @@ def prepare_buyers_data(data): @@ -141,3 +175,24 @@ def prepare_buyers_data(data):
141 item.identifier['id'] = u"playtender" 175 item.identifier['id'] = u"playtender"
142 item.identifier['legalName'] = u"Playtender" 176 item.identifier['legalName'] = u"Playtender"
143 item.identifier['scheme'] = u"UA-EDR" 177 item.identifier['scheme'] = u"UA-EDR"
  178 +
  179 +
  180 +# prepare dictionary from field path + value
  181 +def generate_dictionary_from_field_path_and_value(path, value):
  182 + data = dict()
  183 + path_keys_list = path.split('.')
  184 + if len(path_keys_list) > 1:
  185 + key = path_keys_list.pop(0)
  186 + value = generate_dictionary_from_field_path_and_value('.'.join(path_keys_list), value)
  187 + indexRegex = re.compile(r'(\[(\d+)\]$)')
  188 + matchObj = indexRegex.search(key)
  189 + print matchObj
  190 + if matchObj:
  191 + key = indexRegex.sub('', key)
  192 + value['list_index'] = matchObj.group(2)
  193 + value = [value]
  194 + data[key] = value
  195 + else:
  196 + data = dict()
  197 + data[path] = value
  198 + return data
@@ -22,7 +22,7 @@ ${language_selector_list_element_locator_tpl} = jquery=.lang @@ -22,7 +22,7 @@ ${language_selector_list_element_locator_tpl} = jquery=.lang
22 ${classification_popup_opened_content_locator} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal # for checking if it's visible 22 ${classification_popup_opened_content_locator} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal # for checking if it's visible
23 ${classification_popup_scheme_tab_locator_tpl} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .nav a[data-toggle="tab"][data-scheme="%scheme%"] 23 ${classification_popup_scheme_tab_locator_tpl} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .nav a[data-toggle="tab"][data-scheme="%scheme%"]
24 ${classification_popup_search_input_locator} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .js-search-wrapper:visible .js-input 24 ${classification_popup_search_input_locator} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .js-search-wrapper:visible .js-input
25 -${classification_popup_serach_item_locator_tpl} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .js-search-wrapper:visible .js-search-tree strong:contains("%code%") 25 +${classification_popup_serach_item_locator_tpl} = jquery=.fancybox-is-open .fancybox-slide--current .fancybox-content.classification-modal .js-search-wrapper:visible .js-search-tree strong:contains(%code%)
26 26
27 # authorization 27 # authorization
28 ${login_popup_open_locator} = jquery=.page__header a[data-action="login"] 28 ${login_popup_open_locator} = jquery=.page__header a[data-action="login"]
@@ -57,6 +57,7 @@ ${plan_form_classification_edit_btn_locator} = jquery=.fiel @@ -57,6 +57,7 @@ ${plan_form_classification_edit_btn_locator} = jquery=.fiel
57 ${plan_form_additional_classification_edit_btn_locator} = jquery=.field-planform-additional_classification_ids .js-additional-classification-input-wrapper [data-toggle="additional-classification"] 57 ${plan_form_additional_classification_edit_btn_locator} = jquery=.field-planform-additional_classification_ids .js-additional-classification-input-wrapper [data-toggle="additional-classification"]
58 ${plan_form_kekv_classification_edit_btn_locator} = jquery=.field-planform-additional_classification_ids_kekv .js-additional-classification-input-wrapper [data-toggle="additional_classification_ids_kekv"] 58 ${plan_form_kekv_classification_edit_btn_locator} = jquery=.field-planform-additional_classification_ids_kekv .js-additional-classification-input-wrapper [data-toggle="additional_classification_ids_kekv"]
59 ${plan_form_add_item_btn_locator} = jquery=#Items .js-form-popup-add 59 ${plan_form_add_item_btn_locator} = jquery=#Items .js-form-popup-add
  60 +${plan_form_update_item_btn_locator_tpl} = jquery=#Items .js-form-popup-panel:nth(%index%) .panel-heading .js-form-popup-update
60 ${plan_form_submit_btn_locator} = jquery=#plan-form .js-submit-btn 61 ${plan_form_submit_btn_locator} = jquery=#plan-form .js-submit-btn
61 ${plan_created_checker_element_locator} = id=plan-part-pjax 62 ${plan_created_checker_element_locator} = id=plan-part-pjax
62 63
@@ -64,8 +65,9 @@ ${plan_created_checker_element_locator} = id=plan-part @@ -64,8 +65,9 @@ ${plan_created_checker_element_locator} = id=plan-part
64 ${plan_view_checker_element_locator} = id=plan-general-info 65 ${plan_view_checker_element_locator} = id=plan-general-info
65 ${plan_sync_element_locator} = jquery=#aside-part-pjax .status-label .fa-refresh 66 ${plan_sync_element_locator} = jquery=#aside-part-pjax .status-label .fa-refresh
66 ${plan_uaid_text_locator} = jquery=#plan-general-info .plan-id .value 67 ${plan_uaid_text_locator} = jquery=#plan-general-info .plan-id .value
  68 +${plan_edit_btn_locator} = jquery=#aside-part-pjax a[href*='plan/update']
67 69
68 # plan index + search 70 # plan index + search
69 ${plan_search_form_locator} = id=plan-filter-form 71 ${plan_search_form_locator} = id=plan-filter-form
70 ${plan_search_form_query_input_locator} = jquery=#plan-filter-form .dynamic-search-query input 72 ${plan_search_form_query_input_locator} = jquery=#plan-filter-form .dynamic-search-query input
71 -${plan_search_form_result_locator_tpl} = jquery=#plan-list .lots__item .lot__characteristic li:contains("%query%")  
  73 +${plan_search_form_result_locator_tpl} = jquery=#plan-list .lots__item .lot__characteristic li:contains(%query%)
Please register or login to post a comment