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