@@ -4393,16 +4393,14 @@ def auto_switch_context_and_try(native_web):
43934393 )
43944394 return "zeuz_failed"
43954395
4396+
43964397@logger
43974398def swipe_appium (data_set ):
43984399 """
4399- To auto scroll to an element which is scrollable, won't work if no scrollable element is present
44004400 """
4401- scrollable_element = None
4402- global generic_driver
4403- generic_driver = appium_driver
4401+ global appium_driver
44044402 sModuleInfo = inspect .currentframe ().f_code .co_name + " : " + MODULE_NAME
4405- scrollable_element = LocateElement .Get_Element (data_set ,appium_driver )
4403+ scrollable_element = LocateElement .Get_Element (data_set , appium_driver )
44064404 if scrollable_element == None :
44074405 CommonUtil .ExecLog (sModuleInfo , "Scrollable element is not found" , 3 )
44084406 return "zeuz_failed"
@@ -4495,57 +4493,52 @@ def swipe_appium(data_set):
44954493 "Calculated Coordinate: (%s,%s) to (%s,%s)" % (x1 , y1 , x2 , y2 ), 1 )
44964494 i = 0
44974495 while i < max_try :
4498- generic_driver .swipe (x1 , y1 , x2 , y2 , duration * 1000 ) # duration seconds to milliseconds
4496+ appium_driver .swipe (x1 , y1 , x2 , y2 , duration * 1000 ) # duration seconds to milliseconds
44994497 i = i + 1
45004498 return "passed"
45014499
45024500 except Exception :
45034501 CommonUtil .Exception_Handler (sys .exc_info (), None , "Error could not scroll the element" )
45044502 return "zeuz_failed"
45054503
4504+
45064505@logger
45074506def scroll_to_element (data_set ):
45084507 """
4509- To auto scroll to an element which is scrollable, won't work if no scrollable element is present
4508+ Currently this is the main scroll_to_element function
45104509 """
4511- scrollable_element = None
4512- global generic_driver
4513- generic_driver = appium_driver
45144510 sModuleInfo = inspect .currentframe ().f_code .co_name + " : " + MODULE_NAME
4515- scroll_dataset = []
45164511
4517- for left , mid , right in data_set :
4518- left = left . strip (). lower ()
4519- mid = mid . strip (). lower ()
4520- right = right . replace ( "%" , "" ). replace ( " " , "" )
4521- if mid == 'element parameter' :
4522- scroll_dataset .append ((left , 'element parameter' , right ))
4512+ try :
4513+ global appium_driver
4514+ scroll_dataset = []
4515+ for left , mid , right in data_set :
4516+ if not mid . strip (). lower (). startswith ( "desired" ) :
4517+ scroll_dataset .append ((left , mid , right ))
45234518
4524- scrollable_element = LocateElement .Get_Element (scroll_dataset ,appium_driver )
4525- if scrollable_element == None :
4526- CommonUtil .ExecLog (sModuleInfo , "Scrollable element is not found" , 3 )
4527- return "zeuz_failed"
4528- desired_dataset = []
4529- Element = None
4530- inset = 0.1
4531- position = 0.5
4532- height = scrollable_element .size ["height" ]
4533- width = scrollable_element .size ["width" ]
4534- xstart_location = scrollable_element .location ["x" ] # Starting location of the x-coordinate of scrollable element
4535- ystart_location = scrollable_element .location ["y" ] # Starting location of the y-coordinate of scrollable element
4536- max_try = 10
4537- direction = "up" if height > width else "left"
4538- swipe_speed = None
4519+ scrollable_element = LocateElement .Get_Element (scroll_dataset , appium_driver )
4520+ if scrollable_element == "zeuz_failed" :
4521+ CommonUtil .ExecLog (sModuleInfo , "Scrollable element is not found" , 3 )
4522+ return "zeuz_failed"
4523+ desired_dataset = []
4524+ inset = 0.1
4525+ position = 0.5
4526+ height = scrollable_element .size ["height" ]
4527+ width = scrollable_element .size ["width" ]
4528+ xstart_location = scrollable_element .location ["x" ] # Starting location of the x-coordinate of scrollable element
4529+ ystart_location = scrollable_element .location ["y" ] # Starting location of the y-coordinate of scrollable element
4530+ max_try = 10
4531+ direction = "up" if height > width else "left"
4532+ swipe_speed = None
45394533
4540- try :
45414534 for left , mid , right in data_set :
4542- left = left .strip ().lower ()
45434535 mid = mid .strip ().lower ()
4544- right = right .replace ("%" , "" ).replace (" " , "" )
45454536 if mid .startswith ("desired" ):
4546- desired_dataset .append ((left , 'element parameter' , right ))
4537+ desired_dataset .append ((left , mid [ 8 :]. strip (). lower () , right ))
45474538
45484539 if "scroll parameter" in mid :
4540+ right = right .replace ("%" , "" ).replace (" " , "" )
4541+ left = left .strip ().lower ()
45494542 if left == "direction" and right in ("up" , "down" , "left" , "right" ):
45504543 direction = right
45514544 elif left == "swipe speed" :
@@ -4556,77 +4549,76 @@ def scroll_to_element(data_set):
45564549 position = float (right ) / 100.0
45574550 elif left == "max try" :
45584551 max_try = float (right )
4559- except :
4560- CommonUtil .Exception_Handler (sys .exc_info (), None , "Unable to parse data. Please write data in correct format" )
4561- return "zeuz_failed"
45624552
4563- if direction == "up" :
4564- tmp = 1.0 - inset
4565- new_height = round (tmp * height )
4566- new_width = round (position * width )
4567- x1 = xstart_location + new_width
4568- x2 = x1
4569- y1 = ystart_location + new_height - 1
4570- y2 = ystart_location
4571- if swipe_speed is None :
4572- duration = new_height * 0.0032
4573- else :
4574- duration = new_height * swipe_speed
4575- elif direction == "down" :
4576- tmp = 1.0 - inset
4577- new_height = round (tmp * height )
4578- new_width = round (position * width )
4579- x1 = xstart_location + new_width
4580- x2 = x1
4581- y1 = ystart_location + 1
4582- y2 = ystart_location + new_height
4583- if swipe_speed is None :
4584- duration = new_height * 0.0032
4585- else :
4586- duration = new_height * swipe_speed
4587- elif direction == "left" :
4588- tmp = 1.0 - inset
4589- new_width = round (tmp * width )
4590- new_height = round (position * height )
4591- x1 = xstart_location + new_width - 1
4592- x2 = xstart_location
4593- y1 = ystart_location + new_height
4594- y2 = y1
4595- if swipe_speed is None :
4596- duration = new_width * 0.0032
4597- else :
4598- duration = new_width * swipe_speed
4599- elif direction == "right" :
4600- tmp = 1.0 - inset
4601- new_width = round (tmp * width )
4602- new_height = round (position * height )
4603- x1 = xstart_location + 1
4604- x2 = xstart_location + new_width
4605- y1 = ystart_location + new_height
4606- y2 = y1
4607- if swipe_speed is None :
4608- duration = new_width * 0.0032
4553+ if direction == "up" :
4554+ tmp = 1.0 - inset
4555+ new_height = round (tmp * height )
4556+ new_width = round (position * width )
4557+ x1 = xstart_location + new_width
4558+ x2 = x1
4559+ y1 = ystart_location + new_height - 1
4560+ y2 = ystart_location
4561+ if swipe_speed is None :
4562+ duration = new_height * 0.0032
4563+ else :
4564+ duration = new_height * swipe_speed
4565+ elif direction == "down" :
4566+ tmp = 1.0 - inset
4567+ new_height = round (tmp * height )
4568+ new_width = round (position * width )
4569+ x1 = xstart_location + new_width
4570+ x2 = x1
4571+ y1 = ystart_location + 1
4572+ y2 = ystart_location + new_height
4573+ if swipe_speed is None :
4574+ duration = new_height * 0.0032
4575+ else :
4576+ duration = new_height * swipe_speed
4577+ elif direction == "left" :
4578+ tmp = 1.0 - inset
4579+ new_width = round (tmp * width )
4580+ new_height = round (position * height )
4581+ x1 = xstart_location + new_width - 1
4582+ x2 = xstart_location
4583+ y1 = ystart_location + new_height
4584+ y2 = y1
4585+ if swipe_speed is None :
4586+ duration = new_width * 0.0032
4587+ else :
4588+ duration = new_width * swipe_speed
4589+ elif direction == "right" :
4590+ tmp = 1.0 - inset
4591+ new_width = round (tmp * width )
4592+ new_height = round (position * height )
4593+ x1 = xstart_location + 1
4594+ x2 = xstart_location + new_width
4595+ y1 = ystart_location + new_height
4596+ y2 = y1
4597+ if swipe_speed is None :
4598+ duration = new_width * 0.0032
4599+ else :
4600+ duration = new_width * swipe_speed
46094601 else :
4610- duration = new_width * swipe_speed
4611- else :
4612- CommonUtil . ExecLog ( sModuleInfo , "Direction should be among up, down, right or left" , 3 )
4613- return "zeuz_failed"
4602+ CommonUtil . ExecLog ( sModuleInfo , "Direction should be among up, down, right or left" , 3 )
4603+ return "zeuz_failed"
4604+ except :
4605+ return CommonUtil . Exception_Handler ( sys . exc_info (), None , "Unable to parse data. Please write data in correct format" )
46144606
46154607 try :
46164608 CommonUtil .ExecLog (sModuleInfo , "Scrolling with the following scroll parameter:\n " +
46174609 "Max_try: %s, Direction: %s, Duration: %s, Inset: %s, Position:%s\n " % (max_try , direction , duration , inset * 100 , position * 100 ) +
46184610 "Calculated Coordinate: (%s,%s) to (%s,%s)" % (x1 , y1 , x2 , y2 ), 1 )
46194611 i = 0
46204612 while i < max_try :
4621- Element = LocateElement .Get_Element (desired_dataset , appium_driver )
4622- if Element != ( 'zeuz_failed' or None ) :
4623- CommonUtil .ExecLog (sModuleInfo ,"Scrolled to desired element succesfully ." ,1 )
4613+ Element = LocateElement .Get_Element (desired_dataset , appium_driver , element_wait = 1.5 )
4614+ if Element != 'zeuz_failed' :
4615+ CommonUtil .ExecLog (sModuleInfo , "Scrolled to the desired element successfully ." , 1 )
46244616 return "passed"
4625- generic_driver .swipe (x1 , y1 , x2 , y2 , duration * 1000 ) # duration seconds to milliseconds
4617+ appium_driver .swipe (x1 , y1 , x2 , y2 , duration * 1000 ) # duration seconds to milliseconds
46264618 i = i + 1
4627- CommonUtil .ExecLog (sModuleInfo , "Scrolled %d times.Couldn't find the element." % max_try , 3 )
4619+ CommonUtil .ExecLog (sModuleInfo , "Scrolled %d times.Couldn't find the element." % max_try , 3 )
46284620 return "zeuz_failed"
46294621
46304622 except Exception :
4631- CommonUtil .Exception_Handler (sys .exc_info (), None , "Error could not scroll the element" )
4632- return "zeuz_failed"
4623+ return CommonUtil .Exception_Handler (sys .exc_info (), None , "Error could not scroll the element" )
4624+
0 commit comments