简体   繁体   English

如何使用appium和python控制android设备?

[英]How to control android device using appium and python?

I am new to Appium . 我是Appium的新手 I want to control my android device via appium without sending any apk to phone. 我想通过appium控制我的android设备, 而不将任何apk发送到手机。 I have tried many examples but in each example everyone is pushing an apk and then controlling it using touches and keypress. 我已经尝试了许多示例,但是在每个示例中,每个人都在推送apk,然后使用触摸和按键对其进行控制。

I am not looking for an app testing instead I am looking for an android device testing using resorce id ,name,class or xpath. 我不是在寻找应用测试,而是在寻找使用resorce id,name,class或xpath的android设备测试。

And will the procedure remain same for ios also ? ios的程序也将保持不变吗?

Can anyone help me in writing a script in python ? 有人可以帮我用python编写脚本吗?

Not sure about appium, but AndroidViewClient/culebra can easily do what you want. 不确定appium,但AndroidViewClient / culebra可以轻松完成您想要的操作。

Install it, run culebra with or without GUI ( -G ) and you will be able to automatically generate python tests or plain scripts. 安装它,运行带有或不带有GUI( -G )的culebra ,您将能够自动生成python测试或纯脚本。

For example, if you run 例如,如果您运行

$ culebra -GuU --scale=0.5 -o chrome.py

while the device is on the home screen and click the Chrome icon to open it, this script will be generated 当设备位于主屏幕上并单击Chrome图标将其打开时,将生成此脚本

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018  Diego Torres Milano
Created on 2018-04-04 by Culebra v15.1.2
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import re
import sys
import os


import unittest

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase

TAG = 'CULEBRA'


class CulebraTests(CulebraTestCase):

    @classmethod
    def setUpClass(cls):
        cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
        cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
        cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'concertina-config': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'chrome.py', 'unit-test-method': None, 'interactive': False}
        cls.sleep = 5

    def setUp(self):
        super(CulebraTests, self).setUp()

    def tearDown(self):
        super(CulebraTests, self).tearDown()

    def preconditions(self):
        if not super(CulebraTests, self).preconditions():
            return False
        return True

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Chrome''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)


if __name__ == '__main__':
    CulebraTests.main()

then you can run it as 然后您可以将其运行为

$ ./chrome.py

to achieve the same at any time 随时达到相同的目的

I think the problem is like mine...want to control an android device or emulator with Appium, may be Mayank Shivhare already try to learn culebra and found the fact that....culebra is still not support by python 3 yet (same problem like me that prefer python 3.7 than python 2.7). 我认为问题就像我的...想要用Appium控制一个android设备或模拟器,可能是Mayank Shivhare已经尝试学习culebra并发现了一个事实.... culebra仍然不受python 3支持(相同像我这样的问题,更喜欢python 3.7而不是python 2.7)。

I have the same problem..., what I understood right now is: 我有同样的问题...,我现在了解的是:

  1. All environment should be set up first 应首先设置所有环境

  2. The emulator should be run first...before type any code 模拟器应首先运行...键入任何代码之前

  3. then run Appium to make a gateway with IP and port. 然后运行Appium创建具有IP和端口的网关。

  4. the missing link is how to connect an emulator to appium via ip and port that provide by appium server. 缺少的链接是如何通过appium服务器提供的ip和端口将仿真器连接到appium。

  5. I can detect the emulator element by run 'uiautomatorviewer.bat' from sdk\\tools\\bin folder, the problem is the problem in number 3, is how to send a command to the emulator via appium. 我可以通过从sdk\\tools\\bin文件夹中运行'uiautomatorviewer.bat'来检测仿真器元素,问题是第3个问题,即如何通过appium向仿真器发送命令。 so the command to control emulator base on data that given by 'uiautomatorviewer.bat' 因此,基于“ uiautomatorviewer.bat”给出的数据控制模拟器的命令

coding is about trial and error, so we need live interaction, to build source code. 编码是关于反复试验的,因此我们需要实时交互来构建源代码。 every developer has a personal interest in build a script or source code. 每个开发人员都有自己的兴趣来构建脚本或源代码。 so..to make easier, as beginner, we need live interaction that shows every error in every step our script or to make sure that every line of our script that we type is run smoothly in the android device or emulator. 因此,作为初学者,为了使操作更容易,我们需要实时交互,以显示脚本每个步骤中的每个错误,或者确保我们键入的脚本的每一行在android设备或仿真器中都能顺利运行。

The problem in learn appium is all manual already given finished script...without a really-really basic explanation...in my case, how to connect appium to emulator, send a command from python console, and see the script is work or not... 学习appium的问题是所有手册都已经给出了完成的脚本...没有真正真正的基本解释...就我而言,如何将appium连接到仿真器,如何从python控制台发送命令以及查看脚本是否正常运行或不...

what I mean is... we need the step by step explanation of script...because every beginner developers need a live 'trial and error' experience to understand how it works... 我的意思是...我们需要脚本的逐步说明...因为每个初学者开发人员都需要实时的“试错”经验来了解其工作原理...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python为Android设备运行appium测试时出现问题 - Problems running appium tests for an android device using python 如何使用Windows Machine将android设备与appium连接? - How to connect android device with appium using windows machine? 如何使用 appium 在 android 设备上关闭/终止应用程序? - How to close/kill an app on android device using appium? 如何使用Appium与Robot Framework滚动以在Android设备上测试应用程序 - How to scroll with Robot Framework using Appium to test an application at Android device 如何使用 python 控制你的 Android/iOS 设备? - How to control your Android/iOS device with python? 如何使用 Appium 和 Python 在 android 应用程序中滚动列表一次 - How to scroll list once in android application using Appium and Python 如何使用Appium在真实设备上更改时间? - How to change the time on a real device using Appium? 如何初始化appium webdriver与虚拟android设备的连接,而该虚拟android设备在Python中什么也不做? - How to initilaize connection of appium webdriver to a virtual android device that does nothing in Python? 如何处理 pdf 文件,同时使用 Appium 在 Android 设备中自动移动 web? - How to handle pdf file while automating Mobile web in Android device using Appium? 使用Appium自动化应用程序时如何处理android设备中的Toast生成? - How to handle toast generate in android device while automating an app using appium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM