Git Product home page Git Product logo

problem-solution's People

Watchers

 avatar

problem-solution's Issues

【github】文件夹中有灰色不可点击状态的处理方法

原因是文件夹中包含其它仓库,所以要删除其中的.git文件
[code]git rm -r --cached some-directory
git commit -m "Remove the now ignored directory some-directory"
git push -u origin master

最好是删除文件夹后重新创建一个文件夹

【Appium】怎么在app中查找viewdriver的元素

Appium测试hybirdapp,在webView中处理方法
在native调用webview的时候,在对应的webview页,应用self.driver.switch_to.context(“WEBVIEW”)将driver跳转到webview中,然后就可以和在网页中操作一样进行脚本编写了,下面说一下如何找到webview中的element
1、 HybirdApp中webView元素如何查看(Appium)
1.1 Andriod

准备工作:
chrome47.0以上版本
翻墙软件
手机打开开发者模式下的通过usb调试与电脑相连
工作步骤:
打开chrome
输入chrome://inspect/#devices
再打开的页面中勾选 discover USB devices
在对应列表中选择测试网络即可(过程需要翻墙)

1.2 IOS
准备工作:

  • mac笔记本
  • apple手机在设置中找到safari,进入后在最后面选择高级,然后打开web检查器后一电脑相连
  • 打开mac笔记本的Safari的对应菜单下就可以操作手机上的webview了
    Appium的一点一滴:Appium测试hybirdapp,在webView中处理方法

【Linux】linux常用命令

Linux

常用命令:

  1. cat: 文本输出命令, 通常是用来观看某个文件的内容的;
    cat主要有三个功能:
    1). 一次显示整个文件
    $cat filename

2). 从磁盘创建一个文件
$cat > filename
只能创建新文件, 不能编辑已有的文件

3). 将几个文件合并为一个文件
$cat file1 file2 > filename

cat具体命令格式为: cat [-AbeEnstTuv] [--help] [--version] fileName

  1. more: 功能类似cat,cat命令是整个文件夹的内容从上到下显示在屏幕上,more会以一页一页的显示方式方便使用者逐页阅读, 而最基本的指令就是按space键就往下一页显示, 按b键(back)就会往回一页显示,而且还有搜索字符串的功能。 more命令从前向后读取文件,因此在启动时就加载整个文件

more 具体命令格式为:more [-d1fpcsu] [-num] [+/ pattern] [+ linenum] [file...]
命令参数
+n 从第N行开始显示
-n 定义屏幕大小为N行

  1. tail: 从指定点开始将文件写到标准输出, 使用tail命令的-f选项可以方便的查阅正在改变的日志文件,,tail-f filename会把filename里最尾部的内容显示在屏幕上, 并且不断刷新,使你看到最新的文件内容
    命令功能: 用于显示指定文件末尾的内容, 不指定文件时, 作为输出信息进行处理, 常用查看日志文件

tail -n 5 log.txt 显示第五行的log

  1. pwd: 查看“当前工作目录”的完整路径。 简单的说,每当在终端进行操作时, 都会有一个当前工作目录

  2. mkdir: 用来创建指定的名称得目录,要求创建目录的用户在当前目录具有写权限,并且指定的目录名不能是当前目录中已有的目录

  3. rm:删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除

  4. rmdir: 删除空目录, 一个目录被删除前必须是空的,删除某目录时也必须具有对父目录的写权限

  5. mv: 用来移动文件或者将文件改名(move (rename)files)
    mv [选项] 源文件或目录 目标文件或目录

  6. cp: 用来复制文件或者目录
    cp 源地址 目的地址

  7. touch: 可更改文档或目录的日期时间, 包括存取时间和更改时间, 一般在使用make的时候可能会用到, 用来修改文件戳,或者新建一个不存在的文件

  8. less: less与more类似, 但使用less可以随意浏览文件, 而more仅能向前移动, 却不能向后移动, 而且less在查看文件之前不会加载整个文件

  9. grep:文件搜索工具, 它能使用正则表达式搜索文本, 并把匹配的行打印出来

  10. tar: 用来压缩和解压文件, tar本身不具有压缩功能, 它是调用压缩功能实现的

【Appium】appium中执行脚本log

2016-11-26 07:00:34:983 - info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d) //欢迎语和Appium版本
2016-11-26 07:00:34:985 - info: Appium REST http interface listener started on 0.0.0.0:4723 //启动监听的端口
2016-11-26 07:00:34:989 - info: [debug] Non-default server args:
//含有非默认的服务器参数 appium --session-override --log c://log/log.txt
{"sessionOverride":true,"log":"c://log/log1.txt"}
2016-11-26 07:00:34:990 - info: Console LogLevel: debug //控制器log的级别
2016-11-26 07:00:34:990 - info: File LogLevel: debug //log文档的log级别
2016-11-26 07:00:41:591 - info: --> POST /wd/hub/session {"requiredCapabilities":{},"desiredCapabilities": {"deviceName":"077a4602","unicodeKeyboard":"True","newCommandTimeout":120,"resetKeyboard":"True","platformVersion":"4.4.4","appPackage":"com.manboker.headportrait","platformName":"Android","appActivity":".activities.SplashActivity"}}
//传入设置的设备信息
2016-11-26 07:00:41:594 - info: Client User-Agent string: Python-urllib/2.7 //用户代理
2016-11-26 07:00:41:595 - warn: Converting cap unicodeKeyboard from string to boolean. This might cause unexpected behavior.
2016-11-26 07:00:41:596 - warn: Converting cap resetKeyboard from string to boolean. This might cause unexpected behavior.
2016-11-26 07:00:41:598 - info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
2016-11-26 07:00:41:600 - info: [debug] Creating new appium session eaf118d0-de01-4eb1-a791-3856101e9e1d //创建session
2016-11-26 07:00:41:601 - info: Starting android appium
2016-11-26 07:00:41:604 - info: [debug] Getting Java version
2016-11-26 07:00:41:843 - info: Java version is: 1.8.0_101

2016-11-26 07:00:41:846 - info: [debug] Checking whether adb is present
2016-11-26 07:00:41:848 - info: [debug] Using adb from D:\Test\android-sdk-windows\platform-tools\adb.exe
2016-11-26 07:00:41:850 - warn: No app capability, can't parse package/activity
2016-11-26 07:00:41:851 - info: [debug] Using fast reset? true
2016-11-26 07:00:41:857 - info: [debug] Preparing device for session
2016-11-26 07:00:41:859 - info: [debug] Not checking whether app is present since we are assuming it's already on the device
2016-11-26 07:00:41:860 - info: Retrieving device
2016-11-26 07:00:41:862 - info: [debug] Trying to find a connected android device
2016-11-26 07:00:41:863 - info: [debug] Getting connected devices...
2016-11-26 07:00:41:867 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe devices
2016-11-26 07:00:42:047 - info: [debug] 1 device(s) connected
2016-11-26 07:00:42:049 - info: Found device 077a4602
2016-11-26 07:00:42:050 - info: [debug] Setting device id to 077a4602
2016-11-26 07:00:42:054 - info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
2016-11-26 07:00:42:058 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 wait-for-device
2016-11-26 07:00:42:156 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "echo 'ready'"
2016-11-26 07:00:42:294 - info: [debug] Starting logcat capture
2016-11-26 07:00:42:336 - info: [debug] Getting device API level
2016-11-26 07:00:42:337 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "getprop ro.build.version.sdk"
2016-11-26 07:00:42:452 - info: [debug] Device is at API Level 19
2016-11-26 07:00:42:454 - info: Device API level is: 19
2016-11-26 07:00:42:456 - info: [debug] Extracting strings for language: default
2016-11-26 07:00:42:457 - info: [debug] Apk doesn't exist locally
2016-11-26 07:00:42:458 - info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
2016-11-26 07:00:42:459 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "rm -rf /data/local/tmp/strings.json"
2016-11-26 07:00:42:554 - info: [debug] Not uninstalling app since server not started with --full-reset
2016-11-26 07:00:42:555 - info: [debug] Skipping install since we launched with a package instead of an app path
2016-11-26 07:00:42:556 - info: [debug] Forwarding system:4724 to device:4724
2016-11-26 07:00:42:557 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 forward tcp:4724 tcp:4724
2016-11-26 07:00:42:641 - info: [debug] Pushing appium bootstrap to device...
2016-11-26 07:00:42:643 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 push "D:\Test\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
2016-11-26 07:00:42:823 - info: [debug] Enabling Unicode keyboard support
2016-11-26 07:00:42:824 - info: [debug] Pushing unicode ime to device...
2016-11-26 07:00:42:825 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 install "D:\Test\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk"
2016-11-26 07:00:53:998 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "settings get secure default_input_method"
2016-11-26 07:00:54:863 - info: [debug] Unsetting IME 'io.appium.android.ime/.UnicodeIME'
2016-11-26 07:00:54:865 - info: [debug] Setting IME to 'io.appium.android.ime/.UnicodeIME'
2016-11-26 07:00:54:871 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "ime enable io.appium.android.ime/.UnicodeIME"
2016-11-26 07:00:55:894 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "ime set io.appium.android.ime/.UnicodeIME"
2016-11-26 07:00:56:688 - info: [debug] Pushing settings apk to device...
2016-11-26 07:00:56:692 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 install "D:\Test\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
2016-11-26 07:01:07:894 - info: [debug] Pushing unlock helper app to device...
2016-11-26 07:01:07:898 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 install "D:\Test\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
2016-11-26 07:01:19:067 - info: Starting App
2016-11-26 07:01:19:071 - info: [debug] Attempting to kill all 'uiautomator' processes
2016-11-26 07:01:19:075 - info: [debug] Getting all processes with 'uiautomator'
2016-11-26 07:01:19:078 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "ps 'uiautomator'"
2016-11-26 07:01:19:299 - info: [debug] No matching processes found
2016-11-26 07:01:19:301 - info: [debug] Running bootstrap
2016-11-26 07:01:19:304 - info: [debug] spawning: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.manboker.headportrait -e disableAndroidWatchers false
2016-11-26 07:01:19:957 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
2016-11-26 07:01:19:964 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
2016-11-26 07:01:19:974 - info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
2016-11-26 07:01:19:978 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
2016-11-26 07:01:19:982 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
2016-11-26 07:01:19:984 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
2016-11-26 07:01:19:991 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
2016-11-26 07:01:19:993 - info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
2016-11-26 07:01:19:995 - info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
2016-11-26 07:01:19:996 - info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
2016-11-26 07:01:19:997 - info: [debug] [BOOTSTRAP] [debug] Loading json...
2016-11-26 07:01:19:999 - info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
2016-11-26 07:01:20:004 - info: [debug] Waking up device if it's not alive
2016-11-26 07:01:20:006 - info: [debug] Pushing command to appium work queue: ["wake",{}]
2016-11-26 07:01:20:010 - info: [debug] [BOOTSTRAP] [debug] Client connected
2016-11-26 07:01:20:012 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
2016-11-26 07:01:20:013 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-26 07:01:20:014 - info: [debug] [BOOTSTRAP] [debug] Got command action: wake
2016-11-26 07:01:20:015 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "dumpsys window"
2016-11-26 07:01:20:050 - info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
2016-11-26 07:01:20:118 - info: [debug] Screen already unlocked, continuing.
2016-11-26 07:01:20:119 - info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
2016-11-26 07:01:20:123 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
2016-11-26 07:01:20:124 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-26 07:01:20:125 - info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
2016-11-26 07:01:20:125 - info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"/data/local/tmp","status":0}
2016-11-26 07:01:20:126 - info: [debug] dataDir set to: /data/local/tmp
2016-11-26 07:01:20:127 - info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
2016-11-26 07:01:20:130 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
2016-11-26 07:01:20:131 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-26 07:01:20:131 - info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
2016-11-26 07:01:20:133 - info: [debug] Getting device API level
2016-11-26 07:01:20:133 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "getprop ro.build.version.sdk"
2016-11-26 07:01:20:166 - info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
2016-11-26 07:01:20:202 - info: [debug] Device is at API Level 19
2016-11-26 07:01:20:203 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.manboker.headportrait/.activities.SplashActivity"
2016-11-26 07:01:21:397 - info: [debug] Waiting for pkg "com.manboker.headportrait" and activity ".activities.SplashActivity" to be focused
2016-11-26 07:01:21:401 - info: [debug] Getting focused package and activity
2016-11-26 07:01:21:405 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "dumpsys window windows"
2016-11-26 07:01:21:566 - info: [debug] executing cmd: D:\Test\android-sdk-windows\platform-tools\adb.exe -s 077a4602 shell "getprop ro.build.version.release"
2016-11-26 07:01:21:638 - info: [debug] Device is at release version 4.4.4
2016-11-26 07:01:21:638 - info: [debug] Device launched! Ready for commands
2016-11-26 07:01:21:639 - info: [debug] Setting command timeout to 120 secs
2016-11-26 07:01:21:640 - info: [debug] Appium session started with sessionId eaf118d0-de01-4eb1-a791-3856101e9e1d
2016-11-26 07:01:21:647 - info: <-- POST /wd/hub/session 303 40056.211 ms - 74
2016-11-26 07:01:21:654 - info: --> GET /wd/hub/session/eaf118d0-de01-4eb1-a791-3856101e9e1d {}
2016-11-26 07:01:21:656 - info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"deviceName":"077a4602","unicodeKeyboard":true,"newCommandTimeout":120,"resetKeyboard":true,"platformVersion":"4.4.4","appPackage":"com.manboker.headportrait","platformName":"Android","appActivity":".activities.SplashActivity"},"deviceName":"077a4602","unicodeKeyboard":true,"newCommandTimeout":120,"resetKeyboard":true,"appPackage":"com.manboker.headportrait","platformName":"Android","appActivity":".activities.SplashActivity"},"sessionId":"eaf118d0-de01-4eb1-a791-3856101e9e1d"}
2016-11-26 07:01:21:661 - info: <-- GET /wd/hub/session/eaf118d0-de01-4eb1-a791-3856101e9e1d 200 7.588 ms - 757 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"deviceName":"077a4602","unicodeKeyboard":true,"newCommandTimeout":120,"resetKeyboard":true,"platformVersion":"4.4.4","appPackage":"com.manboker.headportrait","platformName":"Android","appActivity":".activities.SplashActivity"},"deviceName":"077a4602","unicodeKeyboard":true,"newCommandTimeout":120,"resetKeyboard":true,"appPackage":"com.manboker.headportrait","platformName":"Android","appActivity":".activities.SplashActivity"},"sessionId":"eaf118d0-de01-4eb1-a791-3856101e9e1d"}
2016-11-26 07:01:21:666 - info: --> POST /wd/hub/session/eaf118d0-de01-4eb1-a791-3856101e9e1d/timeouts/implicit_wait {"sessionId":"eaf118d0-de01-4eb1-a791-3856101e9e1d","ms":30000

【github】git 本地文件内容更改以后怎么同步到远程仓库

永远记得git是三个文件(本地--本地隐藏文件.git--远程仓库)
先pull再add然后commit最后push稍后给你一个git命令汇总

  1. 安装完成后,在开始菜单里找到“Git”->“Git Bash”

  2. git config --global user.name "Your Name"
    git config --global user.email "[email protected]"

  3. cd F: (打开F盘)
    mkdir (创建子目录)
    pwd (显示当前目录)

  4. git init (把这个目录变成Git可以管理的仓库)

  5. git add

  6. git commit -m "说明"

  7. git status (仓库当前的状态)

  8. git diff (查看不同)

  9. git log [--pretty=oneline {缩略版,可选}] (查看历史记录)

  10. git reset --hard HEAD^ (回退到上一个版本,HEAD后可以是 commit_id)

  11. git reflog (用来记录你的每一次命令,找到commit_id回到未来某个版本)

  12. git diff HEAD -- (查看工作区和版本库里面最新版本的区别)

  13. git checkout -- (用版本库里的版本替换工作区的版本,无论工作区是修改还是删除)

  14. git reset HEAD (把暂存区的修改撤销掉(unstage),重新放回工作区. 用HEAD时,表示最新的版本)

  15. git rm (用于删除一个文件)

  16. ssh-keygen -t rsa -C "[email protected]" (创建SSH Key)

  17. git remote add origin [email protected]:Bruce333/other.git (关联github远程库)

  18. git push -u origin master/git push origin master
    (推送到远程库,第一次用含有 -u 的命令,推送master分支的所有内容,此后用后面的命令推送最新修改)

  19. git clone [email protected]:Bruce333/other.git (克隆一个本地库)

  20. git checkout -b dev
    (创建dev分支,然后切换到dev分支,相当于以下两条命令:git branch dev[创建分支]/git checkout dev[切换分支])

  21. git branch (列出所有分支,当前分支前面会标一个*号)

  22. git checkout master (切换到master分支)

  23. git merge dev (合并指定分支到当前分支)

  24. git branch -d dev (删除dev分支)

  25. git log --graph (查看分支合并图)

  26. git merge --no-ff -m "merge with no-ff" dev
    (通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息;--no-ff表示禁用Fast forward,用普通模式合并,合并后的历史有分支,能看出来曾经做过合并;-m参数,把commit描述写进去)

  27. git stash (把当前工作现场“储藏”起来,等以后恢复现场后继续工作)

  28. git stash list (查看工作现场) / git stash apply stash@{0} ()

  29. git stash pop (恢复的同时把stash内容也删了,相当于:git stash apply[恢复]/git stash drop[删除])

  30. git branch -D (强行删除一个没有被合并过的分支)

  31. git remote (查看远程库的信息) / git remote -v (显示更详细的信息)

  32. git checkout -b branch-name origin/branch-name (在本地创建和远程分支对应的分支,本地和远程分支的名称最好一致)

  33. 从本地推送分支,使用git push origin branch-name,如果推送失败,先用git pull抓取远程的新提交

  34. git pull
    (把最新的提交抓下来;如果提示“no tracking information”,则说明本地分支和远程分支的链接关系没有创建,
    用命令git branch --set-upstream branch-name origin/branch-name)

  35. git tag <commit id 可无>
    (打一个新标签,默认标签是打在最新提交的commit上的;找到历史提交的commit id,可以给历史版本打标签)

  36. git show (查看标签信息)

  37. git tag (查看所有标签)

  38. git tag -a -m "blablabla..." (指定标签信息)

  39. git tag -s -m "blablabla..." (用PGP签名标签)

  40. git tag -d (删除标签)

  41. git push origin (推送某个标签到远程)

  42. git push origin --tags (一次性推送全部尚未推送到远程的本地标签)

  43. git tag -d (删除一个本地标签)

  44. git push origin :refs/tags/ (删除一个远程标签)

  45. git config --global color.ui true (让Git适当地显示不同的颜色)

  46. 忽略某些文件时,需要编写.gitignore;.gitignore文件本身要放到版本库里,并且可以对.gitignore做版本管理

  47. git config --global alias.st status
    (告诉Git,以后st就表示status,配置别名;加上--global是针对当前用户起作用的,如果不加,那只针对当前的仓库起作用;每个仓库的Git配置文件都放在.git/config文件中,别名就在[alias]后面,要删除别名,直接把对应的行删掉即可;而当前用户的Git配置文件放在用户主目录下的一个隐藏文件.gitconfig中)

【Appium】Appium中三种等待方式

#三种appium设置等待时间的方法
#作者:Mr.Dantes
#参考了网上的资料,然后进行了梳理

#第一种 sleep(): 设置固定休眠时间。 python 的 time 包提供了休眠方法 sleep() , 导入 time包后就可以使用 sleep()进行脚本的执行过程进行休眠。
#导入 time 包
import time
time.sleep()

#第二种 implicitly_wait():是 webdirver 提供的一个超时等待。隐的等待一个元素被发现,或一个命令完成。如果超出了设置时间的则抛出异常。
#implicitly_wait():隐式等待
#当使用了隐式等待执行测试的时候,如果 WebDriver没有在 DOM中找到元素,将继续等待,超出设定时间后则抛出找不到元素的异常
#换句话说,当查找元素或元素并没有立即出现的时候,隐式等待将等待一段时间再查找 DOM,默认的时间是0
#一旦设置了隐式等待,则它存在整个 WebDriver 对象实例的声明周期中,隐式的等到会让一个正常响应的应用的测试变慢,
#它将会在寻找每个元素的时候都进行等待,这样会增加整个测试执行的时间。

#implicitly_wait()方法比 sleep() 更加智能,后者只能选择一个固定的时间的等待,前者可以在一个时间
#范围内智能的等待。
self.driver.implicitly_wait()

#第三种 WebDriverWait():同样也是 webdirver 提供的方法。在设置时间内,默认每隔一段时间检测一次当前。页面元素是否存在,如果超过设置时间检测不到则抛出异常。
'''详细格式如下:
WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)
driver - WebDriver 的驱动程序(Ie, Firefox, Chrome 或远程)
timeout - 最长超时时间,默认以秒为单位
poll_frequency - 休眠时间的间隔(步长)时间,默认为 0.5 秒
ignored_exceptions - 超时后的异常信息,默认情况下抛 NoSuchElementException 异常。
WebDriverWait()一般由 until()或 until_not()方法配合使用,下面是 until()和 until_not()方法的说明。
until(method, message=’’)
调用该方法提供的驱动程序作为一个参数,直到返回值不为 False。
until_not(method, message=’’)
调用该方法提供的驱动程序作为一个参数,直到返回值为 False。
lambda
lambda 提供了一个运行时动态创建函数的方法。'''

from selenium.webdriver.support.ui import WebDriverWait
element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id(“someId”))
is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).
until_not(lambda x: x.find_element_by_id(“someId”).is_displayed())

【Appium】Driver常用命令总结

  1. 建立session时常用命令:
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.SetCapability("browserName", ""); // web 浏览器名称('Safari' ,'Chrome'等)。如果对应用进行自动化测试,这个关键字的值应为空。
    cap.SetCapability("platformName", "Android");//你要测试的手机操作系统
    cap.SetCapability("platformVersion", "4.4");//手机操作系统版本
    cap.SetCapability("automationName", "selendroid"); //你想使用的自动化测试引擎:Appium (默认) 或 Selendroid
    cap.SetCapability("deviceName", " Android Emulator"); //使用的手机类型或模拟器类型,真机时输入Android Emulator或者手机型号
    cap.SetCapability("udid", udid); //连接的物理设备的唯一设备标识,Android可以不设置

cap.SetCapability("newCommandTimeout", "300"); //设置收到下一条命令的超时时间,超时appium会自动关闭session ,默认60秒
cap.SetCapability("unicodeKeyboard", "True");//支持中文输入,会自动安装Unicode 输入法。默认值为 false
cap.SetCapability("resetKeyboard", "True"); //在设定了 unicodeKeyboard 关键字的 Unicode 测试结束后,重置输入法到原有状态

cap.SetCapability("'app'", "D:\AndroidAutomation\AndroidAutoTest\app\zhongchou.apk"); //未安装应用时,设置app的路径

//手机已安装app,直接从手机启动app,上面路径不设置
cap.SetCapability("appPackage", "com.nbbank"); //你要启动的Android 应用对应的Activity名称|比如MainActivity, .Settings|
cap.SetCapability("appActivity", "com.nbbank.ui.ActivityShow"); //你想运行的Android应用的包名
cap.SetCapability("appWaitActivity", "com.nbbank.ui.ActivityLogo"); //你想要等待启动的Android Activity名称|比如SplashActivity|

Uri serverUri = new Uri("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver(serverUri, cap, TimeSpan.FromSeconds(180));
更多详细查看官网:https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/caps.cn.md

  1. driver常用方法及注意事项
  1. 常用方法:

driver.HideKeyboard();//隐藏键盘
driver.BackgroundApp(60);//60秒后把当前应用放到后台去
driver.LockDevice(3); //锁定屏幕

//在当前应用中打开一个 activity 或者启动一个新应用并打开一个 activity
driver.StartActivity("com.iwobanas.screenrecorder.pro", "com.iwobanas.screenrecorder.RecorderActivity");
driver.OpenNotifications();//打开下拉通知栏 只能在 Android 上使用
driver.IsAppInstalled("com.example.android.apis-");//检查应用是否已经安装
driver.InstallApp("path/to/my.apk");//安装应用到设备中去
driver.RemoveApp("com.example.android.apis");//从设备中删除一个应用
driver.ShakeDevice();//模拟设备摇晃
driver.CloseApp();//关闭应用
driver.LaunchApp();//根据服务关键字 (desired capabilities) 启动会话 (session) 。请注意这必须在设定 autoLaunch=false 关键字时才能生效。这不是用于启动指定的 app/activities
driver.ResetApp();//应用重置
driver.GetContexts();//列出所有的可用上下文
driver.GetContext();//列出当前上下文
driver.SetContext("name");//将上下文切换到默认上下文
driver.GetAppStrings();//获取应用的字符串
driver.KeyEvent(176);//给设备发送一个按键事件:keycode
driver.GetCurrentActivity();//获取当前 activity。只能在 Android 上使用
//driver.Pinch(25, 25);//捏屏幕 (双指往内移动来缩小屏幕)
//driver.Zoom(100, 200);//放大屏幕 (双指往外移动来放大屏幕)
driver.PullFile("Library/AddressBook/AddressBook.sqlitedb");//从设备中拉出文件
driver.PushFile("/data/local/tmp/file.txt", "some data for the file");//推送文件到设备中去

driver.FindElement(By.Name(""));
driver.FindElementById("id");
driver.FindElementByName("text");
driver.FindElementByXPath("//*[@name='62']");
2) 注意事项:
使用driver.Sendkeys(string str)向文本框输入内容前,最好先element.Click( )一下,否则某些情况下,输入的内容会请不掉,文本框提示的内容也会在 输入的文本前显示出来。sendkey方法在发送数据之前会清空一下文本框,一般不需要Clear,如前面的情况Clear后仍是存在的,click后正常

  1. 等待页面加载策略:
  1. 显性等待:调用selenium的方法, 需要添加WebDriver.Support引用
    显性等待是指在代码进行下一步操作之前等待某一个条件的发生。最不好的情况是使用Thread.sleep()去设置一段确认的时间去等待。但为什么说最不好呢?因为一个元素的加载时间有长有短,你在设置sleep的时间之前要自己把握长短,太短容易超时,太长浪费时间。selenium webdriver提供了一些方法帮助我们等待正好需要等待的时间

         WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
         element = wait.Until<IWebElement>((d) =>
        {
            return driver.FindElement(By.Id("userName"));     
        });
    
  2. 隐性等待:设置时间不易过长,设置为500或1000即可
    隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间。默认值是0,但是设置之后,这个时间将在WebDriver对象实例整个生命周期都起作用。

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
4. drive.KeyEvent(int )的使用: 可使用KeyEvent发送键盘数据,比如退格,Enter键等
driver.KeyEvent(3); //KEYCODE_HOME 按键Home 3
driver.KeyEvent(26); //KEYCODE_POWER 电源键 26
driver.KeyEvent(67); //KEYCODE_DEL 退格键 67
driver.KeyEvent(66); //KEYCODE_ENTER 回车键
driver.KeyEvent(122); //KEYCODE_MOVE_HOME 光标移动到开始
driver.KeyEvent(123); //KEYCODE_MOVE_END 光标移动到末尾
5. 坐标操作

为防止不同手机分辨率不同带来的影响,要避免使用固定的坐标,可以用以下方式获取元素的坐标
double Screen_X = driver.Manage().Window.Size.Width;//获取手机屏幕宽度
double Screen_Y = driver.Manage().Window.Size.Height;//获取手机屏幕高度
double startX = element.Location.X; //获取元素的起点坐标,即元素最左上角点的横坐标
double startY = element.Location.Y; //获取元素的起点坐标,即元素最左上角点的纵坐标
double elementWidth = element.Size.Width; //获取元素的宽度
double elementHight = element.Size.Height; //获取元素的宽度
在封装“滑动”、“ TouchAction”等操作时可以用以上方法来获取坐标进行操作。

示例:分装两个元素之间的滑动

    IWebElement elmentA = null;
    IWebElement elmentB = null;
    int startX = 0, startY = 0, endX = 0, endY = 0;
    int duration=0,time=0;
    /// <summary>
    /// 从元素A的位置滑动到元素B的位置
    /// </summary>
    /// <param name="A">元素A的名称</param>
    /// <param name="B">元素B的名称</param>
    /// <param name="sDuration">滑动持续时间</param>
    /// <param name="sTime">滑动次数</param>
    public void SwipeAToB(string A, string B,string sDuration,string sTime)
    {
        startX = elmentA.Location.X + elmentA.Size.Width / 2;  //元素A的中心横坐标
        startY = elmentA.Location.Y + elmentA.Size.Height / 2; //元素A的中心纵坐标
        endX = elmentB.Location.X + elmentB.Size.Width / 2;    //元素B的中心横坐标
        endY = elmentB.Location.Y + elmentB.Size.Height / 2;   //元素B的中心纵坐标

        duration = string.IsNullOrEmpty(sDuration) ? 1500 : int.Parse(sDuration); //持续时间为空时,默认设置为1500毫秒
        time = string.IsNullOrEmpty(sTime) ? 1500 : int.Parse(sTime); //滑动次数为空时,默认设置为滑动1次

        for (int i = 0; i < time; i++)
        {
            driver.Swipe(startX, startY, endX, endY, duration);
        }
    }

注意:element.Loaction和element.Size,每次获取时都会重新去手机里获取,为节省时间如果有获取相同值的,建议储存成变量。

  1. 取消重新安装unlock和setting
    注销如下代码:

Appium\node_modules\appium\lib\devices\android\android.js
async.series([
this.initJavaVersion.bind(this),
this.initAdb.bind(this),
this.packageAndLaunchActivityFromManifest.bind(this),
this.initUiautomator.bind(this),
this.prepareDevice.bind(this),
this.checkApiLevel.bind(this),
this.pushStrings.bind(this),
this.processFromManifest.bind(this),
this.uninstallApp.bind(this),
this.installAppForTest.bind(this),
this.forwardPort.bind(this),
this.pushAppium.bind(this),
this.initUnicode.bind(this),

// DO NOT push settings app and unlock app
//this.pushSettingsApp.bind(this),
//this.pushUnlock.bind(this),

function (cb) {this.uiautomator.start(cb);}.bind(this),
this.wakeUp.bind(this),
this.unlock.bind(this),
this.getDataDir.bind(this),
this.setupCompressedLayoutHierarchy.bind(this),
this.startAppUnderTest.bind(this),
this.initAutoWebview.bind(this),
this.setActualCapabilities.bind(this)

], function (err) {

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.