Looking to implement a single tag with multiple values depending on the situation in cucumber?

In our automation framework, we have a cleanup hook that is tagged from the cucumber feature file.

For example:

@cc_task_clean_up_hook_enrol_A Scenario: Person can enrol_A When I select the context menu Then I am able to enroll the patient into 'enrol_A'

The implementation of the hook (@cc_task_clean_up_hook) is:

@After(value = "@toc_task_clean_up_hook_enrol_A", order = HookOrder.CLEAN_UP_APP_AFTER)
public void cleanUpTOC() {
    this.patientContextPage.selectedContextMenuItem("Pathway");
    this.pathWayPage.selectReferences("Enroll in Pathway");
    this.pathWayPage.deactivateEnrollment("enrol_A", "Withdrawn");
}

We also need another scenario as follows:

Scenario: Person can enroll_B When I select the context menu Then I am able to enroll the patient into 'enrollB'

To consolidate these two methods and write only one generic clean up hook based on the passed parameter, we can consider implementing it. Any assistance would be greatly appreciated.

Answer №1

To include the scenario object in the after hook's arguments, simply add it to the method signature. This allows the framework to provide the currently executing scenario as a parameter.

public void afterMethod(Scenario scenario){}
  1. An alternative approach is to utilize the getSourceTagNames() method of the Scenario object to access the tags associated with the current scenario. By checking for tags ending in 'enroll_A' or 'enroll_B', you can determine specific scenarios.

  2. Another method is to use the getName() method to retrieve the description of the scenario. This way, you can identify scenarios based on descriptions like 'Person can enroll_A' or 'P..... enroll_B'.

  3. You also have the option to modify the Then step to pass the enrollment type to the step definition and store it in a variable for use in the after hook. Keep in mind that this requires the after hook to be in the same class.

Additionally, don't forget to update the value parameter of After hook to -

{"@toc_task_clean_up_hook_enrollA,@toc_task_clean_up_hook_enrollB"}
.

If you notice similarities in steps, consider implementing ScenarioOutline instead to streamline your testing process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automate Data Extraction from Tables Using Python Selenium and Convert them into a DataFrame

I am just starting to learn Python and selenium, and I'm facing a challenge that I need help with. Currently, I am attempting to extract data from a particular website: "" The goal is to convert the table on this website into a dataframe similar to ...

Having trouble with clicking the browser button in Selenium WebDriver

Currently, I am working with Selenium WebDriver but encountering an issue. When I attempt to click on the Browse button, a popup should be displayed. However, my application is not responding and fails to open the browser. try{ WebElement fileInput = ...

When using Protractor with Typescript, you may encounter the error message "Failed: Cannot read property 'sendKeys' of undefined"

Having trouble creating Protractor JS spec files using TypeScript? Running into an error with the converted spec files? Error Message: Failed - calculator_1.calculator.prototype.getResult is not a function Check out the TypeScript files below: calculato ...

Receiving empty string when extracting text from Span

Looking to extract text from the span within this specific div using Python and Selenium: <div class="product-name"> <span class="h1" itemprop="name">TARGET TEXT</span> </div> I attempted the following code, but it unfortunate ...

What is the simplest method for integrating ChromeDriver into an application?

When it comes to web automation, I find myself frequently using Selenium and ChromeDriver. Currently, I add ChromeDriver to all my projects by making a copy of chromedriver.exe and including it in each project directory. Then, I specify the location of chr ...

Using Python and Selenium, you can locate an element inside another element

I've got the xpath for an element: /html/body/div[1]/div/div[2]/div[3]/div/div/div/div[2]/div[1]/div[2]/div[6]/div/div/div/div[1] Inside that div, there's another element: /html/body/div[1]/div/div[2]/div[3]/div/div/div/div[2]/div[1]/div[2]/div[ ...

Executing selenium tests on Internet Explorer 11 on a Windows 10 1809 machine without encountering any new pop-up windows

While testing on my computer, I encountered an issue where my test would start successfully, but after opening and closing several Internet Explorer windows during the test, no new windows would open. There were no error messages displayed, and the test se ...

Unable to locate an extended hyperlink text using Selenium WebDriver

There is a challenge I am facing in identifying an element by link text. When the link text value is short, like addFirst or addLast, I am able to locate the element easily using: driver.findElement(By.linkText("addLast, addFirst")).click() However, when ...

Is it possible to implement reusable test steps in nightwatch.js?

My goal is to develop reusable components for my nightwatch.js tests. For example, logging in and logging out of the web application. What would be the most effective approach or pattern for creating these steps in a way that is reusable? ...

SeleniumGrid encountered an issue with creating a new session, resulting in an org.openqa.selenium.SessionNotCreatedException. The error was caused by the inability to generate a new ChromeDriverService. This occurred with build information version

My journey began with the following commands: Hub Command: java -jar selenium-server-standalone-3.141.59.jar -role hub Node Command: java -Dwebdriver.chrome.driver="\Users\rachitamittal\eclipse-workspace\firstjavaproject\drivers& ...

Utilizing Selenium webdriver to retrieve images from the internet

Currently, I am attempting to retrieve images from a website using the following code snippet: List <WebElement> listofItems = driver.findElements(By.cssSelector("div.heroThumbnails:nth-child(4) > div:nth-child(2) > div:nth-child(n)")); URL ...

Tips for circumventing the validation popup on Dell's support page while submitting the search string with Python and Selenium WebDriver

For my automation project, I am facing a challenge with inputting service tags on the Dell support page to extract laptop information. Occasionally, a validation pop-up appears when trying to submit, resulting in a 30-second waiting time. https://i.stack. ...

Extracting the text content of a specific tag while ignoring the text within other tags nested inside the initial one

I am trying to extract only the text inside the <a> tags from the first <td> element of each <tr>. I have provided examples of the necessary text as "yyy" and examples of unnecessary text as "zzz". <table> <tbody> <tr ...

No search results appear when the search button is pressed in Python using Selenium

After successfully automating Edge (and Chrome) to navigate to the correct page for searching broadband prices and entering a postcode into the search box, a problem arises when clicking the search button - it fails to display the results. The goal is to o ...

What is the best way to choose the next adjacent element using a CSS selector with Python Selenium?

The structure of the DOM is as shown below: <ul> <li> <a href="#" role="button" class="js-pagination link" data-page="1">1</a> </li> <li> <a href="#" role="button" class="js-pagination link active" data ...

Switch to Edge browser in Selenium instead of using Chrome

I have successfully implemented code using Chrome and WebDriverManager. But now, I am curious if it's feasible to switch the browser Selenium is utilizing from Chrome to Edge? Can this transition be accomplished with just one line of code (modifying ...

The Initial Java Script with Selenium

Recently, I decided to delve into the world of Selenium and wrote my first Java script using this tool. However, when I tried running it, I encountered some errors. https://i.stack.imgur.com/Q5VYj.png The errors that appeared are: WebDriver cannot be re ...

Tips for minimizing lag in Python try and except blocks

I have developed an automation program using Python specifically for a website. One issue I encountered is that there is a random PopUp that appears when I interact with the site. To address this, I incorporated a code to remove the Pop-Up whenever it appe ...

Upon loading a webpage using selenium, it navigates to the end but fails to retrieve all elements housed within the div

Looking to scrape all the product links from this website: . The page only loads 30 out of 100 products initially, and the rest load when clicking somewhere on the page. How can I retrieve all the product links? Any help is appreciated! from selenium im ...

Is there a way for me to navigate back to the active driver window once my script has finished running?

Utilizing Selenium WebDriver alongside Chrome WebDriver, my script1 captures a URL from the driver.get(" ...") method and performs various tasks like web scraping (such as clicking buttons, extracting information, and logging into a website). Af ...