当前位置:网站首页>Open source | Ctrip ticket BDD UI testing framework flybirds
Open source | Ctrip ticket BDD UI testing framework flybirds
2022-07-06 01:35:00 【Software testing Intelligence Agency】
One 、 background
Ctrip ticket from 2018 It was officially introduced in the middle of the year BDD, So far 3 More years , Become the internal preferred agile development technology .
Flybirds It's a set of bases BDD Front end of mode UI Automated testing framework , It provides a series of out of the box tools and perfect documents , Now gradually stabilize , Become the first choice inside the ticket BDD-UI-Testing The test framework .
Two 、 Why open source
Share our BDD Technical solution
Look forward to using in the industry BDD Technology peers have more in-depth exchanges with us through the open source community
This article will introduce... From the characteristics 、 Environment building 、 Use the help 、 Custom extension 、 Continuous integration 、 The framework is introduced in these aspects of the release plan .
3、 ... and 、Flybirds
be based on Behave, Realization BDD in “ Natural language test case documentation ” and “ Automated test code ” Association requires support BDD Tools .
be based on Airtest, Realization BDD in “ Test cases can be executed on an automated test platform ” Need to use UI Automated testing framework .
be based on Multiple-cucumber-html-reporter, Realize visual test report .
Four 、 characteristic
Use Flybirds You can complete most of the mobile terminal automation operations , Here are some feature descriptions to help you get started :
be based on BDD Pattern , Natural language grammar
Support Automation APP operation 、 Form submission 、UI Element verification 、 Keyboard entry 、Deeplink Jump, etc.
English is supported by default 、 There are two languages in Chinese , Support more language extensions
Plug in design , Support user-defined automation extension
Provide cli The scaffold , Build projects quickly
Provide html The report
5、 ... and 、 Environment building
5.1 Use pip install flybirds frame , The required dependent packages will be automatically installed during the process :https://github.com/ctripcorp/flybirds/blob/main/docs/relate_zhCN.md
pip3 install flybirds
stay Mac/Linux Under the system , Need to be given manually adb Executable rights :
for mac
cd {
your_python_path}/site-packages/airtest/core/android/static/adb/mac
chmod +x adb
for linux
cd {
your_python_path}/site-packages/airtest/core/android/static/adb/linux
chmod +x adb
5.2 Use scaffolding to create projects
flybirds create
6、 ... and 、 Quick start
6.1 Run Demo
To help use , When the project is created , Will generate Chinese and English Android、iOS demonstration feature, Convenient for users to refer to .
features/test/
features/test/android
features/test/android/cn/everything.feature
features/test/android/en/everything.feature
features/test/iosfeatures/test/ios/cn/everything.feature
features/test/ios/en/everything.feature
With “Android” For example :
Carry out orders adb devices , Check whether the test equipment is included in the equipment list
Began to run
cd {
PATH_TO_PROJECT_FOLDER}
flybirds run -P features/test/android
The framework will go through flybirds_config Configured in packagePath Automatically download the test package and install ( Please make sure the phone is turned on ” Allow installation of unknown source “ ).
The operation results are as follows :
11 features passed, 0 failed, 0 skipped, 0 untested
23 scenarios passed, 0 failed, 0 skipped, 0 untested
117 steps passed, 0 failed, 0 skipped, 0 undefined, 0 untested
Took 5m21.300s
=====================================================================================
Multiple Cucumber HTML report generated in:
/Users/test/my_first_project/report/7eb9162a-9d42-4fde-a5d7-d8d4bca7a8d8/index.html
=====================================================================================
Next , Learn more about the project details .
6.2 Project structure
config: The configuration file
features: The test case feature file
pscript: Custom extension
report: Test report
6.3 features Catalog
The basic directory structure is as follows :
test: Deposit feature file , These documents are written in natural language , It's best to use the non-technical business in the software project 、 Prepared by product personnel and participants .
steps: Store the... Used in the scene step Statements for ,“steps.py” All... Are loaded in step Sentence template .
features/
features/test/
features/test/everything.feature
features/steps/
features/steps/steps.py
For a more complex directory structure, refer to the following :
features/
features/test/
features/test/list.feature
features/test/buy.feature
features/test/detail.feature
features/steps/
features/steps/steps.py
6.4 feature file
feature The file contains user actions , Text describing behavior characteristics and expected results , The behavioral characteristics section uses Gherkin Language writing .
feature file , Also known as function files , There are two purposes : Documentation and automated testing .
Start with a keyword (“ function ”、“ scene ”、“ Scenario outline ”、“ When ”、“ and ”、“ that ”……), Comment lines are allowed anywhere in the file .
function (Feature) Are some reasonable descriptive titles of the function being tested , Composed of scenes . They can choose to have a description 、 A background and a set of labels .
background (Background) It consists of a series of steps similar to the scene . It allows you to add some context to the functional scenario . Before each scenario of this function .
scene (Senario) The title should be a reasonably descriptive title of the tested scenario , Consists of a series of steps with given conditions .
Scenario outline (Senario Outline) Contains a detailed description of the function , There can be a set of expected conditions and results to match your scenario steps .
The following is Chinese feature Example :
The following is English feature Example :
6.5 step Statement template
Some templates are listed below | View more templates :https://github.com/ctripcorp/flybirds/blob/main/docs/casedsl_zhCN.md
6.6 Hooks
The user can define in the following files hooks:
pscript/dsl/step/hook.py
( Slide left and right to see the full code )
before_step(context,step), after_step(context, step)
At every step (step) Run before and after
before_scenario(context,scenario), after_scenario(context, scenario)
In every scene (senario) Run before and after
before_feature(context,feature), after_feature(context, feature)
In each function file (feature) Run before and after
before_tag(context,tag), after_tag(context, tag)
Marking... With the given name (tag) Run before and after the part of
before_all(context), after_all(context)
Run before and after all execution
6.7 label (Tags)
have access to tag Mark different scenes , Convenient and selective operation .
Here is an example :
The operation has specific tag Scene , Multiple are separated by commas :
flybirds run -T tag1,tag2
‘-’ The beginning indicates that the run does not contain a tag Scene :
flybirds run -T -tag
7、 ... and 、 Check before operation
7.1 Please ensure that the configured test equipment can be connected normally
Android: Carry out orders adb devices , Check whether the test equipment is included in the equipment list
iOS: With tidevice Library example , Carry out orders tidevice list, Check whether the test equipment is included in the equipment list
Android Device to connect Q&A:https://airtest.doc.io.netease.com/IDEdocs/device_connection/2_android_faq/
Please install the official driver of the corresponding brand of the mobile phone first , Make sure you can use the computer to control your mobile phone USB debugging
Make sure the... In your phone is turned on " Developer options ", And turn on " Developer options " Internal " allow USB debugging "
Some mobile phones need to be turned on " Allow simulation position "、“ Allowed to pass through USB Install application ”
Close the phone assistant software already installed on the computer , Can avoid most problems , Please be sure to end the mobile assistant process manually in task manager
iOS Device to connect Q&A:https://airtest.doc.io.netease.com/IDEdocs/device_connection/4_ios_connection/
Please prepare one first macOS , Use xcode Deploy iOS-Tagent After success , In the mac or windows Connect to... On the machine iOS mobile phone . Please download the project code to deploy locally , Download address :https://github.com/AirtestProject/IOS-Tagent
mac The environment passes through Homebrew install iproxy: brew install libimobiledevice
windows Environmental installation itunes, Download address :https://support.apple.com/downloads/itunes
7.2 Download and install the test package
Android:
The framework will go through config Configured in packagePath Automatically download the test package and install ( Please make sure the phone is turned on ” Allow installation of unknown source “ ). You can also manually download and install : Download address
iOS:
a. Please download the demo manually APP Installation : Download address
b. Turn on wdaproxy:shell tidevice --udid
$udid wdaproxy -B $web_driver_angnt_bundle_id -p $port
8、 ... and 、 Operation parameters
Enter the following in the terminal to view flybirds Supported actions when running a project .
flybirds run --help
run
perform features All the feature file .
–path, -P
Specify the feature aggregate , It could be a directory , It can also be specified to specific feature file , The default is ‘features’ Catalog .
Example :
flybirds run -P ./features/test/demo.feature
–tag, -T
The operation has specific tag Scene , Multiple are separated by commas ,‘-’ The beginning indicates that this... Is not run tag Scene .
flybirds run -T tag1,tag2,-tag3,tag4
–format, -F
Specify the format for generating test results , The default is json.
Example :
# Default
flybirds run --format=json
Nine 、 Configuration parameters
Provides a wealth of configuration items | Help document :https://github.com/ctripcorp/flybirds/blob/main/docs/demoproject_zhCN.md
Must configure item :deviceId packageName.
Connect iOS Equipment time , Need extra configuration webDriverAgent、platform.
Ten 、 The report (report)
The report contains a summary Summary And function (feature) 、 scene (senario) The results of the implementation of , For failure scenarios (senario), The report will show the screen images and videos at that time , Here is an example .
11、 ... and 、 Customize step Statement template
Writing Feature In the process of , You may encounter that the public statements provided cannot meet the needs of your own project , Custom statements are required . such as : Need to dock with an internal tool API, At this point, you need to use the custom statement function .
Custom statements will use python, If you don't know this programming language , There's no need to worry too much , Because only the most basic python grammar , It won't be too difficult .
Usage method
Enter project directory "psscript/dsl/steps"
newly build .py File to write custom statements
stay feature/steps/steps.py in import The .py file
The sample code is as follows :
For custom functions common within the team , Consider creating a extend package,flybirds Support dynamic loading ,package The name contains “-flybirds-plugin” that will do .
Twelve 、 Custom framework extensions
Theoretically BDD-UI-Testing It can be applied to all ends , such as :APP、Web、 Applet .
Plug in design pattern of framework , Well preserved extensions , The current version is only open APP Client support , In the future, it will gradually open up more , Here are two examples for your reference .
increase web End extension
stay plugins.default Add your own web package .
add to web Corresponding implementation . such as page.py,element.py, If you need to add other plug-in implementation classes , Only need GlobalContext Add the corresponding name to the class .
stay plugin.event Add your own web package .
stay event.web Rewrite or add new classes under the package , Like rewriting run Events can occur in plugin.event.web Add... Below "run.py", The specific implementation logic can refer to the existing run.py.
In the project profile "flybirdes_config.json" To configure device_info.platform The value is "web".
Modify the current APP End extension
configurable "plugin_info.json" To what already exists plugins Make changes ( Only modification is supported, and new addition is not supported ), For example, you want to be right plugins below ios.app Make changes :
a. You can create your own... Locally app.py
b. stay plugin_info.json Add the following configuration to the corresponding platform :
"app": {
"path": "{local_path}/app.py",
"ns": "app.plugin"
}
{local_path} For local paths ,"ns" For the package name , Pay attention to the uniqueness of the package name .
13、 ... and 、 Other languages support
flybirds Can support 40 Several languages , Add the language configuration of public methods in the following files .
flybirds/core/dsl/globalization/i18n.py
The sample code is as follows :
fourteen 、 Continuous integration
cli Command line execution mode provided , It is very convenient to join various continuous integration tools .
With Jenkins For example :
# Inside the jenkins shell command
cd {
PATH_TO_PROJECT_FOLDER}
# Run
flybirds run -P ./features/test/everything.feature
cp -R reports $WORKSPACE
15、 ... and 、 Release plan
We will follow SemVer Release the version control specification . Gradually add new functions and code optimization , You are very welcome to join our co construction plan , stay Github Put forward valuable suggestions on , And all the problems encountered in use , We will also do a small version of this iteration once a week . You can also give us spiritual support here , Click on one Star.
Github Address :
https://github.com/ctripcorp/flybirds
PyPI Address :
https://pypi.org/project/flybirds
contribution
1)Fork Warehouse
2) Create a branch (git checkout -b my-new-feature)
3) Commit changes (git commit -am ‘Add some feature’)
4) push (git push origin my-new-feature)
5) establish PR
Welcome to the github issues District questions , Address :https://github.com/ctripcorp/flybirds/issues
Support mailbox :[email protected]
Team recruitment information
We are the R & D team of Ctrip , In charge of Ctrip APP/PC Development and innovation of terminal air ticket business . Air ticket research and development in search engine 、 database 、 Deep learning 、 High concurrency and so on , Continuously optimize the user experience , Increase of efficiency .
In the research and development of air tickets , You can work with a lot of top technology bulls , Truly let millions of users enjoy your products and code , Enhance the travel experience and happiness index of global travelers .
If you love technology , And eager to grow , Ctrip ticket R & D team is looking forward to flying with you . At the moment, we are / backstage / data / There are open positions in test development and other fields .
Email address for resume delivery :[email protected], Email title :【 full name 】-【 Ctrip ticket 】-【 Delivery position 】.
Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One button, three links !
Good article recommends
Interview : First tier cities move bricks ! Another software testing post ,5000 That's enough …
What kind of person is suitable for software testing ?
The man who leaves work on time , Promoted before me …
The test post changes jobs repeatedly , Jump, jump and disappear …
“ One year in the job , The automated software test hired by high salary was discouraged .”
边栏推荐
- 【Flask】官方教程(Tutorial)-part3:blog蓝图、项目可安装化
- Luo Gu P1170 Bugs Bunny and Hunter
- Nmap: network detection tool and security / port scanner
- Development trend of Ali Taobao fine sorting model
- Hcip---ipv6 experiment
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
- [flask] official tutorial -part1: project layout, application settings, definition and database access
- How to get the PHP version- How to get the PHP Version?
- How does Huawei enable debug and how to make an image port
- 剑指 Offer 38. 字符串的排列
猜你喜欢
Unity | 实现面部驱动的两种方式
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
现货白银的一般操作方法
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
yii中console方法调用,yii console定时任务
MATLB|实时机会约束决策及其在电力系统中的应用
ThreeDPoseTracker项目解析
500 lines of code to understand the principle of mecached cache client driver
Hcip---ipv6 experiment
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
随机推荐
selenium 元素定位(2)
Force buckle 1020 Number of enclaves
A Cooperative Approach to Particle Swarm Optimization
Condition and AQS principle
Electrical data | IEEE118 (including wind and solar energy)
How does Huawei enable debug and how to make an image port
[flask] official tutorial -part2: Blueprint - view, template, static file
[le plus complet du réseau] | interprétation complète de MySQL explicite
WGet: command line download tool
[flask] obtain request information, redirect and error handling
剑指 Offer 12. 矩阵中的路径
Redis-列表
Basic operations of databases and tables ----- primary key constraints
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
[flask] response, session and message flashing
【Flask】静态文件与模板渲染
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
干货!通过软硬件协同设计加速稀疏神经网络
Tcpdump: monitor network traffic
NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】