telenium
telenium copied to clipboard
TeleniumTestCase :: remotely (android device) run app :: Connected to another telenium server
Description
TeleniumTestCase refuses to communicate with app because get_token request returns None.
@classmethod
def start_process(cls):
...
# ensure the telenium we are connected are the same as the one we
# launched here
if cls.cli.get_token() != cls.telenium_token:
raise Exception("Connected to another telenium server")
In the start_android_process function, the TELENIUM_TOKEN is sent along with other environment variables (perhaps specified by the user) to the android device as a file (/sdcard/telenium_env.json) but this file is never read and therefor the environment variables are never set.
Unfortunately there doesn't seem to be a way to set these environment variables remotely with adb so TeleniumTestCase can't setup the environment before launching the app. We could make use of custom android system properties but this would affect people who have worked around the current situation already by adding code that sets environment variables via /sdcard/telenium_env.json. So it's probably best to stick with the current approach. That said, I believe telenium should be the one loading up these environment variables when the client is started. Although the user doesn't have to do much from a python perspective he'd still have to give the app the right permissions to access this file. So I am adding a bit of code in telenium_client.py.
PR on the way soon.
Various logs and file contents
main.py
import platform
import kivy
import telenium # Only use when app is launched on an android device
from kivy.app import App
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
class FretboardDojo(App):
def build(self):
root_layout = AnchorLayout(anchor_x="center", anchor_y="center")
widget_layout = BoxLayout(orientation="vertical", size_hint=(None, None))
widget_layout.add_widget(Label(text='Test App'))
widget_layout.add_widget(Label(text=f'Python {platform.python_version()}'))
widget_layout.add_widget(Label(text=f'Kivy {kivy.__version__}'))
root_layout.add_widget(widget_layout)
return root_layout
if __name__ == "__main__":
telenium.install() # Only use when app is launched on an android device
FretboardDojo().run()
buildozer.spec
[app]
title = Test App
package.name = testapp
package.domain = org.kivy
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
version = 0.1
requirements = python3,kivy,zipp,more-itertools,pytz,jaraco.functools,importlib-resources,tempora,six,jaraco.text,jaraco.classes,zc.lockfile,portend,MarkupSafe,jaraco.collections,cheroot,ws4py,Werkzeug,Mako,json-rpc,CherryPy,telenium
orientation = portrait
fullscreen = 0
android.permissions = INTERNET,ACCESS_NETWORK_STATE,READ_EXTERNAL_STORAGE
android.arch = armeabi-v7a
[buildozer]
log_level = 2
warn_on_root = 1
test.py
import os
from telenium.tests import TeleniumTestCase
# Only use when app is launched on an android device
os.environ['TELENIUM_HOST'] = '192.168.50.50'
os.environ['TELENIUM_TARGET'] = 'android'
os.environ['TELENIUM_ANDROID_PACKAGE'] = 'org.kivy.testapp'
class TestFretboardDojo(TeleniumTestCase):
def test_startup_screen(self):
self.assertExists("//Label[@text~=\"Test App\"]", timeout=2)
PyCharm Console Output
/home/pdallair/anaconda3/envs/telenium/bin/python /snap/pycharm-community/261/plugins/python-ce/helpers/pycharm/_jb_unittest_runner.py --path /home/pdallair/dev/PycharmProjects/Telenium/TestApp/test.py
Testing started at 9:40 p.m. ...
Launching unittests with arguments python -m unittest /home/pdallair/dev/PycharmProjects/Telenium/TestApp/test.py in /home/pdallair/dev/PycharmProjects/Telenium/TestApp
> app_quit: ()
Execute: ['adb', 'push', '/tmp/telenium_env.json', '/sdcard/telenium_env.json']
/tmp/telenium_env.json: 1 file pushed, 0 skipped. 0.5 MB/s (58 bytes in 0.000s)
Execute: ['adb', 'shell', 'am', 'start', '-n', 'org.kivy.testapp/org.kivy.android.PythonActivity', '-a', 'org.kivy.android.PythonActivity']
Starting: Intent { act=org.kivy.android.PythonActivity cmp=org.kivy.testapp/org.kivy.android.PythonActivity }
(None, None)
> ping: ()
> ping: ()
> get_token: ()
Failure
Traceback (most recent call last):
File "/home/pdallair/anaconda3/envs/telenium/lib/python3.9/unittest/suite.py", line 166, in _handleClassSetUp
setUpClass()
File "/home/pdallair/dev/PycharmProjects/Telenium/telenium/tests.py", line 120, in setUpClass
cls.start_process()
File "/home/pdallair/dev/PycharmProjects/Telenium/telenium/tests.py", line 81, in start_process
raise Exception("Connected to another telenium server")
Exception: Connected to another telenium server
Ran 0 tests in 8.076s
FAILED (errors=1)
Process finished with exit code 1