Skip to content

Commit a8c7c16

Browse files
� Conflicts: � Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py
2 parents 31dea81 + a781e2a commit a8c7c16

File tree

10 files changed

+610
-114
lines changed

10 files changed

+610
-114
lines changed

Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py

Lines changed: 522 additions & 7 deletions
Large diffs are not rendered by default.

Framework/Built_In_Automation/Desktop/Windows/BuiltInFunctions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,16 +2341,15 @@ def save_attribute_values_in_list(data_set):
23412341
right = right.strip()
23422342
if "target parameter" in mid:
23432343
target.append([[], "", [], []])
2344-
temp = right.strip(",").split('",\n')
2344+
temp = right.strip(",").split(',\n')
23452345
data = []
2346-
temp[-1] = temp[-1][:-1]
23472346
for each in temp:
23482347
data.append(each.strip().split("=", 1))
23492348
for i in range(len(data)):
23502349
for j in range(len(data[i])):
23512350
data[i][j] = data[i][j].strip()
23522351
if j == 1:
2353-
data[i][j] = data[i][j][1:] # dont add another strip here. dont need to strip inside quotation mark
2352+
data[i][j] = CommonUtil.strip1(data[i][j], '"') # dont add another strip here. dont need to strip inside quotation mark
23542353

23552354
for Left, Right in data:
23562355
if Left == "return":

Framework/Built_In_Automation/Mobile/CrossPlatform/Appium/BuiltInFunctions.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,21 @@ def start_appium_driver(
869869
# saving simulator path for future use
870870
Shared_Resources.Set_Shared_Variables("ios_simulator_folder_path", str(app))
871871

872-
app = os.path.join(app, ios)
873-
encoding = "utf-8"
874-
bundle_id = str(
875-
subprocess.check_output(
876-
["osascript", "-e", 'id of app "%s"' % str(app)]
877-
),
878-
encoding=encoding,
879-
).strip()
880-
881-
desired_caps["app"] = app # Use set_value() for writing to element
882-
desired_caps["bundleId"] = bundle_id.replace("\\n", "")
872+
ios_part = ios.split('.')[0]
873+
if ios_part == 'com':
874+
desired_caps["bundleId"] = ios
875+
else:
876+
app = os.path.join(app, ios)
877+
encoding = "utf-8"
878+
bundle_id = str(
879+
subprocess.check_output(
880+
["osascript", "-e", 'id of app "%s"' % str(app)]
881+
),
882+
encoding=encoding,
883+
).strip()
884+
885+
desired_caps["app"] = app # Use set_value() for writing to element
886+
desired_caps["bundleId"] = bundle_id.replace("\\n", "")
883887

884888
desired_caps["platformName"] = "iOS" # Read version #!!! Temporarily hard coded
885889
desired_caps["platformVersion"] = platform_version
@@ -4058,16 +4062,15 @@ def save_attribute_values_appium(step_data):
40584062
right = right.strip()
40594063
if "target parameter" in mid:
40604064
target.append([[], [], [], []])
4061-
temp = right.strip(",").split('",\n')
4065+
temp = right.strip(",").split(',\n')
40624066
data = []
4063-
temp[-1] = temp[-1][:-1]
40644067
for each in temp:
4065-
data.append(each.strip().split("=",1))
4068+
data.append(each.strip().split("=", 1))
40664069
for i in range(len(data)):
40674070
for j in range(len(data[i])):
40684071
data[i][j] = data[i][j].strip()
40694072
if j == 1:
4070-
data[i][j] = data[i][j][1:] # do not add another strip here. dont need to strip inside quotation mark
4073+
data[i][j] = CommonUtil.strip1(data[i][j], '"') # do not add another strip here. dont need to strip inside quotation mark
40714074

40724075
for Left, Right in data:
40734076
if Left == "return":

Framework/Built_In_Automation/Sequential_Actions/action_declarations/desktop.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
{ "name": "take partial screenshot", "function": "take_partial_screenshot", "screenshot": "desktop" },
2020
{ "name": "get bounding box", "function": "get_bbox", "screenshot": "desktop" },
2121
{ "name": "keystroke chars", "function": "keystroke_for_element", "screenshot": "desktop" },
22+
{ "name": "ocr click", "function": "ocr_click", "screenshot": "desktop" },
23+
{ "name": "ocr get value with coordinates", "function": "ocr_get_value_with_coordinates", "screenshot": "desktop" },
24+
{ "name": "ocr get value with image", "function": "ocr_get_value_with_image", "screenshot": "desktop" },
25+
{ "name": "ocr get value with text", "function": "ocr_get_value_with_text", "screenshot": "desktop" },
2226
) # yapf: disable
2327

2428
module_name = "desktop"

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 48 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,12 +1748,16 @@ def Keystroke_For_Element(data_set):
17481748
# Insert keystroke
17491749
try:
17501750
if stype == "keys":
1751-
# Requires: python-selenium v3.1+, geckodriver v0.15.0+
1752-
keystroke_value = keystroke_value.upper().replace("CTRL", "CONTROL")
1753-
if keystroke_value.startswith("ARROW"):
1754-
keystroke_value = keystroke_value[5:]
1755-
if keystroke_value.startswith("_"):
1756-
keystroke_value = keystroke_value[1:]
1751+
keystroke_value = keystroke_value.upper()
1752+
convert = {
1753+
"CTRL": "CONTROL",
1754+
"PLUS": "ADD",
1755+
"MINUS": "SUBTRACT",
1756+
"DASH": "SUBTRACT",
1757+
"CMD": "COMMAND",
1758+
}
1759+
for key in convert:
1760+
keystroke_value = keystroke_value.replace(key, convert[key])
17571761
if "+" in keystroke_value:
17581762
hotkey_list = keystroke_value.split("+")
17591763
for i in range(len(hotkey_list)):
@@ -2734,16 +2738,15 @@ def save_attribute_values_in_list(step_data):
27342738
right = right.strip()
27352739
if "target parameter" in mid:
27362740
target.append([[], [], [], []])
2737-
temp = right.strip(",").split('",\n')
2741+
temp = right.strip(",").split(',\n')
27382742
data = []
2739-
temp[-1] = temp[-1][:-1]
27402743
for each in temp:
2741-
data.append(each.strip().split("=",1))
2744+
data.append(each.strip().split("=", 1))
27422745
for i in range(len(data)):
27432746
for j in range(len(data[i])):
27442747
data[i][j] = data[i][j].strip()
27452748
if j == 1:
2746-
data[i][j] = data[i][j][1:] # dont add another strip here. dont need to strip inside quotation mark
2749+
data[i][j] = CommonUtil.strip1(data[i][j], '"') # dont add another strip here. dont need to strip inside quotation mark
27472750

27482751
for Left, Right in data:
27492752
if Left == "return":
@@ -3160,83 +3163,37 @@ def Sleep(step_data):
31603163
def Scroll(step_data):
31613164
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
31623165
global selenium_driver
3163-
selenium_driver.switch_to.default_content()
31643166
try:
3165-
scroll_inside_element = False
3166-
scroll_window_name = "window"
3167-
scroll_window = ""
3168-
action_row = None
3169-
3170-
for row in step_data:
3171-
if str(row[1]) == "action":
3172-
action_row = row
3173-
break
3174-
3175-
if not action_row:
3176-
CommonUtil.ExecLog(sModuleInfo, "No action row defined", 3)
3177-
return "zeuz_failed"
3178-
3179-
if (
3180-
len(step_data) > 1
3181-
): # element given scroll inside element, not on full window
3182-
scroll_inside_element = True
3183-
scroll_window_name = "arguments[0]"
3184-
3185-
if scroll_inside_element:
3186-
scroll_window = LocateElement.Get_Element(step_data, selenium_driver)
3187-
if scroll_window in failed_tag_list:
3188-
CommonUtil.ExecLog(
3189-
sModuleInfo,
3190-
"Element through which instructed to scroll not found",
3191-
3,
3192-
)
3193-
return "zeuz_failed"
3167+
Element = None
3168+
get_element = False
3169+
scroll_direction = ""
3170+
offset = ""
3171+
pixel = 750
3172+
for left, mid, right in step_data:
3173+
mid = mid.strip().lower()
3174+
if "action" in mid:
3175+
scroll_direction = right.strip().lower()
3176+
elif mid == "element parameter":
3177+
get_element = True
3178+
elif left.strip().lower() == "pixels":
3179+
pixel = int(right.strip().lower())
31943180

3195-
CommonUtil.ExecLog(
3196-
sModuleInfo,
3197-
"Element inside which instructed to scroll has been found. Scrolling thorugh it",
3198-
1,
3199-
)
3200-
else:
3201-
CommonUtil.ExecLog(sModuleInfo, "Scrolling through main window", 1)
3181+
if get_element:
3182+
Element = LocateElement.Get_Element(step_data, selenium_driver)
32023183

3203-
scroll_direction = str(action_row[2]).strip().lower()
32043184
if scroll_direction == "down":
3205-
CommonUtil.ExecLog(sModuleInfo, "Scrolling down", 1)
3206-
result = selenium_driver.execute_script(
3207-
"%s.scrollBy(0,750)" % scroll_window_name, scroll_window
3208-
)
3209-
time.sleep(2)
3210-
return "passed"
3185+
offset = f"0,{pixel}"
32113186
elif scroll_direction == "up":
3212-
CommonUtil.ExecLog(sModuleInfo, "Scrolling up", 1)
3213-
result = selenium_driver.execute_script(
3214-
"%s.scrollBy(0,-750)" % scroll_window_name, scroll_window
3215-
)
3216-
time.sleep(2)
3217-
return "passed"
3187+
offset = f"0,-{pixel}"
32183188
elif scroll_direction == "left":
3219-
CommonUtil.ExecLog(sModuleInfo, "Scrolling left", 1)
3220-
result = selenium_driver.execute_script(
3221-
"%s.scrollBy(-750,0)" % scroll_window_name, scroll_window
3222-
)
3223-
time.sleep(2)
3224-
return "passed"
3189+
offset = f"-{pixel},0"
32253190
elif scroll_direction == "right":
3226-
CommonUtil.ExecLog(sModuleInfo, "Scrolling right", 1)
3227-
result = selenium_driver.execute_script(
3228-
"%s.scrollBy(750,0)" % scroll_window_name, scroll_window
3229-
)
3230-
time.sleep(2)
3231-
return "passed"
3232-
else:
3233-
CommonUtil.ExecLog(
3234-
sModuleInfo,
3235-
"Value invalid. Only 'up', 'down', 'right' and 'left' allowed",
3236-
3,
3237-
)
3238-
result = "zeuz_failed"
3239-
return result
3191+
offset = f"{pixel},0"
3192+
3193+
CommonUtil.ExecLog(sModuleInfo, f"Scrolling {scroll_direction}", 1)
3194+
selenium_driver.execute_script(f"{'arguments[0]' if Element is not None else 'window'}.scrollBy({offset})")
3195+
time.sleep(2)
3196+
return "passed"
32403197

32413198
except Exception:
32423199
return CommonUtil.Exception_Handler(sys.exc_info())
@@ -3248,11 +3205,15 @@ def scroll_to_element(step_data):
32483205
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
32493206
global selenium_driver
32503207
use_js = False
3208+
additional_scroll = 0.1
32513209
try:
3252-
for row in step_data:
3210+
for left, mid, right in step_data:
3211+
left = left.lower().strip()
3212+
if "use js" == left:
3213+
use_js = right.strip().lower() in ("true", "yes", "1")
3214+
elif "additional scroll" == left:
3215+
additional_scroll = float(right.strip())
32533216

3254-
if "use js" in row[0].lower():
3255-
use_js = row[2].strip().lower() in ("true", "yes", "1")
32563217
scroll_element = LocateElement.Get_Element(step_data, selenium_driver)
32573218
if scroll_element in failed_tag_list:
32583219
CommonUtil.ExecLog(
@@ -3268,10 +3229,10 @@ def scroll_to_element(step_data):
32683229
if use_js:
32693230
selenium_driver.execute_script("arguments[0].scrollIntoView(true);", scroll_element)
32703231
else:
3271-
actions = ActionChains(selenium_driver)
3272-
3273-
actions.move_to_element(scroll_element)
3274-
actions.perform()
3232+
ActionChains(selenium_driver).move_to_element(scroll_element).perform()
3233+
3234+
if additional_scroll > 0:
3235+
selenium_driver.execute_script(f"window.scrollBy(0,{round(selenium_driver.get_window_size()['height']*additional_scroll)})")
32753236
return "passed"
32763237

32773238
except Exception:

Framework/MainDriverApi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ def run_all_test_steps_in_a_test_case(
525525
CommonUtil.current_step_name = current_step_name = all_step_info[StepSeq - 1]["step_name"]
526526
CommonUtil.current_step_id = current_step_id = all_step_info[StepSeq - 1]["step_id"]
527527
CommonUtil.current_step_sequence = current_step_sequence = all_step_info[StepSeq - 1]["step_sequence"]
528+
shared.Set_Shared_Variables("zeuz_current_step_name", current_step_name, print_variable=False, pretty=False)
529+
shared.Set_Shared_Variables("zeuz_current_step_sequence", current_step_sequence, print_variable=False, pretty=False)
530+
shared.Set_Shared_Variables("zeuz_total_step_count", len(all_step_info), print_variable=False, pretty=False)
528531

529532
shared.Set_Shared_Variables("zeuz_current_step", all_step_info[StepSeq - 1], print_variable=False, pretty=False)
530533

Framework/Utilities/CommonUtil.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ def Add_File_To_Current_Test_Case_Log(src):
344344
return Exception_Handler(sys.exc_info())
345345

346346

347+
def strip1(original_value: str, remove: str) -> str:
348+
if original_value.startswith(remove):
349+
original_value = original_value[len(remove):]
350+
if original_value.endswith(remove):
351+
original_value = original_value[:-len(remove)]
352+
return original_value
353+
354+
347355
def Exception_Handler(exec_info, temp_q=None, UserMessage=None):
348356
try:
349357
# console.print_exception(show_locals=True, max_frames=1)

requirements-linux.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ configobj
5555
jinja2
5656
pandas
5757
pyperclip
58+
thefuzz
5859
backports-datetime-fromisoformat; python_version < '3.11'

requirements-mac.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ configobj
5959
jinja2
6060
pandas
6161
pyperclip
62-
backports-datetime-fromisoformat; python_version < '3.11'
62+
backports-datetime-fromisoformat; python_version < '3.11'
63+
thefuzz

requirements-win.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@ configobj
6969
jinja2
7070
pandas
7171
pyperclip
72-
backports-datetime-fromisoformat; python_version < '3.11'
72+
backports-datetime-fromisoformat; python_version < '3.11'
73+
thefuzz

0 commit comments

Comments
 (0)