怎樣在網(wǎng)站上做鏈接站長字體
1.目標
-
在做飯、鍛煉等無法騰出雙手的場景中,想刷刷抖音
-
刷抖音的時候有太多的廣告
如何解決痛點
- 抖音自動播放下一個視頻
- ?iOS系統(tǒng)高版本無法 越獄 安裝插件
2.操作環(huán)境
MAC一臺,安裝 Xcode
iPhone一臺,16 系統(tǒng)以上最佳
?3.流程
下載最新?web-driver-agent_appium
xcode 打開
?配置開發(fā)者證書
運行?
( 直接command+U運行,這是test模式,不能run,即一定要執(zhí)行project>Test 才可以校驗第三步),?運行后會提示輸入mac電腦的密碼,提示編譯成功,并且在IOS真機上看到了WDA的身影。
編譯成功
同時,控制臺會顯示輸出IP地址和端口,如下圖所示(打開控制臺方法:選擇view->Debug Area->Activate console打開底部控制臺。):關鍵是最后一句話(ServerURLHere->http://192.168.11.236:8100<-ServerURLHere)
復制url到輸入在瀏覽器中,就會發(fā)現(xiàn)網(wǎng)頁上顯示出你的手機界面,然后,你就可以為所欲為啦。
不過有些iPhone,據(jù)說是國產(chǎn)的原因,直接使用ip不能連接手機(即輸入打印出來的url無法顯示手機界面),需要進行端口轉(zhuǎn)發(fā)(終端執(zhí)行 “iproxy 8300 8100”?回車后在瀏覽器中輸入http://localhost:8300/出現(xiàn)json字符串即表示成功,同時說明WDA安裝成功了)。
查看當前設備
地址后面添加/status可以查看當前設備(你使用的哪個設備運行,就是哪個設備的狀態(tài))的狀態(tài)。---http://localhost:8300/status,獲取與wda通信session id
?手機桌面app
?iOS15 以上打開屏幕會出現(xiàn)黑色影子,15 一下會閃退,需要 xcode 附加調(diào)試才能運行
第一部完成
web-driver-agent 就算安裝完了。
開始第二部分
實現(xiàn)自動點擊,和滑動,界面文字獲取,等操作...
實現(xiàn)原理
? ? ? 本身?web-driver-agent 就是 一個服務器,我們在寫app安裝到手機,調(diào)用本機127.0.0.1服務器接口。
點擊/滑動 接口
+ (NSArray *)routes
{return@[[[FBRoute POST:@"/wda/touch/perform"] respondWithTarget:self action:@selector(handlePerformAppiumTouchActions:)],[[FBRoute POST:@"/wda/touch/multi/perform"] respondWithTarget:self action:@selector(handlePerformAppiumTouchActions:)],[[FBRoute POST:@"/actions"] respondWithTarget:self action:@selector(handlePerformW3CTouchActions:)],];
}
要調(diào)用本地服務器,需要先獲取一個sessionId
訪問?http://127.0.0.1:8100/status 可以得到若sessionId字段為空,
就訪問? /session? 創(chuàng)建
POST?http://127.0.0.1:8100/session?
Body?
NSString *body = @"{\"capabilities\":{\"firstMatch\":[{\"arguments\":[],\"environment\":{},\"eventloopIdleDelaySec\":0,\"shouldWaitForQuiescence\":true,\"shouldUseTestManagerForVisibilityDetection\":false,\"maxTypingFrequency\":60,\"shouldUseSingletonTestManager\":true,\"shouldTerminateApp\":true}],\"alwaysMatch\":{}}}";
獲取session完整代碼
- (IBAction)noButtonhttp:(id)sender {//get請求//[self reqWithMethod:0];[xddHttp reqWithMethodxdd2:@"http://127.0.0.1:8100/status" Method:0 HTTPBody:@"" Block:^(NSURLResponse * _Nonnull response, NSDictionary * _Nonnull dic) {NSString *sessionId = dic[@"sessionId"];NSLog(@"請求成功-status-sessionId=%@",sessionId);iPhoneSessionId = sessionId;if ([sessionId isKindOfClass:[NSNull class]]) // 字符串為空NSString *body = @"{\"capabilities\":{\"firstMatch\":[{\"arguments\":[],\"environment\":{},\"eventloopIdleDelaySec\":0,\"shouldWaitForQuiescence\":true,\"shouldUseTestManagerForVisibilityDetection\":false,\"maxTypingFrequency\":60,\"shouldUseSingletonTestManager\":true,\"shouldTerminateApp\":true}],\"alwaysMatch\":{}}}";[xddHttp reqWithMethodxdd2:@"http://127.0.0.1:8100/session" Method:1 HTTPBody:body Block:^(NSURLResponse * _Nonnull response, NSDictionary * _Nonnull dic) {NSString *sessionId = dic[@"sessionId"];NSLog(@"請求成功-session-sessionId=%@",sessionId);iPhoneSessionId = sessionId;}];}}];}
拿到session
及可以去點擊,滑動,獲取屏幕信息了。
我測試每 10 秒手機屏幕自動上滑一次
創(chuàng)建定時器
+(void)myTimers{userarr = [self testArr];dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{// 在這里執(zhí)行你的任務//[self goo:nil];});myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(goo:) userInfo:nil repeats:YES];}
每秒加一到 10 ,就執(zhí)行一次滑動屏幕
+(void)go{GlobalVariableName = @"g0";userindex = userindex + 1;NSLog(@"定時器查: %d",userindex );//if(userindex %3 == 0){if(userindex == 10){userindex=0;NSLog(@"開始滑動: %@",@"-------------------");NSString*url = [NSString stringWithFormat:@"http://127.0.0.1:8100/session/%@/wda/touch/perform",iPhoneSessionId];//點擊NSString*body = @"{"actions":[{"action":"tap","options":{"x":131,"y":248}}]}";//滑動body=@"{\"actions\":[{\"action\":\"press\",\"options\":{\"x\":111,\"y\":392}},{\"action\":\"wait\",\"options\":{\"ms\":500}},{\"action\":\"moveTo\",\"options\":{\"x\":112,\"y\":161}},{\"action\":\"release\",\"options\":{}}]}";[xddHttp reqWithMethodxdd2:url Method:1 HTTPBody:body Block:^(NSURLResponse * _Nonnull response, NSDictionary * _Nonnull data) {NSLog(@"滑動結(jié)果: %@",data);}];}}
實現(xiàn)效果
web-driver-agent_appium-自動滑動
手機需要保持后臺運行,定時器一直運行
保持后臺運行參考代碼
iOS 關于后臺持續(xù)運行https://gitee.com/vww/BgTaskDemo