RUVIDEO
Поделитесь видео 🙏

Selenium Cucumber Java BDD Framework Class 9: HOOKS

📁 Лайфстайл 👁️ 16 📅 05.12.2023

How to use HOOKS:
-----------------

1 - What are Hooks
2 - Why to use Hooks
3 - When to use Hooks
4 - How to create & use Hooks - Step by Step Demo
5 - Conditional Hooks

What are HOOKS

- Blocks of code that runs before OR after each scenario
- Hooks in Cucumber are like Listeners in TestNG
- Can define hooks by using annotations @Before @After

Scenario Hooks - runs before and after each scenario
Step Hooks - runs before and after each step
Conditional Hooks - hooks associated with tags for conditional execution

Why to use HOOKS

- To manage the setup and teardown
- To avoid rewriting the common setup or teardown actions
- Allow better management of code workflow

When to use HOOKS

- Whenever you have some common setup and teardown actions to be executed before each scenario

How to use HOOKS

Step 1 - Create a new or use an existing Feature File
Step 2 - Create the steps for the scenario in the feature file
Step 3 - Create setup and teardown methods and mark with annotation
@Before
@After
@BeforeSteps
@AfterSteps

Step 4 - Create new or use an existing TestRunner class
Step 5 - Run the TestRunner class and check execution

We can use Tags with Hooks - Conditional Hooks
Hooks can be conditionally selected for execution based on the tags of the scenario
To run a particular hook only for certain scenarios, you can associate a Before or After hook with a tag expression
Tags can be used with
@BeforeSteps
@AfterSteps
@After(value="@smoke", order=2)

@smoke
Scenario

@Before("@smoke")

@Before(value="@smoke", order=1)

Single tag
tags = {"@smoke"}

Multiple tags
Tags with AND OR conditions

tags = {"@smoke or @regression"}

tags = {"@smoke and @regression"}

tags = {"@smoke and not @regression"}

Skip or Ignore Tags

tags = {"(@smoke or @regression) and not @important"}

Ordering Hooks
We can use multiple Before and After hooks and also assign order of execution

@Before(order=0)
@Before(order=1)

Background

- Whatever happens in hooks is invisible to people who only read the features
- Only use hooks for low-level logic such as starting a browser or deleting data from a database.
- You should consider using a background as a more explicit alternative, especially if the setup should be readable by non-technical people


You can keep your function name anything
Hooks will get executed even if the test fails

You need to import the library
import io.cucumber.java.Before;
import io.cucumber.java.After;

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Selenium Cucumber Java BDD Framework Class 9: HOOKS», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.