wangshub / wechat_jump_game

微信《跳一跳》Python 辅助

Home Page:https://zhuanlan.zhihu.com/p/32452473

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iOS已完美运行

SiliconZou opened this issue · comments

img_2017
多谢楼主分享,技术无止境

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8100): Max retries exceeded with url: /status (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1053cf0f0>: Failed to establish a new connection: [Errno 61] Connection refused',))
这个有遇到过吗

大神 求一个 IOS 的简单教程 需要什么东西。 我是WIN 10系统。。。 需要什么软件 运行什么脚本呢? 感谢

@xiao-Warning
配置WDA的最后:有些国产的iPhone机器通过手机的IP和端口还不能访问,此时需要将手机的端口转发到Mac上。

$ brew install libimobiledevice
$ iproxy 8100 8100
这时如果访问 http://localhost:8100/status 能显示一堆JSON数据,就说明WDA运行成功
然后再试试,应该就可以了

👌 谢谢 我试试看

@overthehump iOS我也是按照楼主的步骤一步一步来的,我用的MacBook Pro,win10的话可以装Mac的虚拟机,不过比较麻烦

大神 我运行的时候 截的图有时候不太对 你有这种情况吗

@SiliconZou @xiao-Warning
我也遇到这个错误了,在浏览器里面访问 http://localhost:8100/status 能显示一堆JSON数据,但是就是报异常
2017-12-30 18 15 54

@SIXSIXSIXX 我这边截图的时候会把Python的进程给杀掉,但是还可以再重新运行,没发现图不对

@GhostClock Traceback (most recent call last):
File "wechat_jump_iOS_py3.py", line 30, in
pull_screenshot()
File "wechat_jump_iOS_py3.py", line 19, in pull_screenshot
c.screenshot('1.png')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 295, in screenshot
value = self.http.get('screenshot').value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 101, in fetch
return self._fetch_no_alert(method, url, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 107, in _fetch_no_alert
return httpdo(target_url, method, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/wda/init.py", line 83, in httpdo
raise WDAError(r.status, r.value)
wda.WDAError: WDAError(status=13, value=To screenshot a frame, it must have non-0 area.

(
0 CoreFoundation 0x00000001824c2dc8 + 148
1 libobjc.A.dylib 0x0000000181b27f80 objc_exception_throw + 56
2 CoreFoundation 0x00000001824c2c80 + 0
3 Foundation 0x0000000182e48154 + 112
4 XCTest 0x000000010008806c -[XCUIScreen _screenshotDataForQuality:rect:error:] + 192
5 XCTest 0x0000000100087f38 -[XCUIScreen screenshotDataForQuality:rect:error:] + 108
6 WebDriverAgentLib 0x0000000106b3f2dc -[XCUIDevice(FBHelpers) fb_screenshotWithError:] + 624
7 WebDriverAgentLib 0x0000000106b20dbc +[FBScreenshotCommands handleGetScreenshot:] + 132
8 WebDriverAgentLib 0x0000000106b2da10 -[FBRoute_TargetAction mountRequest:intoResponse:] + 208
9 WebDriverAgentLib 0x0000000106b2563c __37-[FBWebServer registerRouteHandlers:]_block_invoke + 496
10 RoutingHTTPServer 0x0000000106bde3cc -[RoutingHTTPServer handleRoute:withRequest:response:] + 144
11 RoutingHTTPServer 0x0000000106bdeb80 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 44
12 libdispatch.dylib 0x0000000181f0d47c + 16
13 libdispatch.dylib 0x0000000181f1cae8 + 644
14 libdispatch.dylib 0x0000000181f0d47c + 16
15 libdispatch.dylib 0x0000000181f12b84 _dispatch_main_queue_callback_4CF + 1844
16 CoreFoundation 0x0000000182478d50 + 12
17 CoreFoundation 0x0000000182476bb8 + 1628
18 CoreFoundation 0x00000001823a0c50 CFRunLoopRunSpecific + 384
19 Foundation 0x0000000182db0cfc + 308
20 WebDriverAgentLib 0x0000000106b24630 -[FBWebServer startServing] + 424
21 WebDriverAgentRunner 0x00000001006abbe4 -[UITestingUITests testRunner] + 132
22 CoreFoundation 0x00000001824c8a60 + 144
23 CoreFoundation 0x00000001823c0488 + 284
24 XCTest 0x0000000100072654 __24-[XCTestCase invokeTest]_block_invoke.275 + 48
25 XCTest 0x0000000100072404 __24-[XCTestCase invokeTest]_block_invoke + 680
26 XCTest 0x00000001000b89d8 -[XCUITestContext performInScope:] + 208
27 XCTest 0x000000010007214c -[XCTestCase invokeTest] + 136
28 XCTest 0x0000000100073224 __26-[XCTestCase performTest:]_block_invoke.382 + 48
29 XCTest 0x00000001000bda78 +[XCTContext runInContextForTestCase:block:] + 164
30 XCTest 0x0000000100072c20 -[XCTestCase performTest:] + 596
31 XCTest 0x000000010006ee14 __27-[XCTestSuite performTest:]_block_invoke + 288
32 XCTest 0x000000010006e83c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 44
我访问localhost之后一执行python3 wechat_jump_iOS_py3.py就这样了

@xiao-Warning 我访问localhost是错误没数据的,然后iproxy 8100 8100后 再打开http://localhost:8100/inspector就可以了

image
我这个打开是这样子,不过执行python3 wechat_jump_iOS_py3.py 还是跪了

楼主,IOS可以自动跳吗?

commented

iphone 6s

time_coefficient = 0.00190
不会用GitHub发这里了

卡在iproxy这一项了,
$iproxy 8100 8100
waiting for connection
accepted connection, fd = 4
waiting for connection
Number of available devices == 1
Requesting connecion to device handle == 40 (serial: 81d9164fb0991126168fc7b35d493205ae067ffb), port 8100
Error connecting to device!
启动之后
$ python3 wechat_jump_iOS_py3.py
retry to connect, error: HTTPConnectionPool(host='localhost', port=8100): Read timed out. (read timeout=60.0)
提示错误

@LucasDvP 好像是不能,我是一步一步点着跳的😂 iPhone6的参数time_coefficient = 0.00200

pip install -t /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages --pre facebook-wda

image

到iproxy 8100 8100 打开浏览器这一步得到的是这个
2017-12-31 12 47 51

iPhone 7 Plus 系数
time_coefficient = 0.00120

我运行出来的图怎么是这个
image

@siitao 你这个应该是直接运行py文件之后的结果吧。其他都还没弄吧。

@w0wbin 起来的弄了 localhost:8100的图也是这样的 是我哪一步没做对 还是漏了
image

@xiao-Warning 我遇到的问题和你一模一样 请问你解决了吗

@siitao 你这个是模拟器,不是手机的界面

commented

@SiliconZou requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) 这是是什么情况

成功实现了。不过不能自动跳,哪个大神尽快出自动跳版本吧

我也可以实现了,但是需要手动点击一下,每次不能跳到中心点,有误差,有时候也会跳不上去。这个应该怎么处理啊

Android的auto脚本稍稍改下就可以在ios上自动跳了,不过参数一直不够完美,只能跳到几百,就不发出来了,等dalao撸个完美的。

@SwiftieTerrence 求IOS自动跳的脚本

1

我的运行除了不能自动跳都ok。跳不准的只能自己掌握以下技巧了吧

@Qiuliuyang 如何点击让他一步步跳,图片显示的分数是我在手机上点击的跳
wx20171231-105445 2x

@zhangmyWZDY 在matplot里面上点一下起始坐标,再点一下终点坐标就行了。会自动跳

@Qiuliuyang thks , 有没有出现python界面显示不全,点完一个块,下一个块不在屏幕中显示,或者找不到下一个块的坐标点,请问如何解决?

@zhangmyWZDY 是你手机连接不太好?我还没有这个问题,延迟倒是有,不过等一两秒就好了

@SiliconZou 楼主 怎么让他自动跳?wda应该在9.3.2d的系统运行有问题

@SiliconZou 手动。。说错

wx20171231-112008 2x

8deb9dc5d50f44885c679fa1dcf59fd8

同一个界面,python应用程序显示如上图,手机上显示如下图,
设备iPhone6,运行的python3 wechat_jump_iOS_py3.py,time_coefficient = 0.00200,其他未做改动,
各路大神有看到的,求解。

@cultivater 你指哪一个?

@xiao-Warning 你遇到的那几个问题我都遇到过,尤其是最后的http://localhost:8100/inspector不显示手机的界面,你最后怎么解决的呢?

commented

iPhone 7 plus跳一步之后界面刷新不完整,有大佬遇到过么,求解决方法。

@LoveJuly 7Plus time_coefficient = 0.00120

commented

@LucasDvP 这个系数我是这样设置的,就是跳了一步之后,新的小方块出现不完整。。。

@LoveJuly@wangshub,看看需不需要改一下updatefig里面sleep时间

commented

@LucasDvP 这个时间是什么时间?

@LoveJuly 刷新截图的间隔时间,要不你直接改成0.5试试好了

commented

@LucasDvP 我明白了,可以尝试一下

commented

iphone 怎么保证每次都跳到中心点?

@LoveJuly 棋子下方中间超出1mm为起点,终点就是几何体顶平面中心

commented

@LucasDvP 应该怎么修改iOS_py3的代码

commented

@LucasDvP 把点击获取的坐标转换为对应几何体的中心?

@LoveJuly 不用改代码,具体IOS我没有找到自动化方法,只能自己一个一个点

commented

@LucasDvP 我在想能不能把代码改改,点击第一次获取起点的中心点,点击第二次获取终点的中心点,distance就等于两个中心点的间距,这样无论怎么点,就都是跳到中心点了(保证每次都点到几何体的情况下)

@LoveJuly,可是你几何体中心点在变化,这个原po使用OpenCV实现获取中心点的,你可以研究下如何在IOS里面调用wechat_jump_auto的代码

commented

@LucasDvP 找到一个可行的,#224(issue)

@LoveJuly 棒,我试试

commented

@LucasDvP 有没有遇到过webdriveragent在iPhone 5s 下 test fail的情况

@LoveJuly 没有我没有5s真机,你可以把error贴上来看看

commented

@LucasDvP 关键是xcode的控制台没有显示任何东西,command + U之后直接一个“test failed”的弹窗,就没了。

检查2个地方:

  • 设置里面Device Setting有没有Trust你个人用户证书
  • 证书有没有按照这个设置好
commented

在Mac下运行,好像需要把

ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)

改为

ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=False)

要不然,不会自动更新图像

commented

@LucasDvP 环境都没有问题,同样的环境下,6s和7p都可以成功test,唯独5s不行,我正在升级5s的系统,想知道是不是系统的问题,因为我用模拟器验证过是正常的。

@LoveJuly,很有可能,你bundle setting里面选的IOS系统要跟你真机系统匹配

可以自动化了。见:
https://github.com/wangshub/wechat_jump_game/pull/273/files

运行前提:
一个iOS设备、一台Mac电脑、一份Xcode

  1. 安装brew
  2. 安装WebDriverAgent,各种问题可以参考这个帖子
  3. 安装python3,即brew install python3
  4. 安装本项目的各种依赖pip3 install -r requirements.txt
  5. 安装WebDriverAgent的Python库:pip3 install facebook-wda
  6. 安装brew install libimobiledevice

接下来

  1. 手机用线连接mac,然后xcode通过真机运行WebDriverAgent(Product->test)
  2. 电脑运行iproxy 8100 8100,在电脑浏览器访问http://localhost:8100/status看是否有输出。有则说明wda正常。
  3. 手机运行跳一跳程序
  4. 电脑运行python3 wechat_jump_auto_iOS.py即可。
    不断调整代码里的参数,使得可以自动完成。

@kaizhetutuquliaomei 不排除是wda和iOS9的兼容问题啊。
不过我想也没必要为了这个就升级系统吧。

@goodbest good work~

@kaizhetutuquliaomei 我刚刚用5s@iOS10试了一下,第一次也是截图崩。后来关了一些程序,重新就好了。估计是内存不足..(5s和6都是内存捉急)

commented

@LucasDvP 已解决,有没有iPhone 5S的参数,分享一下。

@kaizhetutuquliaomei 我只能说inspector有时正常,有时不正常。
xcode里面经常报错ebDriverAgentRunner-Runner[249:8414] Enqueue Failure: Application local.pid.195 is not running

commented

iPhoneSE的参数
time_coefficient = 0.00225

commented

@champkeh config.json的配置呢?是用1920x1080的吗

@LucasDvP

自己的机器上测试可用的自动脚本 #271

请问配置WDA bundle签名证书那些一定需要个人证书吗

mac + iPhoneX完美运行

@Azleal 请教一下WDA签名那部分是怎么完成的,我也是Mac和iPhone X

@Azleal 请教下,iPhone X 的参数如何配置

@goodbest
你好,在运行wda的时候 弹出什么要access的钥匙串密钥,我不知道,然后我就点了拒绝,现在就跑不起来了。提示这个错误

CodeSign /Users/pengpn/Library/Developer/Xcode/DerivedData/WebDriverAgent-epqieiskmzjtbzfnpjbdjrvtlmrx/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app/Frameworks/XCTAutomationSupport.framework
    cd /Users/pengpn/Downloads/WebDriverAgent
    export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    
Signing Identity:     "iPhone Developer: 312924860@qq.com (5B98PT69ZW)"

    /usr/bin/codesign --force --sign 2C4AD029F196C7ECFC5FC0E94A9EDD5BA80C1DBA --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none /Users/pengpn/Library/Developer/Xcode/DerivedData/WebDriverAgent-epqieiskmzjtbzfnpjbdjrvtlmrx/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app/Frameworks/XCTAutomationSupport.framework

/Users/pengpn/Library/Developer/Xcode/DerivedData/WebDriverAgent-epqieiskmzjtbzfnpjbdjrvtlmrx/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app/Frameworks/XCTAutomationSupport.framework: replacing existing signature
/Users/pengpn/Library/Developer/Xcode/DerivedData/WebDriverAgent-epqieiskmzjtbzfnpjbdjrvtlmrx/Build/Products/Debug-iphoneos/WebDriverAgentRunner-Runner.app/Frameworks/XCTAutomationSupport.framework: unknown error -1=ffffffffffffffff
Command /usr/bin/codesign failed with exit code 1
commented

@LoveJuly

我没有用config.json,我是直接改的ios的那个文件
image

commented

@SiliconZou 按照你说的方式安装了iproxy,问题依然存在。
ip:port/status 无数据
localhost:port/status 有数据
但是
localhost:port/inspector访问非常缓慢
而且执行py的时候提示
requests.exceptions.ConnectionError: HTTPConnectionPool 最大重试次数过多的问题

折腾小半天终于OK了,刷了3288分
npm版本要更新最新
iphone端口不能直接http访问,brew install libimobiledevice,不是brew install imobiledevice
iphone7plus: time_coefficient = 0.00117

@BABALA258 请问下WDA general那块签名怎么弄,用什么签名证书。。感谢

卡在 waiting for connection。捂脸

@Abysman 我用的是apple开发者账号,到developer.apple.com去新建iOS Provisioning Profiles下载到xcode使用;

@BABALA258 感谢。。不过这是不是收费的才能有证书

@BABALA258 不能直接http访问怎么办呢 我一直在waiting for connection

@LucisBaoshg 参考一下 issues/4 , 另外wechat_jump_iOS_py3.py 中的参数已经是iPhone X的推荐参数了, 我没有调.

@Abysman 参考 这篇这篇 基本上配置了个人证书 改下buddle identifier就行了

@zhangmyWZDY 你把 wechat_jump_iOS_py3.py 里面的 time.sleep(1) 改成合适的时间 我试了 1.5s 没问题

有没有人和我一样中途把手机拔了的。。然后估计是iproxy映射的问题,就再也连不上了。。。


自己解决了。。用lsof -i tcp:port 将port换成被占用的端口(如:8100),然后找到进程的PID,使用kill命令:kill PID(进程的PID,如40989),杀死对应的进程。再重新用iproxy映射就可以了

commented

@pengpn 你好 请问你的那个Command /usr/bin/codesign failed with exit code 1问题解决了吗?

@Azleal 对,我的问题其实是个人证书怎么来的,是一定要交钱申请才行是吗。谢谢~

一定要有mac电脑吗?

iphone8 plus
time_coefficient = 0.00120

6s
用auto的跑起来了,可以加上总分识别来完成指定总分的功能

iPhone 6 + Mac
自动模式下 press_coefficient = 1.95 个人觉得比较合适
另外,time.sleep(random.uniform(2, 3)) 设置为2-3 这样更稳定同时还能够获得 唱片机 便利店等的加分
再次感谢作者们!

@Abysman 不用的,改了WebDriverAgent的BundleID,用自己icloud账号就行,参考给出的https://testerhome.com/topics/7220这篇的“免费版的个人证书“这段

@SiliconZou @goodbestpip3 install –pre facebook-wda
Invalid requirement: '–pre'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/packaging/requirements.py", line 92, in init
req = REQUIREMENT.parseString(requirement_string)
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1617, in parseString
raise exc
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1607, in parseString
loc, tokens = self._parse( instring, 0 )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1379, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 3376, in parseImpl
loc, exprtokens = e._parse( instring, loc, doActions )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1379, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 3698, in parseImpl
return self.expr._parse( instring, loc, doActions, callPreParse=False )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1379, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 3359, in parseImpl
loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 1383, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/pyparsing.py", line 2670, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected W:(abcd...) (at char 0), (line:1, col:1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 82, in init
req = Requirement(req)
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/packaging/requirements.py", line 96, in init
requirement_string[e.loc:e.loc + 8]))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'–pre'"

大佬 help!

commented

求教大佬
Product -> test 后显示
image
运行环境 Mac 10.13.2,Xcode 也是最新版本
手机系统 iPhone 8Plus 11.2.1

@Ding221 xcode应该是9.2

iPhone 7 + mac

建议将 wechat_jump_auto_iOS.py 中的

 if abs(pixel[0] - last_pixel[0]) + abs(pixel[1] - last_pixel[1]) + abs(pixel[2] - last_pixel[2]) > 10

改为

if abs(pixel[0] - last_pixel[0]) + abs(pixel[1] - last_pixel[1]) + abs(pixel[2] - last_pixel[2]) > 2

对于一些圆形带条纹board效果好,完成了500到1000以上的质变

此外

time.sleep(random.uniform(1, 1.1))   # 为了保证截图的时候应落稳了,多延迟一会儿

改成

time.sleep(random.uniform(1.4, 1.5))   # 为了保证截图的时候应落稳了,多延迟一会儿

这样可以吃到大多数的5/10/15/20。上面提到的2,3也是稳妥的选择。


感谢作者和大家,祝不删好友

卡在waiting for connection,尝试了很多办法都没解决,有人遇到这个问题的嘛