本文主要是介绍Appium Python behave 自动化测试框架搭建(3) - Environment.py,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
https://www.pythonhosted.org/behave/api.html#environment-file-functions
1. 框架结构
You may optionally include some environmental controls (code to run before and after steps, scenarios, features or the whole shooting match).
The minimum requirement for a features directory is:
features/
features/everything.feature
features/steps/
features/steps/steps.py
A more complex directory might look like:
features/
features/signup.feature
features/login.feature
features/account_details.feature
features/environment.py
features/steps/
features/steps/website.py
features/steps/utils.py
2.
before_step(context, step), after_step(context, step)
These run before and after every step. The step passed in is an instance of Step.
before_scenario(context, scenario), after_scenario(context, scenario)
These run before and after each scenario is run. The scenario passed in is an instance of Scenario.before_feature(context, feature), after_feature(context, feature)These run before and after each feature file is exercised. The feature passed in is an instance of Feature.
before_tag(context, tag), after_tag(context, tag)T
hese run before and after a section tagged with the given name. They are invoked for each tag encountered in the order they’re found in the feature file. See Controlling Things With Tags. The tag passed in is an instance of Tag and because it’s a subclass of string you can do simple tests like:
# -- ASSUMING: tags @browser.chrome or @browser.any are used.
if tag.startswith("browser."):
browser_type = tag.replace("browser.", "", 1)
if browser_type == "chrome":
context.browser = webdriver.Chrome()
else:
context.browser = webdriver.PlainVanilla()
before_all(context), after_all(context)
These run before and after the whole shooting match.
3. 代码调用顺序
before_all
for feature in all_features:before_featurefor scenario in feature.scenarios:before_scenariofor step in scenario.steps:before_stepstep.run()after_stepafter_scenarioafter_feature
after_all
这篇关于Appium Python behave 自动化测试框架搭建(3) - Environment.py的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!