利用Calabash-Android刷广告

时间:2022-06-16 22:32:03

    calabash-android是一个单元测试的工具,用来测试UI。这个特点非常适合来刷应用程序的广告。本文以一个简单的例子来教大家使用calabash-anroid来刷应用程序的广告。代码下载地址:https://github.com/bigconvience/poker_hu

    在使用本文提供的例子进行测试前,请先确保安装好测试环境,可参考此文:Windows 安装Calabash-Android 

     代码下载后,进入到工程目录,输入calabash-android run,如下图所示:

利用Calabash-Android刷广告

此时,工程目录先边创建了目录features. 此app为一个三人斗地主的小游戏,点击menu->广告推荐,才弹出广告,如下图所示:

利用Calabash-Android刷广告

利用Calabash-Android刷广告


为了能达到刷广告的目的,在features/my_first.feature中添加如下代码

Feature: Click ads feature
  
  Scenario: I can click menu item to show ads
	Then I wait for the "PokerActivity" screen to appear
	Then I wait for 10 seconds
	Then I press the menu key
	Then I wait for 5 seconds
        Then I touch on screen 600 from the left and 350 from the top
	Then I wait for 10 seconds
	Then I go back

由于android 版的touch坐标step尚未定义,可在step_definitions中添加文件touch_steps.rb,代码如下:

# -- Touch --#
Then /^I (?:press|touch) on screen (\d+) from the left and (\d+) from the top$/ do |x, y|
	touch(nil, {:offset => {:x => x.to_i, :y => y.to_i}})
	sleep(3)
end

打开windows命令行,设置命令行字体:cmd中输入: chcp 65001,具体可参考: http://blog.sina.com.cn/s/blog_628e2ab30101ajcg.html

在命令行中输入:calabash-android run Poker_hu.apk,即可开始刷广告。之后,使用shell脚本或批处理文件封装该命令,即可自动刷广告了。对于windows环境,新建run.bat,然后添加如下代码:

@echo off
:begin
start /b calabash-android run PokerHu.apk
ping /n 180 127.1 >nul
@echo resart
goto begin

在命令行输入run,没隔三分钟广告会被刷一次。 但愿刷多了账号不会被封 利用Calabash-Android刷广告