Code Monkey home page Code Monkey logo

Comments (2)

dtmilano avatar dtmilano commented on May 18, 2024

I would do something like this to simplify the use of the API as AndroidViewClient/culebra includes most of the cases:

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from com.dtmilano.android.viewclient import ViewClient


device, serialno = ViewClient.connectToDeviceOrExit()

kwargs2 = {'useuiautomatorhelper': True}
vc = ViewClient(device, serialno, **kwargs2)

for o in vc.uiAutomatorHelper.findObjects(by_selector='text@$[A-Z].*'):
    print(vc.uiAutomatorHelper.getText(o.oid))

This is a simple example based on your request.

Here, we use AndroidViewClient bindings. We request the backend to be CulebraTester2-public by passing {'uiautomatorhelper': True} to the constructor. Notice that the default backend is adb, therefore we need to specify we want uiautomatorhelper (a synonim for CulebraTester2-public) and have the service already running on the device or emulator.

Then, we invoke findObjects (see API) passing a selector text with a value starting with $ which is then interpreted as a regular expression.

We loop over the list of objects found and we invoke getText passing the specific object id.

I run it on an emulator with the Clock as the top Activity to obtain these results:

{'text': 'Alarm'}
{'text': 'Clock'}
{'text': 'Timer'}
{'text': 'Stopwatch'}
{'text': 'Thu, Nov 25'}

If AndroidViewClient does not satisfy your needs my second recommendation would be to use CulebraTester2-client which is the lower level API python client used by AndroidViewClient.

And there's more, if you need bindings for another language other than python you can generate the client from the openapi.yaml spec.

Hope this helps.
Feel free to follow up with more questions here or in Stackoverflow using tag androidviewclient.

Resources

from culebratester2-public.

bradmill avatar bradmill commented on May 18, 2024

Thanks, very helpful

from culebratester2-public.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.