Commit 21b4c4fd authored by Robert Poienar's avatar Robert Poienar

Merge remote-tracking branch 'origin/189-project-refactoring-altdriver-python'...

Merge remote-tracking branch 'origin/189-project-refactoring-altdriver-python' into 196-update-readme-with-correct-url-to-download-latest-unity-package
parents b22af4a2 819bc709
from .runner import AltElement, AltrunUnityDriver, PlayerPrefKeyType,By
from .altUnityExceptions import *
\ No newline at end of file
from altunityrunner.commands import *
from altunityrunner.altElement import AltElement
from altunityrunner.by import By
from altunityrunner.runner import *
from altunityrunner.player_pref_key_type import *
\ No newline at end of file
import json
from altunityrunner.commands.ObjectCommands.get_text import GetText
from altunityrunner.commands.ObjectCommands.set_component_property import SetComponentProperty
from altunityrunner.commands.ObjectCommands.get_component_property import GetComponentProperty
from altunityrunner.commands.ObjectCommands.tap import Tap
from altunityrunner.commands.ObjectCommands.call_component_method import CallComponentMethodForObject
from altunityrunner.commands.ObjectCommands.click_event import ClickEvent
from altunityrunner.commands.ObjectCommands.drag import Drag
from altunityrunner.commands.ObjectCommands.drop import Drop
from altunityrunner.commands.ObjectCommands.pointer_down import PointerDown
from altunityrunner.commands.ObjectCommands.pointer_enter import PointerEnter
from altunityrunner.commands.ObjectCommands.pointer_exit import PointerExit
from altunityrunner.commands.ObjectCommands.pointer_up import PointerUp
class AltElement(object):
def __init__(self, alt_unity_driver, appium_driver, json_data):
self.alt_unity_driver = alt_unity_driver
if (appium_driver != None):
self.appium_driver = appium_driver
data = json.loads(json_data)
self.name = str(data['name'])
self.id = str(data['id'])
self.x = str(data['x'])
self.y = str(data['y'])
self.z=str(data['z'])
self.mobileY = str(data['mobileY'])
self.type = str(data['type'])
self.enabled = str(data['enabled'])
self.worldX = str(data['worldX'])
self.worldY = str(data['worldY'])
self.worldZ = str(data['worldZ'])
self.idCamera=str(data['idCamera'])
def toJSON(self):
return '{"name":"' + self.name + '", \
"id":"' + self.id + '", \
"x":"' + self.x + '", \
"y":"' + self.y + '", \
"z":"'+self.z+'",\
"mobileY":"' + self.mobileY + '", \
"type":"' + self.type + '", \
"enabled":"' + self.enabled + '", \
"worldX":"' + self.worldX + '", \
"worldY":"' + self.worldY + '", \
"worldZ":"' + self.worldZ + '",\
"idCamera":"'+self.idCamera+'"}'
def get_component_property(self, component_name, property_name, assembly_name=''):
alt_object = self.toJSON()
return GetComponentProperty(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,component_name,property_name,assembly_name,alt_object).execute()
def set_component_property(self, component_name, property_name, value, assembly_name=''):
alt_object = self.toJSON()
return SetComponentProperty(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,component_name,property_name,value,assembly_name,alt_object).execute()
def call_component_method(self, component_name, method_name, parameters,assembly_name='',type_of_parameters=''):
alt_object = self.toJSON()
return CallComponentMethodForObject(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,component_name,method_name,parameters,assembly_name,type_of_parameters,alt_object).execute()
def get_text(self):
alt_object = self.toJSON()
return GetText(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def click_Event(self):
alt_object = self.toJSON()
return ClickEvent(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def mobile_tap(self, durationInSeconds=0.5):
self.appium_driver.tap([[float(self.x), float(self.mobileY)]], durationInSeconds * 1000)
def mobile_dragTo(self, end_x, end_y, durationIndSeconds=0.5):
self.appium_driver.swipe(self.x, self.mobileY, end_x, end_y, durationIndSeconds* 1000)
def mobile_dragToElement(self, other_element, durationIndSeconds=0.5):
self.appium_driver.swipe(self.x, self.mobileY, other_element.x, other_element.mobileY, durationIndSeconds* 1000)
def drag(self, x, y):
alt_object = self.toJSON()
return Drag(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,x,y,alt_object).execute()
def drop(self, x, y):
alt_object = self.toJSON()
return Drop(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,x,y,alt_object).execute()
def pointer_up(self):
alt_object = self.toJSON()
return PointerUp(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def pointer_down(self):
alt_object = self.toJSON()
return PointerDown(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def pointer_enter(self):
alt_object = self.toJSON()
return PointerEnter(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def pointer_exit(self):
alt_object = self.toJSON()
return PointerExit(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
def tap(self):
alt_object=self.toJSON()
return Tap(self.alt_unity_driver.socket,self.alt_unity_driver.requestSeparator,self.alt_unity_driver.requestEnd,alt_object).execute()
class By(object):
NAME=1
TAG=2
LAYER=3
COMPONENT=4
ID=5
PATH=6
\ No newline at end of file
from altunityrunner.commands.FindObjects.find_object_which_contains import *
from altunityrunner.commands.FindObjects.find_object import *
from altunityrunner.commands.FindObjects.find_objects import *
from altunityrunner.commands.FindObjects.find_objects_which_contains import *
from altunityrunner.commands.FindObjects.get_all_elements import *
from altunityrunner.commands.FindObjects.wait_for_object import *
from altunityrunner.commands.FindObjects.wait_for_object_to_not_be_present import *
from altunityrunner.commands.FindObjects.wait_for_object_which_contains import *
from altunityrunner.commands.FindObjects.wait_for_object_with_text import *
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.by import By
class FindObject(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,by,value,camera_name,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.enabled=enabled
def execute(self):
path=self.set_path(self.by,self.value)
if self.enabled==True:
if self.by==By.NAME:
data= self.send_data(self.create_command('findActiveObjectByName', self.value , self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findObject', path , self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findObject', path , self.camera_name ,'false'))
return self.get_alt_element(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.by import By
class FindObjectWhichContains(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,by,value,camera_name,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.enabled=enabled
def execute(self):
path=self.set_path_contains(self.by,self.value)
if self.enabled==True:
data = self.send_data(self.create_command('findObject', path , self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findObject', path , self.camera_name ,'false'))
return self.get_alt_element(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.by import By
class FindObjects(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,by,value,camera_name,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.enabled=enabled
def execute(self):
path=self.set_path(self.by,self.value)
if self.enabled==True:
data = self.send_data(self.create_command('findObjects', path , self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findObjects', path , self.camera_name ,'false'))
return self.get_alt_elements(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.by import By
class FindObjectsWhichContains(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,by,value,camera_name,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.enabled=enabled
def execute(self):
path=self.set_path_contains(self.by,self.value)
if self.enabled==True:
data = self.send_data(self.create_command('findObjects', path , self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findObjects', path , self.camera_name ,'false'))
return self.get_alt_elements(data)
\ No newline at end of file
from altunityrunner.commands.base_command import BaseCommand
class GetAllElements(BaseCommand):
def __init__(self, socket,requestSeparator,requestEnd,camera_name,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.camera_name=camera_name
self.enabled=enabled
def execute(self):
if enabled==True:
data = self.send_data(self.create_command('findAllObjects','//*', self.camera_name ,'true'))
else:
data = self.send_data(self.create_command('findAllObjects','//*', self.camera_name ,'false'))
return self.get_alt_elements(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.altUnityExceptions import WaitTimeOutException
import time
class WaitForObject(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, by,value,camera_name, timeout, interval,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.timeout=timeout
self.interval=interval
self.enabled=enabled
def execute(self):
t = 0
alt_element = None
while (t <= timeout):
try:
alt_element = self.find_object(by,value,camera_name,enabled)
break
except Exception:
print('Waiting for element ' + value + '...')
time.sleep(interval)
t += interval
if t>=timeout:
raise WaitTimeOutException('Element ' + value + ' not found after ' + str(timeout) + ' seconds')
return alt_element
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.altUnityExceptions import WaitTimeOutException
import time
class WaitForObjectToNotBePresent(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, by,value,camera_name, timeout, interval,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.timeout=timeout
self.interval=interval
self.enabled=enabled
def execute(self):
t = 0
while (t <= timeout):
try:
print('Waiting for element ' + value + ' to not be present...')
self.find_object(by,value,camera_name,enabled)
time.sleep(interval)
t += interval
except Exception:
break
if t>=timeout:
raise WaitTimeOutException('Element ' + value + ' still found after ' + str(timeout) + ' seconds')
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.altUnityExceptions import WaitTimeOutException
import time
class WaitForObjectWhichContains(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, by,value,camera_name, timeout, interval,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.camera_name=camera_name
self.timeout=timeout
self.interval=interval
self.enabled=enabled
def execute(self):
t = 0
alt_element = None
while (t <= timeout):
try:
alt_element = self.find_object_which_contains(by,value,camera_name,enabled)
break
except Exception:
print('Waiting for element where name contains ' + value + '...')
time.sleep(interval)
t += interval
if t>=timeout:
raise WaitTimeOutException('Element where name contains ' + value + ' not found after ' + str(timeout) + ' seconds')
return alt_element
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.altUnityExceptions import WaitTimeOutException
import time
class WaitForObjectWithText(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, by,value,text,camera_name, timeout, interval,enabled):
super().__init__(socket,requestSeparator,requestEnd)
self.by=by
self.value=value
self.text=text
self.camera_name=camera_name
self.timeout=timeout
self.interval=interval
self.enabled=enabled
def execute(self):
t = 0
alt_element = None
while (t <= timeout):
try:
alt_element=self.find_object(value,camera_name,enabled)
if alt_element.get_text() == text:
break
raise Exception('Not the wanted text')
except Exception:
print('Waiting for element ' + value + ' to have text ' + text)
time.sleep(interval)
t += interval
if t>=timeout:
raise WaitTimeOutException('Element ' + value + ' should have text `' + text + '` but has `' + alt_element.get_text() + '` after ' + str(timeout) + ' seconds')
return alt_element
\ No newline at end of file
from altunityrunner.commands.InputActions.click_at_coordinates import *
from altunityrunner.commands.InputActions.move_mouse_and_wait import *
from altunityrunner.commands.InputActions.move_mouse import *
from altunityrunner.commands.InputActions.press_key import *
from altunityrunner.commands.InputActions.press_key_and_wait import *
from altunityrunner.commands.InputActions.scroll_mouse import *
from altunityrunner.commands.InputActions.scroll_mouse_and_wait import *
from altunityrunner.commands.InputActions.swipe import *
from altunityrunner.commands.InputActions.swipe_and_wait import *
from altunityrunner.commands.InputActions.tilt import *
from altunityrunner.commands.InputActions.tap_at_coordinates import *
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
class ClickAtCoordinates(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, x, y):
super().__init__(socket,requestSeparator,requestEnd)
self.x=x
self.y=y
def execute(self):
data = self.send_data(self.create_command("clickScreenOnXY",self.x,self.y ))
print('Clicked at ' + str(self.x) + ', ' + str(self.y))
return data
from altunityrunner.commands.base_command import BaseCommand
class MoveMouse(BaseCommand):
def __init__(self, socket,requestSeparator,requestEnd, x, y, duration):
super().__init__(socket,requestSeparator,requestEnd)
self.x=x
self.y=y
self.duration=duration
def execute(self):
location = self.vector_to_json_string(self.x, self.y)
print ('Move mouse to: ' + location)
data = self.send_data(self.create_command('moveMouse', location, self.duration ))
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.commands.InputActions.move_mouse import MoveMouse
import time
class MoveMouseAndWait(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, x, y, duration):
super().__init__(socket,requestSeparator,requestEnd)
self.x=x
self.y=y
self.duration=duration
def execute(self):
data = MoveMouse(self.socket,self.requestSeparator,self.requestEnd,self.x, self.y, self.duration).execute()
self.handle_errors(data)
print('Wait for move mouse to finish')
time.sleep(self.duration)
action_in_progress = True
while action_in_progress:
action_finished = self.send_data(self.create_command('actionFinished'))
self.handle_errors(action_finished)
if action_finished is 'Yes':
break
elif action_finished != 'No':
action_in_progress = False
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
import time
class PressKey(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, keyName,power,duration):
super().__init__(socket,requestSeparator,requestEnd)
self.keyName=keyName
self.power=power
self.duration=duration
def execute(self):
print ('Press key: ' + self.keyName)
data = self.send_data(self.create_command('pressKeyboardKey',self.keyName,self.power, self.duration ))
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.commands.InputActions.press_key import PressKey
import time
class PressKeyAndWait(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, keyName,power,duration):
super().__init__(socket,requestSeparator,requestEnd)
self.keyName=keyName
self.power=power
self.duration=duration
def execute(self):
data = PressKey(self.socket,self.requestSeparator,self.requestEnd,self.keyName,self.power,self.duration).execute()
self.handle_errors(data)
print('Wait for press key to finish')
time.sleep(self.duration)
action_in_progress = True
while action_in_progress:
action_finished = self.send_data(self.create_command('actionFinished'))
self.handle_errors(action_finished)
if action_finished is 'Yes':
break
elif action_finished != 'No':
action_in_progress = False
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
import time
class ScrollMouse(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, speed, duration):
super().__init__(socket,requestSeparator,requestEnd)
self.speed=speed
self.duration=duration
def execute(self):
print ('Scroll mouse with: ' + str(self.speed))
data = self.send_data(self.create_command('scrollMouse', self.speed, self.duration ))
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.commands.InputActions.scroll_mouse import ScrollMouse
import time
class ScrollMouseAndWait(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd, speed, duration):
super().__init__(socket,requestSeparator,requestEnd)
self.speed=speed
self.duration=duration
def execute(self):
data = ScrollMouse(self.socket,self.requestSeparator,self.requestEnd,self.speed, self.duration).execute()
self.handle_errors(data)
print('Wait for scroll mouse to finish')
time.sleep(self.duration)
action_in_progress = True
while action_in_progress:
action_finished = self.send_data(self.create_command('actionFinished'))
self.handle_errors(action_finished)
if action_finished is 'Yes':
break
elif action_finished != 'No':
action_in_progress = False
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
class Swipe(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,x_start, y_start, x_end, y_end, duration_in_secs):
super().__init__(socket,requestSeparator,requestEnd)
self.x_start=x_start
self.y_start=y_start
self.x_end=x_end
self.y_end=y_end
self.duration_in_secs=duration_in_secs
def execute(self):
start_position = self.vector_to_json_string(self.x_start, self.y_start)
end_position = self.vector_to_json_string(self.x_end, self.y_end)
print('Swipe from ' + start_position + ' to ' + end_position + ' with duration: ' + str(self.duration_in_secs) + ' secs')
data = self.send_data(self.create_command('movingTouch', start_position , end_position , str(self.duration_in_secs) ))
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
from altunityrunner.commands.InputActions.swipe import Swipe
import time
class SwipeAndWait(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,x_start, y_start, x_end, y_end, duration_in_secs):
super().__init__(socket,requestSeparator,requestEnd)
self.x_start=x_start
self.y_start=y_start
self.x_end=x_end
self.y_end=y_end
self.duration_in_secs=duration_in_secs
def execute(self):
data = Swipe(self.socket,self.requestSeparator,self.requestEnd,self.x_start, self.y_start, self.x_end, self.y_end, self.duration_in_secs).execute()
self.handle_errors(data)
print('Wait for swipe to finish')
time.sleep(self.duration_in_secs)
swipe_in_progress = True
while swipe_in_progress:
swipe_finished = self.send_data(self.create_command('actionFinished'))
self.handle_errors(swipe_finished)
if swipe_finished is 'Yes':
break
elif swipe_finished != 'No':
swipe_in_progress = False
return self.handle_errors(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
class TapAtCoordinates(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,x,y):
super().__init__(socket,requestSeparator,requestEnd)
self.x=x
self.y=y
def execute(self):
data=self.send_data(self.create_command('tapScreen',self.x, self.y))
if 'error:notFound' in data:
return None
return self.get_alt_element(data)
\ No newline at end of file
from altunityrunner.commands.command_returning_alt_elements import CommandReturningAltElements
import time
class Tilt(CommandReturningAltElements):
def __init__(self, socket,requestSeparator,requestEnd,x, y, z):
super().__init__(socket,requestSeparator,requestEnd)
self.x=x
self.y=y
self.z=z