前言
哈Ha!在本教程文章中,我想讨论诸如Cucumber之类的框架的基本功能及其在移动iOS设备上创建UI自动测试的用途。
我的目标是使描述对于大多数读者来说尽可能简单和易于理解,而不论其编程或自动化技能如何。通常,网络上有很多有关BDD和Cucumber的信息,因此,为了避免重复,我不想深入研究一般理论,而是将重点放在框架和iOS的结合上。
首先,对于刚开始学习自动测试领域的那些测试人员,本文将很感兴趣。他们将获得有关如何部署Cucumber的详细说明,以及编写第一个测试的详细示例。对于不熟悉此工具的有经验的用户,本文将给出Cucumber的一般概念,并可能会帮助选择支持这种(相反,反之亦然-另一种)测试框架。
关于小黄瓜,黄瓜和BDD的几句话
Gherkin PO, - . «» Gherkin , - , (Given-When-Then-And) //.
Cucumber - , behavior driven (BDD) , Gherkin.
BDD (behavior driven development) - , - . BDD :
Scenario: Login with PIN
Given the app is running
And I'am registered user
And I see Login screen
When I enter 4-digits PIN
Then I am logged in
, , , , . .
Cucumber
Cucumber iOS semi-official (-?) .
Cucumber - ocoaPod , . CocoaPod
sudo gem install cocoa pods
pod init
. , :
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!
inhibit_all_warnings!
def test_pods
pod 'Cucumberish'
end
target ‘__CucumberTests’ do
test_pods
end
- , . ,
XCFit
sudo gem install xcfit
Xcode, , cucumberish bundle. CucumberTests . Features
build phases CucumberTests, Copy Bundle Resources, Compile Sources Link Binary With Libraries
Xcode,
pod install
.xcworkspace , . Screens, Step Definitions Supporting Files. - Add Files to.
, Cucumber!
( 2020) « » - . , . Xcode :
@objc
class func CucumberishSwiftInit()
var elementQurey
var elementQuery
expectedMenuCount: uInt = uInt(menuCount)!
expectedMenuCount: Int = Int(menuCount)!
expectedCellCount: uInt = uInt(cellCount)!
expectedCellCount: Int = Int(cellCount)!
. ⌘+U . , , «Tests successfully executed 0 from 0». , , , , .
" "
Cucumber :
Features - .feature, BDD . , Gherkin, ,
< >CucumberTests.swift . , Given , . . , , ,
Screens - .swift , ,
Step Definitions - .swift ,
Common - commonStepDefinitions.swift , , ( , ..)
. .feature , Features, , beforeStart CucumberishSwiftInit()
?
, . , , , c Xcode , ⌘+U.
:
/
-
Given And . Given , Given-And-And-…
swift , . , :
«The app is running» , .
Given When Then , . .swift Step Definitions
. -, , -
, , , :
feature Features. :
Feature:…
In order to …
As a …
I want to …
feature , Gerkin
swift Given
step definition
Given
«the app is running» . , - «», Given-And-And-… . , .
- . , , , .
, , , «My credentials», .
. , , .
, , «Get started». , , «0000»,
, , , , , . «0000».
UIInterruptionMonitor, , (faceid ) .
, / , «My credentials». ,
, credentialList , , . , , "Delete" "Delete credential".
. , «My credentials».
CommonStepDefinitions
Given-, .
CommonStepDefinitions.swift. Common , , .
, Menu, Confirm Deny, «Please confirm». , , , step definitions . CommonStep :
…
And I see the "Menu" view
And I see "Confirm" button
And I see "Deny" button
And I see "Please confirm" text
…
common , , :
common , . , - . step definitions accessibility identifier.
, BDD definition, ⌘+U. , , , ( ) executeFeatures .swift .
, - , , - , .
. , 50+ 5 . 5- 45 , . , 10 , , .
- ( «I have no credentials»). , .
Xcode . . .
. .
?
cucumber , , BDD . .
- , . , , 3-4 . , -, , BDD-. , BDD . ? ? cucumber .
, BDD PO -- , , Jira - .
, - , PO , , , , . step definitions .
, , , , , .
, , UI- Cucumber. , , .