Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plugin(self):
def _my_plugin(d, k):
def _inner():
return k
return _inner
u2.plugin_clear()
u2.plugin_register('my', _my_plugin, 'pp')
self.assertEqual(self.d.ext_my(), 'pp')
self._clear = cnf.get('clear')
self._steps = cnf.get('steps')
self._watchers = cnf.get('watchers', [])
self._udid = cnf.get('udid')
self._plugins = cnf.get('plugins', {})
d = self._d = u2.connect(self._udid)
self.session = None
# plugins
if 'ocr' in self._plugins:
logger.info("load plugin: ocr")
import uiautomator2.ext.ocr as ocr
ocr.API = self._plugins['ocr']
logger.info("Use ocr plugin: %s", ocr.API)
u2.plugin_register('ocr', ocr.OCR)
if self._pkg_name and 'perf' in self._plugins:
logger.info("load plugin: perf")
import uiautomator2.ext.perf as perf
u2.plugin_register('perf', perf.Perf, self._pkg_name)
perfcnf = self._plugins['perf']
d.ext_perf.interval = perfcnf.get('interval', 1.0)
d.ext_perf.debug = perfcnf.get('debug', True)
d.ext_perf.csv_output = perfcnf.get('filename', 'perf.csv')
plt.ylabel('CPU')
plt.gca().xaxis.set_major_formatter(ticker.NullFormatter())
plt.subplot(3, 1, 3)
plt.plot(data['time'], data['fps'], '-')
plt.ylabel('FPS')
plt.ylim(0, 60)
plt.xlabel('Time')
plt.savefig(os.path.join(target_dir, "summary.png"))
if __name__ == '__main__':
import uiautomator2 as u2
pkgname = "com.tencent.tmgp.sgame"
# pkgname = "com.netease.cloudmusic"
u2.plugin_register('perf', Perf, pkgname)
d = u2.connect()
print(d.app_current())
# print(d.ext_perf.netstat(5350))
# d.app_start(pkgname)
d.ext_perf.start()
d.ext_perf.debug = True
try:
time.sleep(500)
except KeyboardInterrupt:
d.ext_perf.stop()
d.ext_perf.csv2images()
print("threading stopped")
self._plugins = cnf.get('plugins', {})
d = self._d = u2.connect(self._udid)
self.session = None
# plugins
if 'ocr' in self._plugins:
logger.info("load plugin: ocr")
import uiautomator2.ext.ocr as ocr
ocr.API = self._plugins['ocr']
logger.info("Use ocr plugin: %s", ocr.API)
u2.plugin_register('ocr', ocr.OCR)
if self._pkg_name and 'perf' in self._plugins:
logger.info("load plugin: perf")
import uiautomator2.ext.perf as perf
u2.plugin_register('perf', perf.Perf, self._pkg_name)
perfcnf = self._plugins['perf']
d.ext_perf.interval = perfcnf.get('interval', 1.0)
d.ext_perf.debug = perfcnf.get('debug', True)
d.ext_perf.csv_output = perfcnf.get('filename', 'perf.csv')