Skip to content

Commit 2a836d0

Browse files
authored
Merge pull request #119 from AutomationSolutionz/appium_click_offset
click offset
2 parents 521e0cb + 6b9efb9 commit 2a836d0

File tree

2 files changed

+22
-79
lines changed

2 files changed

+22
-79
lines changed

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

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ def Click_Element_Appium(data_set):
19951995
Example:
19961996
below example will offset by 25% to the right off the center of the element. If we select 100% it will go to the right edge of the bound. If you want to go left prove -25.
19971997
1998-
x_offset:y_offset optional option 25:0
1998+
x_offset:y_offset optional parameter 25:0
19991999
20002000
"""
20012001

@@ -2011,62 +2011,39 @@ def Click_Element_Appium(data_set):
20112011
y_offset = False
20122012
offset = False
20132013

2014-
for row in data_set:
2015-
if (
2016-
"option" in str(row[1]).lower().strip()
2017-
and "x_offset:y_offset" in str(row[0]).lower().strip()
2018-
):
2014+
for left, mid, right in data_set:
2015+
left = left.lower().strip()
2016+
mid = mid.lower().strip()
2017+
if mid in ("option", "parameter") and "x_offset:y_offset" in left:
20192018
offset = True
2020-
x_offset = ((str(row[2]).lower().strip()).split(":")[0]).strip()
2021-
y_offset = ((str(row[2]).lower().strip()).split(":")[1]).strip()
2019+
x_offset, y_offset = [i.strip() for i in (right.strip()).split(":")]
20222020

20232021
Element = LocateElement.Get_Element(data_set, appium_driver)
20242022

20252023
if Element == "zeuz_failed":
2026-
2027-
CommonUtil.ExecLog(
2028-
sModuleInfo, "Unable to locate your element with given data.", 3
2029-
)
2024+
CommonUtil.ExecLog(sModuleInfo, "Unable to locate your element with given data.", 3)
20302025
CommonUtil.ExecLog(sModuleInfo, "Trying to see if there are contexts", 1)
20312026

20322027
context_result = auto_switch_context_and_try("webview")
20332028
if context_result == "zeuz_failed":
2034-
CommonUtil.ExecLog(
2035-
sModuleInfo,
2036-
"Unable to locate your element with different contexts.",
2037-
3,
2038-
)
2029+
CommonUtil.ExecLog(sModuleInfo, "Unable to locate your element with different contexts.", 3)
20392030
return "zeuz_failed"
20402031
else:
20412032
context_switched = True
20422033
Element = LocateElement.Get_Element(data_set, appium_driver)
20432034
if Element == "zeuz_failed":
2044-
CommonUtil.ExecLog(
2045-
sModuleInfo,
2046-
"Unable to locate your element with different contexts.",
2047-
3,
2048-
)
2035+
CommonUtil.ExecLog(sModuleInfo, "Unable to locate your element with different contexts.", 3)
20492036
if context_switched == True:
2050-
CommonUtil.ExecLog(
2051-
sModuleInfo,
2052-
"Context was switched during this action. Switching back to default Native Context",
2053-
1,
2054-
)
2037+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
20552038
context_result = auto_switch_context_and_try("native")
20562039
return "zeuz_failed"
20572040
else:
2058-
CommonUtil.ExecLog(
2059-
sModuleInfo, "Found your element with different context", 1
2060-
)
2041+
CommonUtil.ExecLog(sModuleInfo, "Found your element with different context", 1)
20612042

20622043
if Element.is_enabled():
20632044
if offset == True:
20642045
try:
2065-
CommonUtil.ExecLog(
2066-
sModuleInfo,
2067-
"Clicking the element based on offset with appium TouchAction.",
2068-
1,
2069-
)
2046+
CommonUtil.ExecLog(sModuleInfo, "Clicking the element based on offset with appium TouchAction.", 1)
20702047
start_loc = Element.location
20712048
height_width = Element.size
20722049
start_x = int((start_loc)["x"])
@@ -2084,32 +2061,18 @@ def Click_Element_Appium(data_set):
20842061
x_cord_to_tap = center_x + total_x_offset
20852062
y_cord_to_tap = center_y + total_y_offset
20862063
TouchAction(appium_driver).tap(None, x_cord_to_tap, y_cord_to_tap, 1).perform()
2087-
CommonUtil.ExecLog(
2088-
sModuleInfo, "Tapped on element by offset successfully", 1
2089-
)
2064+
CommonUtil.ExecLog(sModuleInfo, "Tapped on element by offset successfully", 1)
20902065
if context_switched == True:
2091-
CommonUtil.ExecLog(
2092-
sModuleInfo,
2093-
"Context was switched during this action. Switching back to default Native Context",
2094-
1,
2095-
)
2066+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context",1)
20962067
context_result = auto_switch_context_and_try("native")
20972068

20982069
return "passed"
20992070

21002071
except:
21012072
# CommonUtil.TakeScreenShot(sModuleInfo)
2102-
CommonUtil.ExecLog(
2103-
sModuleInfo,
2104-
"Element is enabled. Unable to tap based on offset.",
2105-
3,
2106-
)
2073+
CommonUtil.ExecLog(sModuleInfo, "Element is enabled. Unable to tap based on offset.", 3)
21072074
if context_switched == True:
2108-
CommonUtil.ExecLog(
2109-
sModuleInfo,
2110-
"Context was switched during this action. Switching back to default Native Context",
2111-
1,
2112-
)
2075+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
21132076
context_result = auto_switch_context_and_try("native")
21142077

21152078
return "zeuz_failed"
@@ -2118,51 +2081,31 @@ def Click_Element_Appium(data_set):
21182081
try:
21192082
Element.click()
21202083
# CommonUtil.TakeScreenShot(sModuleInfo)
2121-
CommonUtil.ExecLog(
2122-
sModuleInfo,
2123-
"Successfully clicked the element with given parameters and values",
2124-
1,
2125-
)
2084+
CommonUtil.ExecLog(sModuleInfo, "Successfully clicked the element with given parameters and values", 1)
21262085
if context_switched == True:
2127-
CommonUtil.ExecLog(
2128-
sModuleInfo,
2129-
"Context was switched during this action. Switching back to default Native Context",
2130-
1,
2131-
)
2086+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
21322087
context_result = auto_switch_context_and_try("native")
21332088
return "passed"
21342089

21352090
except Exception:
21362091
errMsg = "Could not select/click your element."
21372092

21382093
if context_switched == True:
2139-
CommonUtil.ExecLog(
2140-
sModuleInfo,
2141-
"Context was switched during this action. Switching back to default Native Context",
2142-
1,
2143-
)
2094+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
21442095
context_result = auto_switch_context_and_try("native")
21452096
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
21462097

21472098
else:
21482099
# CommonUtil.TakeScreenShot(sModuleInfo)
21492100
CommonUtil.ExecLog(sModuleInfo, "Element not enabled. Unable to click.", 3)
21502101
if context_switched == True:
2151-
CommonUtil.ExecLog(
2152-
sModuleInfo,
2153-
"Context was switched during this action. Switching back to default Native Context",
2154-
1,
2155-
)
2102+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
21562103
context_result = auto_switch_context_and_try("native")
21572104
return "zeuz_failed"
21582105

21592106
except Exception:
21602107
if context_switched == True:
2161-
CommonUtil.ExecLog(
2162-
sModuleInfo,
2163-
"Context was switched during this action. Switching back to default Native Context",
2164-
1,
2165-
)
2108+
CommonUtil.ExecLog(sModuleInfo, "Context was switched during this action. Switching back to default Native Context", 1)
21662109
context_result = auto_switch_context_and_try("native")
21672110
errMsg = "Could not find/click your element."
21682111
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)

Framework/Built_In_Automation/Shared_Resources/LocateElement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def Get_Element(step_data_set, driver, query_debug=False, return_all_elements=Fa
137137
else:
138138
CommonUtil.ExecLog(sModuleInfo, "Use '%| |%' sign to get variable value", 3)
139139
return "zeuz_failed"
140-
elif row[1].strip().lower() == "option":
140+
elif row[1].strip().lower() in ("option", "parameter"):
141141
left = row[0].strip().lower()
142142
right = row[2].strip().lower()
143143
if left in ("allow hidden", "allow disable"):

0 commit comments

Comments
 (0)