@@ -93,16 +93,26 @@ class UiAutomatorHelper:
9393 TEST_CLASS = PACKAGE + '.test'
9494 TEST_RUNNER = 'com.dtmilano.android.uiautomatorhelper.UiAutomatorHelperTestRunner'
9595
96- def __init__ (self , adbclient , adb = None , localport = 9987 , remoteport = 9987 , hostname = 'localhost' ):
96+ def __init__ (self , adbclient , adb = None , localport = 9987 , remoteport = 9987 , hostname = 'localhost' , api_version = 'v2' ):
97+ """
98+ UiAutomatorHelper constructor used when the backend selected is **CulebraTester2-public**.
99+ This class holds references to the different API's:
100+ - Device
101+ - TargetContext
102+ - ObjectStore
103+ - UiDevice
104+ - UiObject2
105+ - Until
106+
107+ :param adbclient: the adb client
108+ :param adb: adb if known
109+ :param localport: the local port used in CulebraTester2-public port forwarding
110+ :param remoteport: the remote port used in CulebraTester2-public port forwarding
111+ :param hostname: the hostname used by CulebraTester2-public
112+ :param api_version: the api version
113+ """
97114 self .adbClient = adbclient
98115 ''' The adb client (a.k.a. device) '''
99- # instrumentation = self.adbClient.shell('pm list instrumentation %s' % self.PACKAGE)
100- # if not instrumentation:
101- # raise RuntimeError('The target device does not contain the instrumentation for %s' % self.PACKAGE)
102- # if not re.match('instrumentation:%s/%s \(target=%s\)' % (self.TEST_CLASS, self.TEST_RUNNER, self.PACKAGE),
103- # instrumentation):
104- # raise RuntimeError('The instrumentation found for %s does not match the expected %s/%s' % (
105- # self.PACKAGE, self.TEST_CLASS, self.TEST_RUNNER))
106116 self .adb = self .__whichAdb (adb )
107117 ''' The adb command '''
108118 self .osName = platform .system ()
@@ -111,18 +121,11 @@ def __init__(self, adbclient, adb=None, localport=9987, remoteport=9987, hostnam
111121 ''' Is it Mac OSX? '''
112122 self .hostname = hostname
113123 ''' The hostname we are connecting to. '''
114- # if hostname in ['localhost', '127.0.0.1']:
115- # self.__redirectPort(localport, remoteport)
116- # self.__runTests()
117- # self.baseUrl = 'http://%s:%d' % (hostname, localport)
118- # try:
119- # self.session = self.__connectSession()
120- # except RuntimeError as ex:
121- # self.thread.forceStop()
122- # raise ex
123- print ('⚠️ CulebraTester2 server should have been started and port redirected.' , file = sys .stderr )
124- # TODO: localport should be in ApiClient configuration
125- self .api_instance = culebratester_client .DefaultApi (culebratester_client .ApiClient ())
124+
125+ print (f'⚠️ CulebraTester2 server should have been started and localport { localport } redirected to remote port { remoteport } .' , file = sys .stderr )
126+ configuration = culebratester_client .Configuration ()
127+ configuration .host = f'http://{ hostname } :{ localport } /{ api_version } '
128+ self .api_instance = culebratester_client .DefaultApi (culebratester_client .ApiClient (configuration ))
126129 self .device : UiAutomatorHelper .Device = UiAutomatorHelper .Device (self )
127130 self .target_context : UiAutomatorHelper .TargetContext = UiAutomatorHelper .TargetContext (self )
128131 self .object_store : UiAutomatorHelper .ObjectStore = UiAutomatorHelper .ObjectStore (self )
0 commit comments