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_feature
    for scenario in feature.scenarios:
        before_scenario
        for step in scenario.steps:
            before_step
                step.run()
            after_step
        after_scenario
    after_feature
after_all

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值