Unable to save screenshot in the report portal while running with WebDriver.io (wdio) execution

In my webdriverio project, the directory structure is as follows: e2e/ utilities/pUtil.js report/screenshot specs wdio.config.js

Within pUtil.js file, I have the following code snippet:

static takeScreenshot(name, failure = false, test) {
    const path = './e2e/report/screenshot/';
    let fileName = '';
    if (!fs.existsSync(path)) {
      fs.mkdirSync(path, { recursive: true });
    }
    if (failure) {
      fileName = name + '_fail';
    }
    fileName = fileName.replace(/ /g, '_') + '.png';
    browser.saveScreenshot(path + fileName);
    const data = fs.readFileSync(`${path}${fileName}`);
    reporter.sendFileToTest(test, 'INFO', fileName, data);
  }

My project is set up to generate both allure and report portal reports. However, when a test fails, the screenshot is successfully added to the allure report but not the report portal.

 ********* FILE NAME IN **********./e2e/report/screenshot/should_allow_us_fail.png
[2021-09-23T01:20:52.483Z] [0-0] ************ outputFile::./e2e/report/screenshot//should_allow_us_fail.png
[2021-09-23T01:20:52.483Z] [0-0] 2021-09-23T01:20:51.026Z ERROR @wdio/sync: Error: ENOENT: no such file or directory, open './e2e/report/screenshot/should_allow_us_fail.png'
[2021-09-23T01:20:52.483Z] [0-0]     at Object.openSync (fs.js:457:3)
[2021-09-23T01:20:52.483Z] [0-0]     at Object.readFileSync (fs.js:359:35)

I am requesting assistance in identifying what might be missing in this setup.

Answer №1

Give this a try!

Utilize wdio

after: function (result, capabilities, specs) {}
hook for spec file or WDIO
afterStep: async function (step, scenario, result, passed, error,duration) {}},
hook for cucumber to capture screenshots for failed tests.

step 1: npm i wdio-reportportal-reporter
Place the code snippet in your WDIO config file

const reportportal = require('wdio-reportportal-reporter');

after: async function (result, capabilities, specs) {
  if (!result) {
     const screenShot = await global.browser.takeScreenshot();
     let attachment = await Buffer.from(screenShot, 'base64');
     await reportportal.sendFile('error', "screnshot.png", attachment);
 }
},

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

Having trouble retrieving the content of a paragraph inside an accordion element using Selenium in Java

After successfully using xpath to retrieve the text from the first paragraph, I encountered issues with getting the text from the second and third paragraphs. The console output showed them as empty. The problematic strings were: String secondAns , String ...

Unlocking the true potential of JSON data encoding in PHP

While attempting to retrieve an object from my controller, the console.log(response) function displays the correct value: [ { "itemValue":100, "itemUnit":"2" } ] However, when trying to access the object using ...

What is the best approach for developing an npm package containing multiple Vue directives? Should each directive have its own separate package, or should they

While I have successfully created an npm package by exporting a single vue directive in the src/index.js file, I am now faced with the challenge of creating a package that allows for the use of multiple vue directives. Unfortunately, I have been unable t ...

An issue occurred while executing PhantomJS using Selenium's RemoteWebDriver

Launching a selenium grid hub using the default startup command: java -jar selenium-server-standalone-2.33.0.jar -role hub Also, initiating PhantomJS in its webdriver mode on the same machine with the following command: phantomjs --webdriver=8080 --web ...

Maximizing Efficiency: Sending Multiple Responses during computation with Express.js

Seeking a way to send multiple responses to a client while computing. See the example below: app.get("/test", (req, res) => { console.log('test'); setTimeout(() => { res.write('Yep'); setTime ...

Guide on how to showcase an array in a string format using table rows in JavaScript or jQuery

After making an AJAX call to a PHP database, I receive a String as a result in my script. The format of the string is shown below: array(4) { [0]=> array(3) { ["id"]=> string(3) "181" ["number"]=> ...

Error with object props in React using Typescript

Here's a scenario; I have a list of 'Reviews' that I am trying to render. The Proptype for these reviews is as follows: export interface Props { title: string; name: string; reviewdesc: string; rating: number; } In the pare ...

Combine TypeScript files in a specific sequence following compilation

I am hoping to utilize gulp for the following tasks: Compiling TypeScript to JavaScript, which is easily achievable Concatenating JavaScript files in a specific order, proving to be challenging Since I am developing an Angular application, it is crucial ...

compress a website to display advertisement

Here is a JSFiddle link I would like to share with you: I am currently working on squeezing the webpage to display an ad on the right side. http://jsfiddle.net/5o6ghf9d/1/ It works well on desktop browsers, but I am facing issues with iPad Safari/Chrome ...

Leveraging Forms for Entering Google Maps Information

Recently, I've been working on an app that aims to generate a custom map based on user input from a form. If you'd like to test the functionality yourself, head over to this page. After filling out all required fields and hitting "Submit", the g ...

Dealing with multiple Datepicker components in React hooks

Managing a single instance of Datepicker in a React project is easy, but what about handling multiple instances? The date changes are not reflected on the UI even though they can be seen in the console. What are some efficient solutions to tackle this issu ...

Can Node.js fetch a PHP file using AJAX?

The Challenge: Greetings, I am facing an issue with my website that features a game created using node.js, gulp, and socket.io. The problem arises when I attempt to call a php file from node.js. While the file returns a success message (echo in the file) ...

Problems with JQuery UI buttonset behavior

As I develop a UI application utilizing JQuery UI components, I encounter an issue with aligning radio buttons within the interface. While using JQuery buttonset in isolation functions correctly, integrating it with other UI elements causes misalignment: ...

Collaborative session sharing between two node applications through Single Sign-On (SSO

I currently have a website created with express and node.js. I need to add a nodebb forum to this website, which is a separate node application. Both the main site and the forum use Facebook login, but users have to log in separately using the same Faceboo ...

Is it possible to implement a validation process that prevents the opening of a modal using data-bs-target until all necessary

I am currently using bootstrap version 5.2.3 and I have encountered an issue where the modal opens regardless of validation rules being met or not. I attempted to modify the data-bs-toggle and data-bs-target attributes using Vue.js, but the changes did no ...

The process of making a pop-up modal instead of just relying on alerts

Attempting to change from using an alert to a pop-up with a simple if statement, but encountering some issues. Here is the current code: if(values == ''){ $('body').css('cursor','auto'); alert("Blah Blah..." ...

The element is implicitly assigned an 'any' type due to the fact that an expression of type 'any' cannot be used to index types in nodejs and solidity

I am in need of setting networks in my contract using NodeJS and TypeScript. Below is the code I have written: let networkId: any = await global.web3.eth.net.getId(); let tetherData = await Tether.networks[networkId]; Unfortunately, I encountered ...

Having difficulties fetching data from Express server to React

My current project involves fetching data from an Express server to a React application using the Fetch API. The Express server interacts with a PostgreSQL database to retrieve relevant data that should be sent to the React frontend. The code snippets bel ...

The modal in Bootstrap V5 refuses to hide using JavaScript unless the window method is utilized

Currently in the process of developing a react application and utilizing standard bootstrap. The command to display a modal and switch to one is functioning properly; but, the command to hide the modal does not work unless I establish it as a property on t ...

Tips for removing duplicate objects from an array

I am utilizing the underscore.js plugin in my code I experimented with it on jsfiddle var basket=[{ "basketitems":[{"items":[]}], "itemdetails":[{ "amountPledged": "100", "bActivity": "Handloom Wo ...