Skip to content

Commit 17487b4

Browse files
Merge pull request #444 from AutomationSolutionz/scroll
Scroll and save-attr-val-in-list
2 parents a1e6724 + 9145589 commit 17487b4

File tree

4 files changed

+40
-81
lines changed

4 files changed

+40
-81
lines changed

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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4062,16 +4062,15 @@ def save_attribute_values_appium(step_data):
40624062
right = right.strip()
40634063
if "target parameter" in mid:
40644064
target.append([[], [], [], []])
4065-
temp = right.strip(",").split('",\n')
4065+
temp = right.strip(",").split(',\n')
40664066
data = []
4067-
temp[-1] = temp[-1][:-1]
40684067
for each in temp:
4069-
data.append(each.strip().split("=",1))
4068+
data.append(each.strip().split("=", 1))
40704069
for i in range(len(data)):
40714070
for j in range(len(data[i])):
40724071
data[i][j] = data[i][j].strip()
40734072
if j == 1:
4074-
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
40754074

40764075
for Left, Right in data:
40774076
if Left == "return":

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 27 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,16 +2730,15 @@ def save_attribute_values_in_list(step_data):
27302730
right = right.strip()
27312731
if "target parameter" in mid:
27322732
target.append([[], [], [], []])
2733-
temp = right.strip(",").split('",\n')
2733+
temp = right.strip(",").split(',\n')
27342734
data = []
2735-
temp[-1] = temp[-1][:-1]
27362735
for each in temp:
2737-
data.append(each.strip().split("=",1))
2736+
data.append(each.strip().split("=", 1))
27382737
for i in range(len(data)):
27392738
for j in range(len(data[i])):
27402739
data[i][j] = data[i][j].strip()
27412740
if j == 1:
2742-
data[i][j] = data[i][j][1:] # dont add another strip here. dont need to strip inside quotation mark
2741+
data[i][j] = CommonUtil.strip1(data[i][j], '"') # dont add another strip here. dont need to strip inside quotation mark
27432742

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

3191-
CommonUtil.ExecLog(
3192-
sModuleInfo,
3193-
"Element inside which instructed to scroll has been found. Scrolling thorugh it",
3194-
1,
3195-
)
3196-
else:
3197-
CommonUtil.ExecLog(sModuleInfo, "Scrolling through main window", 1)
3173+
if get_element:
3174+
Element = LocateElement.Get_Element(step_data, selenium_driver)
31983175

3199-
scroll_direction = str(action_row[2]).strip().lower()
32003176
if scroll_direction == "down":
3201-
CommonUtil.ExecLog(sModuleInfo, "Scrolling down", 1)
3202-
result = selenium_driver.execute_script(
3203-
"%s.scrollBy(0,750)" % scroll_window_name, scroll_window
3204-
)
3205-
time.sleep(2)
3206-
return "passed"
3177+
offset = f"0,{pixel}"
32073178
elif scroll_direction == "up":
3208-
CommonUtil.ExecLog(sModuleInfo, "Scrolling up", 1)
3209-
result = selenium_driver.execute_script(
3210-
"%s.scrollBy(0,-750)" % scroll_window_name, scroll_window
3211-
)
3212-
time.sleep(2)
3213-
return "passed"
3179+
offset = f"0,-{pixel}"
32143180
elif scroll_direction == "left":
3215-
CommonUtil.ExecLog(sModuleInfo, "Scrolling left", 1)
3216-
result = selenium_driver.execute_script(
3217-
"%s.scrollBy(-750,0)" % scroll_window_name, scroll_window
3218-
)
3219-
time.sleep(2)
3220-
return "passed"
3181+
offset = f"-{pixel},0"
32213182
elif scroll_direction == "right":
3222-
CommonUtil.ExecLog(sModuleInfo, "Scrolling right", 1)
3223-
result = selenium_driver.execute_script(
3224-
"%s.scrollBy(750,0)" % scroll_window_name, scroll_window
3225-
)
3226-
time.sleep(2)
3227-
return "passed"
3228-
else:
3229-
CommonUtil.ExecLog(
3230-
sModuleInfo,
3231-
"Value invalid. Only 'up', 'down', 'right' and 'left' allowed",
3232-
3,
3233-
)
3234-
result = "zeuz_failed"
3235-
return result
3183+
offset = f"{pixel},0"
3184+
3185+
CommonUtil.ExecLog(sModuleInfo, f"Scrolling {scroll_direction}", 1)
3186+
selenium_driver.execute_script(f"{'arguments[0]' if Element is not None else 'window'}.scrollBy({offset})")
3187+
time.sleep(2)
3188+
return "passed"
32363189

32373190
except Exception:
32383191
return CommonUtil.Exception_Handler(sys.exc_info())

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)

0 commit comments

Comments
 (0)