Appium Appium python 框架

woyebuzhidaowoshishei · 2015年10月12日 · 最后由 剑玄 回复于 2020年01月07日 · 20601 次阅读
本帖已被设为精华帖!

希望给点意见和建议,毕竟周围没有人可以交流。。。

前言

嘿嘿,第一次发帖有点小激动。
接触 appium 也有一个多月了,自己根据以前做 selenium 的经验(其实只有一年不到!!!)搭建了框架,希望大家给点意见啊!!!毕竟我身边没有可以和我交流的!!!万分感谢

流程

1.打开 appium server
2.获取当前手机的 device Name 和 安卓版本号,打开 driver
3.运行 case
4.生成报告
5.关闭 driver
6.关闭 appium server

结构

具体说说 run.py

整个程序是从这个模块开始运行的,也是花了我最长时间的地方。下面上代码

# ========================================================
# Summary        :run
# Author         :tong shan
# Create Date    :2015-10-09
# Amend History  :
# Amended by     :
# ========================================================

import readConfig
readConfigLocal = readConfig.ReadConfig()
import unittest
from testSet.common.DRIVER import myDriver
import testSet.common.Log as Log
import os
from time import sleep

from selenium.common.exceptions import WebDriverException
import threading

mylock = threading.RLock()
log = Log.myLog.getLog()

# ========================================================
# Summary        :myServer
# Author         :tong shan
# Create Date    :2015-10-10
# Amend History  :
# Amended by     :
# ========================================================
class myServer(threading.Thread):

    def __init__(self):
        global appiumPath
        threading.Thread.__init__(self)
        self.appiumPath = readConfigLocal.getConfigValue("appiumPath")

    def run(self):

        log.outputLogFile("start appium server")
        rootDirectory = self.appiumPath[:2]
        startCMD = "node node_modules\\appium\\bin\\appium.js"

        #cd root directory ;cd appiuu path; start server
        os.system(rootDirectory+"&"+"cd "+self.appiumPath+"&"+startCMD)

# ========================================================
# Summary        :Alltest
# Author         :tong shan
# Create Date    :2015-10-10
# Amend History  :
# Amended by     :
# ========================================================
class Alltest(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        global casePath, caseListLpath, caseList, suiteList, appiumPath
        self.caseListPath = readConfig.logDir+"\\caseList.txt"
        self.casePath = readConfig.logDir+"\\testSet\\"
        self.caseList = []
        self.suiteList = []
        self.appiumPath = readConfigLocal.getConfigValue("appiumPath")

# =================================================================
# Function Name   : driverOn
# Function        : open the driver
# Input Parameters: -
# Return Value    : -
# =================================================================
    def driverOn(self):
        myDriver.GetDriver()

# =================================================================
# Function Name   : driverOff
# Function        : colse the driver
# Input Parameters: -
# Return Value    : -
# =================================================================
    def driverOff(self):
        myDriver.GetDriver().quit()

# =================================================================
# Function Name   : setCaseList
# Function        : read caseList.txt and set caseList
# Input Parameters: -
# Return Value    : -
# =================================================================
    def setCaseList(self):

        print(self.caseListPath)

        fp = open(self.caseListPath)

        for data in fp.readlines():

            sData = str(data)
            if sData != '' and not sData.startswith("#"):
                self.caseList.append(sData)

# =================================================================
# Function Name   : createSuite
# Function        : get testCase in caseList
# Input Parameters: -
# Return Value    : testSuite
# =================================================================
    def createSuite(self):

        self.setCaseList()
        testSuite = unittest.TestSuite()

        if len(self.caseList) > 0:

            for caseName in self.caseList:

                discover = unittest.defaultTestLoader.discover(self.casePath, pattern=caseName+'.py', top_level_dir=None)
                self.suiteList.append(discover)

        if len(self.suiteList) > 0:

            for test_suite in self.suiteList:
                for casename in test_suite:
                    testSuite.addTest(casename)
        else:
            return None

        return testSuite

# =================================================================
# Function Name   : runTest
# Function        : run test
# Input Parameters: -
# Return Value    : -
# =================================================================
    def run(self):

        try:


            while not isStartServer():
                mylock.acquire()
                sleep(1)
                log.outputLogFile("wait 1s to start appium server")
                mylock.release()
            else:
                log.outputLogFile("start appium server success")
                suit = self.createSuite()
                if suit != None:

                    log.outputLogFile("open Driver")
                    self.driverOn()
                    log.outputLogFile("Start to test")
                    unittest.TextTestRunner(verbosity=2).run(suit)
                    log.outputLogFile("end to test")
                    log.outputLogFile("close to Driver")
                    self.driverOff()

                else:
                    log.outputLogFile("Have no test to run")
        except Exception as ex:
            log.outputError(myDriver.GetDriver(), str(ex))

def isStartServer():

    try:
        driver = myDriver.GetDriver()
        if driver == None:
            return False
        else:
            return True
    except WebDriverException:
        raise


if __name__ == '__main__':

    thread1 = myServer()
    thread2 = Alltest()

    thread2.start()
    thread1.start()

    while thread2.is_alive():
        sleep(10)#"allTest is alive,sleep10"
    else:
        #kill myServer
        os.system('taskkill /f /im node.exe')
        log.outputLogFile("stop appium server")

思路

刚接触的时候发现每次都要手动打开 appium 服务,然后再运行代码,想着是不是太麻烦了?就想试着可不可做成一步?
这一想,就费了我好多功夫。
1.打开 appium server
开始的时候,连如何用命令行打开服务都不会,在群里问了一圈(感谢回答问题的大大们!!!),然后自己又琢磨了一下,搞定了,可是!!!用 os.system(),居然阻塞进程,最后还是问了群里的大大解决(再次感谢!!!!)。
2.如何判断 server 是否被成功开启
这个问题我想了很久,现在我解决了,但是解决方法我不太满意,希望有大大可以给我一个好点的方法或者思路(跪谢!!)
目前做法:判断是否可以返回一个正常的 driver 对象

def isStartServer():

    try:
        driver = myDriver.GetDriver()
        if driver == None:
            return False
        else:
            return True
    except WebDriverException:
        raise

3.关闭 appium server
目前的做法是强制杀死,还是不太满意,不知道以后会不会有什么不可预见的问题,希望有大大可以给我一个好点的方法或者思路(跪谢!!)

if __name__ == '__main__':

    thread1 = myServer()
    thread2 = Alltest()

    thread2.start()
    thread1.start()

    while thread2.is_alive():
        sleep(10)#"allTest is alive,sleep10"
    else:
        #kill myServer
        os.system('taskkill /f /im node.exe')
        log.outputLogFile("stop appium server")

其他模块

1.common.py 共同方法,主要指封装了一些方法,供其他模块使用。
2.DRIVER.py 获取 driver,这里是做成了一个单例模式,run.py 中打开,关闭,其他模块调用。
3.Log.py 中有 2 个类 log 和 myLog,同样也把 myLog 做成了一个单例模式
4.myPhone.py 主要使用了 adb 命令来识别和获取手机参数
5.readConfig.py 是读取配置文件

有点遗憾的地方

1.目前异常机制还不够完善,也怪我学艺不精
2.线程是先学的,线程安全之类也没有考虑,目前做到的仅仅是可以用了
3.测试数据参数化还没有实现(这个还要再研究)
4.重要的话说 3 遍:没有人交流!!!
没有人交流!!!
没有人交流!!!
希望大家在看完后,多多题意见

最后附上源码地址:https://github.com/tongshan1/appium_python

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 110 条回复 时间 点赞

鼓掌

在第 2 点中,判断 appium 是否开启,我使用的是 http get 这个 url: http://127.0.0.1:4723/wd/hub/status ,可以获取到 appium 的状态,如果在执行中,还可以得到正在执行的手机的 udid 等信息。

第 3 点钟,杀进程没关系,不放心可以在案例的最后 delete session。

#2 楼 @among29 谢谢回复,我会试试的。

@tongshanshanshan testerhome 欢迎你。

先点赞!

结构很 nice~~学习了

#2 楼 @among29

第一点根据你提供的方法我写出来了

def isStartServer():

    response = None
    url = baseUrl+"/status"
    try:
        response = urllib.request.urlopen(url, timeout=5)

        if str(response.getcode()).startswith("2"):
            print(response.getcode())
            return True
        else:
            return False
    except URLError:
        return False
    finally:
        if response:
            response.close()

第二点

我发现在 case 执行结束后有这么一句 log
info: <-- DELETE /wd/hub/session/ebfae3a8-b604-47c1-bb58-17cf02b28b57 200 977.879 ms - 76 {"status":0,"value":null,"sessionId":"ebfae3a8-b604-47c1-bb58-17cf02b28b57"}
是不是意味着我不需要在 delete session 了呢?

先 github star 一下再说

appium 初学者,想问一下,在安装 appium 除了错误: 请问如何破解
C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\ws\node_modules\bufferutil\build\b inding.sln : error MSB3411: 未能加载 Visual C++ 组件 “VCBuild.exe”。如果未安装该组件,请执行下列操作之一: 1) 安
装 Microsoft Windows SDK fo
r Windows Server 2008 和 .NET Framework 3.5;或 2) 安装 Microsoft Visual Studio 2008。

很好的框架,也是我想要找到和学习的东西,新人学艺不精,先收藏,慢慢学习!

#11 楼 @wusuowei
请安装 VC++ 运行包或者 VS 2010 以上版本,应该可以解决。

#9 楼 @tongshanshanshan 判断返回值是不是 200,是一种方式,返回的 json 数据里面有 status 等字段,也可以判断。
正常情况下,driver 的 close_app ,quit 方法也会 delete session,不用手动操作。

赞一个!

这么短时间能做到这个程度很不错了,框架的层次基本已经出来了。

下面是一些个人的建议:

  1. 既然分层了,那就尽量不要把所有执行相关的文件都放到 run.py 里面,按照层次分离成不同的文件。这样更清晰,也方便未来扩展(我估计很快你就需要扩展各个层次的内容了,各层次的功能不是很够用)
  2. appium server wrapper 这方面你可以参考下 cosyman 以前发过的帖子。他写的比较全。server 建议用进程做。
  3. 不是很理解为何要设计成运行测试和 server 要做成两个 thread 。个人觉得应该 server 是一个 process ,wrapper 提供 start 和 stop 方法,然后框架就直接 run 就好了。 run 完后调用 wrapper 的 stop 就没问题了,没啥必要做个轮询不断地检查 run 完没。
  4. 其实 appium server 还是比较稳定的,不至于会经常挂掉,所以个人觉得没太大必要在测试框架里总是去打开/关闭它,把它当 service ,启动后一直运行就好了。

接下来是个人代码洁癖给出的吐槽,不想打击你,但忍不住要吐下槽:

  1. 一处 open file 后不 close 。建议如果没办法记得去 close 的话用 with open(path, mode) as f 来打开文件。
  2. 代码风格有点偏 Java(主要是注释的使用),建议你看下 python-client 的源码和 Google 的 Python 风格规范,代码风格和主流贴近一点,这样便于让别人阅读你的代码,进而和你合作。
  3. 从代码来看你的两个线程之间没什么资源共享,应该不需要搞线程锁什么的。不过我对线程也不是十分熟悉,你还是先看下相关资料再决定吧。
  4. 路径建议用 os.path.join ,不要把路径分隔符 hard code 进去。
  5. log 的方法名越短越好,最好 log.d, log.i 之类的就好了。另外, python 有现成的 logging 模块,功能强大,没太大必要自己实现个 Log 模块。

#16 楼 @chenhengjie123 恒洁有架构师的风范啊

#16 楼 @chenhengjie123 十分感谢,我会努力改善的!!

一样,我也是来这里看下大家有什么好的想法,不过我们用的 java,因为感觉 testNG 用的还挺爽,就用的飞起了,哈哈。其实感觉可以把所有控件做成单一一个文件之类的也是不错的方法

#16 楼 @chenhengjie123 @tongshanshanshan 嗯,恒洁架构师风范啊。
appium server 确实就用线程做是比较好的了。
然后线程锁的话你能实现出来肯定是最好的,有用的地方还是有的。
场景总会遇到,比如:
短时间内的并发,用线程锁去处理端口、设备号的分配更加安全。
不然用 get http status 的方式的话,中间总会有启动 Appium 或其他方面的耗时,导致端口冲突的问题。

#20 楼 @darker50 好的,我会试试的。谢谢你的意见

#21 楼 @anikikun 谢谢你的意见,我会试试的。

#17 楼 @lihuazhang
#18 楼 @monkey
#21 楼 @anikikun
我那只是代码洁癖,和架构师还有很大差距。。。现在深入了解过架构的程序还不够多,很多想法还很 native 。。。

#19 楼 @tongshanshanshan 继续加油!以后多点过来 Testerhome 交流, sharing codes show cool

hi 大师 ,我碰到了一个问题,可否给些意见?我用的 app 是混合型 app,web 开发通过 angular js,当用 appium 的时候找不到 pop
view 的元素,如截图中弹出来的 pick a doctor 界面上的元素 cancel 就是找不到。 这个是要怎么解决呢?。server log 如下:
Tests-MacBook-Pro-2:python testuser$ python /Users/testuser/Desktop/Appium\ Example/sample-code/sample-code/examples/python/android_AuroraMakeappointment.py
test_webview (main.AndroidWebViewTests) ... info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4","appPackage":"com.covidien.rpm","app":"/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk","platformName":"Android","deviceName":"SM-T331C"}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: /Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk
info: [debug] Creating new appium session e2cefc8e-48a5-488c-ac58-d24da9e8d744
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.7.0_79
info: [debug] Checking whether adb is present
info: [debug] Using adb from /users/testuser/Library/Android/sdk/platform-tools/adb
info: [debug] Parsing package and activity from app manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from /users/testuser/Library/Android/sdk/build-tools/22.0.1/aapt
info: [debug] Extracting package and launch activity from manifest.
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/build-tools/22.0.1/aapt dump badging "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk"
info: [debug] badging package: com.covidien.rpm
info: [debug] badging act: com.covidien.rpm.activity.MainWebActivity
info: [debug] Parsed package and activity are: com.covidien.rpm/com.covidien.rpm.activity.MainWebActivity
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb devices
info: [debug] 1 device(s) connected
info: Found device a4aa956805cd2952
info: [debug] Setting device id to a4aa956805cd2952
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 wait-for-device
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: Device API level is: 19
info: [debug] Extracting strings for language: default
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "getprop persist.sys.language"
info: [debug] Current device persist.sys.language: en
info: [debug] java -jar "/usr/local/lib/node_modules/appium/node_modules/appium-adb/jars/appium_apk_tools.jar" "stringsFromApk" "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk" "/tmp/com.covidien.rpm" en
info: [debug] No strings.xml for language 'en', getting default strings.xml
info: [debug] java -jar "/usr/local/lib/node_modules/appium/node_modules/appium-adb/jars/appium_apk_tools.jar" "stringsFromApk" "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk" "/tmp/com.covidien.rpm"
info: [debug] Reading strings from converted strings.json
info: [debug] Setting language to default
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 push "/tmp/com.covidien.rpm/strings.json" /data/local/tmp
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from /users/testuser/Library/Android/sdk/build-tools/22.0.1/aapt
info: [debug] Retrieving process from manifest.
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/build-tools/22.0.1/aapt dump xmltree "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk" AndroidManifest.xml
info: [debug] Set app process to: com.covidien.rpm
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Checking app cert for /Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk.
info: [debug] executing cmd: java -jar /usr/local/lib/node_modules/appium/node_modules/appium-adb/jars/verify.jar "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk"
info: [debug] App already signed.
info: [debug] Zip-aligning /Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from /users/testuser/Library/Android/sdk/build-tools/22.0.1/zipalign
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/build-tools/22.0.1/zipalign -f 4 "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk" /var/folders/7p/vc6l_9b12rl7f6k4xrx44wxm0000gn/T/115914-9413-fsi6k8/appium.tmp
info: [debug] MD5 for app is ac0eb8b8d4482d7c3b6d5a7feb3db4ed
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "ls /data/local/tmp/ac0eb8b8d4482d7c3b6d5a7feb3db4ed.apk"
info: [debug] Getting install status for com.covidien.rpm
info: [debug] Getting device API level
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "pm list packages -3 com.covidien.rpm"
info: [debug] App is installed
info: Installing App
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "mkdir -p /data/local/tmp/"
info: [debug] Removing any old apks
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "ls /data/local/tmp/*.apk"
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell rm "/data/local/tmp/29649242b53e9a67ba855b067422713c.apk"
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 push "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk" /data/local/tmp/ac0eb8b8d4482d7c3b6d5a7feb3db4ed.apk
info: [debug] Uninstalling com.covidien.rpm
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "am force-stop com.covidien.rpm"
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 uninstall com.covidien.rpm
info: [debug] App was uninstalled
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "pm install -r /data/local/tmp/ac0eb8b8d4482d7c3b6d5a7feb3db4ed.apk"
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 push "/usr/local/lib/node_modules/appium/build/android_bootstrap/AppiumBootstrap.jar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 install "/usr/local/lib/node_modules/appium/build/settings_apk/settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 install "/usr/local/lib/node_modules/appium/build/unlock_apk/unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.covidien.rpm -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: wake
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"\/data\/local\/tmp","status":0}
info: [debug] dataDir set to: /data/local/tmp
info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
info: [debug] Getting device API level
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.covidien.rpm/com.covidien.rpm.activity.MainWebActivity"
info: [debug] Waiting for pkg "com.covidien.rpm" and activity "com.covidien.rpm.activity.MainWebActivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "dumpsys window windows"
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "getprop ro.build.version.release"
info: [debug] Device is at release version 4.4.2
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId e2cefc8e-48a5-488c-ac58-d24da9e8d744
info: <-- POST /wd/hub/session 303 22694.460 ms - 74
info: --> GET /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744 {}
info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"4.4","appPackage":"com.covidien.rpm","app":"/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk","platformName":"Android","deviceName":"SM-T331C"},"appPackage":"com.covidien.rpm","app":"/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk","platformName":"Android","deviceName":"a4aa956805cd2952"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- GET /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744 200 1.369 ms - 697 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"4.4","appPackage":"com.covidien.rpm","app":"/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk","platformName":"Android","deviceName":"SM-T331C"},"appPackage":"com.covidien.rpm","app":"/Users/testuser/Desktop/Appium Example/sample-code/sample-code/apps/Aurora.apk","platformName":"Android","deviceName":"a4aa956805cd2952"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/elements {"using":"class name","sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","value":"android.widget.EditText"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"class name","selector":"android.widget.EditText","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"class name","selector":"android.widget.EditText","context":"","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding android.widget.EditText using CLASS_NAME with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.EditText]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.EditText]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[CLASS=android.widget.EditText, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[CLASS=android.widget.EditText, INSTANCE=1]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (2)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[CLASS=android.widget.EditText, INSTANCE=2]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[{"ELEMENT":"1"},{"ELEMENT":"2"}],"status":0}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"}],"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/elements 200 184.366 ms - 105 {"status":0,"value":[{"ELEMENT":"1"},{"ELEMENT":"2"}],"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/1/value {"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","id":"1","value":["j","i","n","g","j","i","n","g"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"1","text":"jingjing","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"1","text":"jingjing","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Using element passed in.
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: jingjing
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/1/value 200 6958.115 ms - 76 {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/2/value {"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","id":"2","value":["1","2","3","4","5","6"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"2","text":"123456","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"2","text":"123456","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Using element passed in.
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: 123456
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/2/value 200 4677.353 ms - 76 {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element {"using":"name","sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","value":"Login"}
warn: [DEPRECATED] The name locator strategy has been deprecated and will be removed. Please use the accessibility id locator strategy instead.
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"Login","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"Login","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding Login using NAME with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Login, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"3"},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"3"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element 200 51.049 ms - 87 {"status":0,"value":{"ELEMENT":"3"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/3/click {"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","id":"3"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"3"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"3"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/3/click 200 128.167 ms - 76 {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element {"using":"name","sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","value":"Make New Appointment"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"Make New Appointment","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"Make New Appointment","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding Make New Appointment using NAME with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Make New Appointment, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"4"},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"4"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element 200 101.800 ms - 87 {"status":0,"value":{"ELEMENT":"4"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/4/click {"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","id":"4"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"4"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element/4/click 200 641.900 ms - 76 {"status":0,"value":true,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: --> POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element {"using":"name","sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744","value":"Cancel"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"name","selector":"Cancel","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"Cancel","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding Cancel using NAME with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Cancel, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=Cancel, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
info: [debug] [BOOTSTRAP] [debug] Finding Cancel using NAME with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Cancel, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=Cancel, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"No element found","status":7}
info: [debug] Condition unmet after 1119ms. Timing out.
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"No element found"},"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- POST /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744/element 500 1123.018 ms - 195
ERROR
info: --> DELETE /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744 {}
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: /users/testuser/Library/Android/sdk/platform-tools/adb -s a4aa956805cd2952 shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 27.235
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}
info: <-- DELETE /wd/hub/session/e2cefc8e-48a5-488c-ac58-d24da9e8d744 200 1131.054 ms - 76 {"status":0,"value":null,"sessionId":"e2cefc8e-48a5-488c-ac58-d24da9e8d744"}

ERROR: test_webview (main.AndroidWebViewTests)

Traceback (most recent call last):
File "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/examples/python/android_AuroraMakeappointment.py", line 43, in test_webview
button2=self.driver.find_element_by_name('Cancel')
File "/Library/Python/2.7/site-packages/selenium-2.47.3-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 330, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "/Library/Python/2.7/site-packages/selenium-2.47.3-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "/Library/Python/2.7/site-packages/selenium-2.47.3-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/Users/testuser/Desktop/Appium Example/sample-code/sample-code/examples/python/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
截图在附近

#26 楼 @dujingjing1_1
1.大师我不敢当啊,我也是刚接触不久。
2.我看了一下 log,你是根据 find_element(by=By.NAME, value=name) 来寻找的,有没有尝试过 xpath 之类的?弹出框的话,找之前是不是要 switch_to_alert()一下呢?
3.其他的话我也想不到其他原因了,毕竟我也接触不久。不知道可不可帮到你。

这个弹出框的元素没有办法用 appium 定位,所以没有 xpath。这个弹出框是 modal view 的 ,

31楼 已删除
32楼 已删除

很棒。向你学习。

我在使用的时候报以下错误,请教一下是咋回事,感觉是没获取到 case,但是不知道咋改

est01 (unittest.loader._FailedTest) ... ERROR

======================================================================
ERROR: test01 (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test01
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\unittest\loader.py", line 428, in _find_test_path
    module = self._get_module_from_name(name)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\lib\unittest\loader.py", line 369, in _get_module_from_name
    __import__(name)

#34 楼 @yuweixx 贴下代码呢,是不是你的路径没有配对?

#35 楼 @tongshanshanshan
config.ini

appiumPath =C:\Program Files\nodejs\node_modules\appium
platformName=Android
appPackage=com.w.m
appActivity=.welcome
baseUrl=http://127.0.0.1:4723/wd/hub
findElementTimes=10

run.py

def __init__(self):
    global casePath, caseListLpath, caseList, suiteList, appiumPath,log,logger
    self.caseListPath = os.path.join(readConfig.prjDir, "caseList.txt")
    self.casePath = os.path.join(readConfig.prjDir, "testSet\\")
    self.caseList = []
    self.suiteList = []
    self.appiumPath = readConfigLocal.getConfigValue("appiumPath")
    self.myServer = AppiumServer()
def createSuite(self):
        """from the caseList,get caseName,According to the caseName to search the testSuite
        :return:testSuite
        """
        self.setCaseList()
        testSuite = unittest.TestSuite()

        if len(self.caseList) > 0:

            for caseName in self.caseList:

                discover = unittest.defaultTestLoader.discover(start_dir=self.casePath, pattern=caseName+'.py', top_level_dir=None)
                self.suiteList.append(discover)

文件存放的位置应该没有问题,case 放在 testSet 下,caseList 在上一级 testApp 下
以上的这些涉及到 case 路径的我也没动过。
注:我的系统是 win10.

#36 楼 @yuweixx 我加你 qq 看下?

#37 楼 @tongshanshanshan 492497451,但公司上不了 QQ。你的 github 最近还会更新吗?方便剧透一下吗?

#38 楼 @yuweixx 这几个月都会更新的

这里锁没必要 rlock,直接 lock 即可,没用在线程里面继续锁资源的需求

希望越做越好!

@tongshanshanshan 你好楼主,方便发下 QQ 吗 加一下你 有几个问题

我把配置改了之后 还是提示报错。

这是我 QQ 加一下 281599519 最近公司在搞移动端自动化 希望帮帮忙

@tongshanshanshan 学习了,能不能在 github 上获取学习一哈 😄

#47 楼 @spanthrive 帖子上有附 github 地址

可以帮我安装下 APPium 安卓自动化测试环境吗

—— 来自 TesterHome 官方 安卓客户端

这个项目可以运行吗,为什么放在我的环境中运行报错啊

运行时,报错
/usr/bin/python /Users/haozhen/PycharmProjects/dudutest/duTestSet/run.py
Traceback (most recent call last):
File "/Users/haozhen/PycharmProjects/dudutest/duTestSet/run.py", line 9, in
from duTestSet.common.DRIVER import MyDriver
ImportError: No module named duTestSet.common.DRIVER

Process finished with exit code 1

#51 楼 @dudubaby 你仔细查看一下路径是否有问题。

#52 楼 @tongshanshanshan 已经 ok 了,是 python 版本的问题,之前用的 python2.7 然后不支持这种目录引用,后来换成 python3.4 就 ok 了,但还有其他问题,可否加下你 QQ 请教一下

#53 楼 @dudubaby 可以再群里搜我。。。

#54 楼 @tongshanshanshan 什么群哪个群,我没加群啊

你的文件里面没有 phone.py 可以发一下完整的代码吗,谢谢大神。我是初学者

#56 楼 @mymgbaby 我删了,代码移到 init.py 里面了。

58楼 已删除

#3 楼 @tongshanshanshan 为啥我直接下载你的代码运行是这样的

#59 楼 @mymgbaby 看英文,英文不好,还是别学编程了。

#59 楼 @mymgbaby 缺模块,安装模块

#61 楼 @mymgbaby 这个错误无关紧要

#60 楼 @lihuazhang 我确实有这个模块啊

我只直接下载他的代码,直接调试的

#62 楼 @lihuazhang
他这个是导入自定义的模块,

#64 楼 @mymgbaby common 目录下新建一个init.py 文件。。这种问题与测试无关,你上网百度呗

#64 楼 @mymgbaby common 是不是 package?

#65 楼 @neyo common 下面本来就有 init.py 文件

#66 楼 @lihuazhang common 是文件夹

#67 楼 @mymgbaby 那个是外层的吧,你在 common 文件内新建一个试试

#68 楼 @mymgbaby 文件名起错了啊亲..你看看我怎么打的

#70 楼 @neyo 你仔细看一下啊,内层也有一个的额

#71 楼 @mymgbaby common 文件夹下面没有init.py 吧。。

#73 楼 @mymgbaby 不好意思。。我打的被 markdown 加粗了😢,你看 demo1.py 上面那个文件名。。

#74 楼 @neyo 嗯嗯,没事。

#75 楼 @mymgbaby 这样 ok 了吗?

#76 楼 @neyo 我的目录结构一直就是这样啊,就是报错找不到模块额。。。

#74 楼 @neyo
#75 楼 @mymgbaby common 是一个文件夹,里面的 init.py 是我添加的,目的是在运行 case 之前识别手机,获取手机信息,testSet 是一个 package,在创建 package 的时候会自动创建init.py。2 个是不同的,一个是系统自动创建的,一个是我自己建的。不知道我说明白来没有。还有啊,不是把代码拷贝下来就是直接能运行,里面还有一些配置是需要自己配置的。

楼主你好,我想问下就是你放在 testcase 的 excel 里面放的是测试用例代码是吧,然后在需要做测试的时候传到代码里是这个思路吧,比如 login 的测试用例,是什么时候传呢,比如我选择了账号框在 send_keys( "") 这里传测试用例吗
,不好意思可能你觉的问题很低级,但我没接触过这块,以前都是把用例写在代码里,但这样显的代码太长了太重复了,也想像你学习

楼主已疯

#79 楼 @enumerate 不是,在测试开始的读取测试用例,将测试用例作为参数传入带测试的 case。具体你可以看看 demo2.py

#78 楼 @tongshanshanshan 嗯。。我看她这边缺文件,想她是不是误删了,所以让她加一下

#79 楼 @enumerate 没懂你问的啥,不过浅陋的说几句,你在前台比如说一个网站上编写好用例,并把用例的数据(用例名,用例定位方式,以及元素的值,断言啥的)存在数据库,点击调试,再把用例 id 传给你封装好的一些类,在后台进行以下操作:通过 id 查找该用例的具体信息,在去定位每个步骤的元素,最后再执行一些动作,比如点击,输入之类的。

#78 楼 @tongshanshanshan 哪些配置啊?能针对我这个问题说一下吗

#82 楼 @neyo 我没删他的代码额,就是他的源代码

#84 楼 @mymgbaby 你现在还有什么问题?

#86 楼 @tongshanshanshan 一直就是那个问题啊
找不到导入的模块

#85 楼 @mymgbaby 你和楼主讨论吧。。我撤了= =

#87 楼 @mymgbaby 编译通过没?

#88 楼 @neyo 还是很谢谢你,试着帮我解决问题。

#89 楼 @tongshanshanshan 编译也是说找不到模块

#81 楼 @tongshanshanshan 好的谢谢楼主,我周六日要狂看 demo2,嘿嘿

#83 楼 @mymgbaby 好的多谢,我学习下楼主的 demo2,然后在结合你说的自己搞一下,多谢回答

#94 楼 @tongshanshanshan 直接在代码里面加?加了也没用啊

#93 楼 @enumerate 你直接运行这个代码没问题吗?还是做了什么配置的?

在你的 init.py 中。运行该文件,print startServer,得到的是
这个是不是有问题

#95 楼 @mymgbaby 哎。。加 qq 聊吧。

#98 楼 @tongshanshanshan 你只能通过 email 添加额,你的 email 是?

把 github 上的源码下载到本地试运行了一下,报错 “No module named readConfig”,楼主知不知道是哪里出了问题呀?

woyebuzhidaowoshishei [该话题已被删除] 中提及了此贴 06月30日 16:56

新手学习了

woyebuzhidaowoshishei Appium+python 框架 (二) 中提及了此贴 12月01日 14:04

楼主,我是初来学习的。看到你写的框架,赞。
能分享一下你的源码吗,非常感谢。

楼主,源码地址失效了,可以再提供下吗?另外我运行 appium 的时候报错 “error:Failed to start an Appium session,err was:Error:Waited 20 secs fro selendroid server and it never showed up"
app 一启动马上就关闭了,有遇到过吗?

老马 python appium UI 自动化测试框架讨论 中提及了此贴 02月01日 10:48

先点赞,楼主你的 github 用不了,想看下你的源码。

仅楼主可见

楼主,你 github 访问不了了

@tongshanshanshan 你的 github 访问不了了,正在学习 appium,想看下源码。

@tongshanshanshan git 地址失效了,麻烦给个~~~😀

星痕 python+selenium UI 自动化测试 中提及了此贴 09月01日 05:00

地址失效了,想看下源码,跪求~

地址失效了 想看下 yuan ma r

求源码,有没有下了源码的大大分享一下

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册