Is there a TestNG Listener that can automatically clear the temporary folder, even if the test run is aborted through

When I run my tests, I utilize Java Selenium WebDriver along with TestNG.

In the final test, I include driver.quit() to ensure that any files created in the /tmp/ folder are removed.

However, if the run is interrupted (e.g. via Jenkins), the contents of the /tmp/ folder remain untouched.

Is there a way, perhaps through a TestNG listener or other method, to guarantee that the tmp folder is cleared even if the run is abruptly halted?

Answer №1

If the issue at hand is occurring on Jenkins level (such as aborting action), it would be more effective to resolve it within Jenkins itself rather than relying on TestNG Listener.

For declarative pipeline

pipeline {
    agent any

    stages {
        ...
    }
    post {
        aborted {
            script {
              echo 'cleanup on abort'
              // performing workspace cleanup
              // cleanWs() 
              

              // alternatively, delete 'tmp' directory only
              dir ('tmp') {
                  deleteDir()
              }
            }
        }
    }
}

Utilizing Plugin

Install the plugin and configure shell script execution for the job like so

rm -rf tmp

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

Serialize HashMap to JSON as the primary element

I've created a custom class that acts as a wrapper for a HashMap. My goal is to serialize this class using Jackson into a JSON object without any additional wrapping elements. public class Customers { @JsonProperty private Map< ...

What are some methods for extracting text from a document using Selenium Webdriver?

If I have a single document, how can I extract text from it using the Selenium WebDriver? Below is the code I've used: d1.findElementByClassName("odd").click(); Thread.sleep(5000); d1.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS); WebElem ...

Merging JSON data from server on Android platform

As a novice coder, I am delving into Android development through Ravi's insightful tutorials. At the moment, my focus is on merging two specific tutorials - login/register and listview (I provided the links for reference to avoid cluttering the post w ...

Is there a way in Python using Selenium to scroll to the position of a page where a specific element is visible?

I have been attempting to navigate to the center of the page using this code snippet, but it does not seem to be functioning correctly. driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);") In addition, I am experimenting with elem ...

Managing NoSuchElementException() at the project level in a selenium C# application

Currently, I am working on selenium using C# with the NUNIT 3.0 framework. I have around 200 test cases and I want to avoid repetitive try-catch blocks for each one as there is a possibility of exceptions occurring in any test case. Is there a way to handl ...

When executing tests in a docker environment with Selenium_Hub, Selenium-Node-Chrome-Debug, and a Mocha + Selenium-Webdriver (JS) container, the ability to upload files becomes restricted

I have spent a significant amount of time conducting experiments and utilizing various search engines in an effort to find a resolution to this problem, but unfortunately, I haven't had any luck thus far. Consequently, I'm hoping that someone wit ...

Struggling to locate an element within a frame using Selenium in Python?

I've been working on a bot that logs into my account. After entering the username and password, I have the bot click on the "I'm not a robot recaptcha" using this code successfully: def _delay(): time.sleep(randint(1,3)) frames = driver.f ...

What is the best way to create a report.html file for each testsuit (.robot file) in RoboTFramework?

Currently, I am utilizing a single PyCharm project to execute various test files for a specific website. For instance, I have robot files containing test cases like: loginTest.robot, purchasetest.robot, signinwith_facebook.robot However, whenever I run t ...

Utilizing Webdriver in C# to loop through elements and add their names to a screenshot array

My Plan: Grab the dropdown menu Find each option in the dropdown menu Click on each option, take a screenshot Progress so far: IWebElement DropDownMenu = driver.FindElement(By.XPath("//*[@id='DropDownMenu']/span")); ...

A beginner's guide to extracting information from a website using Selenium

I'm attempting to extract data from a website, but encountering an error. Here is the link to the website: from selenium import webdriver PATH="C:\Program Files (x86)\chromedriver.exe" url='https://www.dastelefonbuch.de/Suche ...

Attempting to choose a radio button in the second column of a table using Selenium XPATH, specifically where the text corresponds to "name"

I am facing an issue with navigating through a table that has 5 columns. The second column contains text data for the Name field, while columns 1, 3, 4, and 5 contain radio buttons. Specifically, I need to select the radio button in column 3 where the name ...

Difficulty with automating tests using selenium in Linux: Unable to automatically close Firefox browser

When conducting automation testing for web GUI in Linux using Selenium (Selenium RC), I encountered an issue. While running Selenium tests on Windows yielded successful results with Firefox closing automatically after completing the test, the same could no ...

Having trouble locating the table element within a div element using Selenium in Python

My goal is to access values from a table within a div element using selenium. Although I am able to see the table when inspecting the element, I cannot locate it in the source code while attempting to access it through selenium. When Inspecting: https:/ ...

Having difficulty locating the identification number of an item within the HTML coding

I'm currently trying to locate the ID of the "proceed to checkout" button for a bot that I am developing for my mother on the Best Buy website. However, it seems like the button's ID is hidden and I'm unable to determine how to uncover it. A ...

The Selenium element stubbornly refuses to be clicked, despite being patiently waited for

I'm facing a challenge where I need to open a form, wait for all of its elements to be loaded, and then fill in one of the fields within the form. As the form is loading, I have set up a WebdriverWait to explicitly wait for the element to become click ...

Having trouble with the moveToElement Selenium action specifically on BrowserStack's iPhone device?

Currently, I am working on creating a selenium automation script for an Angular single page application that has been integrated with browserstack. The code runs smoothly when executed locally, and it functions properly on browserstack for the specified pl ...

Granting permission to use the camera and microphone in Chrome 64

I recently came across a helpful discussion in my quest to enable camera and microphone access in Chrome, but unfortunately the suggested methods haven't been successful for me. I tried both approaches outlined in the thread but without any luck. Desp ...

Guide on Maximizing the Power of Selenium Ruby Bindings

I'm currently exploring the Selenium Ruby binding and I'm looking for the official website that provides information on the available options for Ruby Driver capabilities. Despite my efforts to search online, most of the resources I found are Ja ...

Protractor's elementExplorer is malfunctioning, and the REPL is not showing up on Windows

Having some difficulty getting elementExplorer to work. Here's what I've been trying: node node_modules\protractor\bin\protractor .\protractor.dev.conf.js --baseUrl http://angularjs.org --elementExplorer Using the following ...

WebdriverIO: encountering the error message "Cannot read property length of undefined" while setting up cucumber and running tests

For a while now, I've been trying to dive into testing using the webdriverIO cucumber setup. I discovered some documentation and an example on the webdriverIO website that I'm attempting to implement: https://github.com/webdriverio/webdriverio/tr ...