序作为被测对象进行实践。
安装和配置环境。安装并且启动Appium,分别使用命令“ gem install selenium-webdriver”、“ gem install rspec"和"gem install cucumber”安装ruby版本的WebDriver. Repec和Cucumber.
按照Cucumber的规则建立相关目录和文件。首先需要定义support目录下的env.rb文件。文件中需要定义测试初始化的一些功能,详细代码如下:
require ' rspec/ expectations '
require ' selenium-webdriver'
# Where our app lives, relative to this file
APP_ PATH - '../ ../bui1d/ Debug- i phones imulator / i0SCounter 4MVC. app'
#What we need as a capability --> i0s device, where our app is, .
ect.
def capabilities
' browserName' => ',
'platform' => 'Mac',
'device' => ' iPhone Simulator',
'version' => '6.0',
'app' => absolute_ app_ path
end
# Make sure the path above is relative to this file
def absolute_ apP_ path
File. join(File.dirname(_ FILE_ ), APP_ PATH)
end
# The location of our selenium (or in this case, Appium) file
def server_ url
"http://127.0.0.1:4723/wd/hub"
end
# Set up a driver or, if one exists, return it
def selenium
@driver 11= Selenium: :WebDriver. for (:remote, :desired_
capabilities => capabilities, :url => server_ ur1) .
end
After { @driver.quit }
然后定义测试场景,由于测试使用了相同的应用程序,所以功能和场景都是一样的。 在此直接保留之前的my_ feature.feature文件。文件内容如下: