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

Include an additional tag solely by using a specific set of keys predetermined in advance

After getting inspiration from Stackoverflow, I decided to enhance my text-box with a tagging feature. The first step was downloading and adding the http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js file to my ASP.NET web folder, allowing me to u ...

What is the best way to incorporate markers into my d3 line chart that includes two separate datasets?

In my JavaScript code, I'm creating a line chart for two datasets using the d3 library with Vue framework integration. Within the HTML code, there are buttons that trigger the updateData function to display the line charts for the respective datasets ...

Preventing file overwriting using fs.writefile method

Encountering an issue where the data being saved from a chat room built with socket.io in nodejs is constantly overwritten upon submission of a message. The desired outcome is to append both the username and message to the JSON file as an object, rather th ...

Issue with retrieving data using AngularJS Restangular

I've been trying to figure out how to make restangular work properly. When I call my API (using the endpoint /user) I receive the following JSON response: { "error": false, "response": { "totalcount": 2, "records": [{ "id": "1", ...

TranslateY animation glitching

I need help with expanding a box to 100% height after click, then collapsing and sticking to the bottom. I created a function in Vue framework to handle the animation, but it's not working smoothly. How can I make it less buggy? Check out the demo her ...

Redux repeatedly triggers re-rendering despite the absence of any changes in the state

This is my first venture into React-Redux projects. I was under the impression that React only re-renders when a component's state changes. However, I am currently facing confusion. The component is being re-rendered every 1 to 3 seconds even thoug ...

How can we determine the nL and nH values using an ESC/POS command?

Looking to adjust the printer's head position using ESC / pos commands: ESC $ command sets the absolute horizontal position ESC $ nL nH Trying to figure out how to calculate the values for nL and nH? ...

Configuration failed: Maven was not able to run the @BeforeTest method for TestNG tests using Selenium

Hey there! I'm currently setting up my Selenium script with Maven and TestNG in Eclipse. To start, I simply right click on my project, select TestNG, then Convert to TestNG (which creates a testing.xml file). Next, I head over to Run Configurations t ...

Having difficulty executing the Cypress open command within a Next.js project that uses Typescript

I'm having trouble running cypress open in my Next.js project with Typescript. When I run the command, I encounter the following issues: % npm run cypress:open > [email protected] cypress:open > cypress open DevTools listening on ws: ...

Trigger function when the element is generated

Is there a way to execute a function only once while still having it run each time a new element is created using v-for? <div v-for"value in values"> <div @ function(value, domElement) if value.bool===true @> </div> ...

The Vue.JS application encountered an error while making an API request, resulting in an uncaught TypeError: Cannot read properties of undefined related to the 'quote'

<template> <article class="message is-warning"> <div class="message-header"> <span>Code Examples</span> </div> <div class="message-body"> ...

Item could not be located in the storage - it is possible that the content has been altered since the last search was conducted

Currently, I am utilizing the Watir webdriver to automatically click on all links that share the same title within a webpage. browser.links(:title => 'Hide week').each(&:click) However, I occasionally encounter an error message that rea ...

The query encoding function of the NextJS router

Encountering an issue while trying to open a new page using NextJS router. The parameter was passed as follows: router.push({ pathname: '/', query: { id: '12344567' }, }) Occasionally, the page redirects to something like: /%3Fid ...

Guide on accessing values from an array of objects in JavaScript/Node.js

I am working with an array of objects that looks like this: const objArray = [{prop: "a", prop2 : "1"}, {prop: "b", prop2 : "2"}, {prop: "c"}, prop2 : "3"] My goal is to extract the property names of the objects in the array, rather than their values. D ...

Locate and eliminate the item containing specific content

There are many <p> &nbsp </p> tags scattered throughout the description. I need to locate and delete any tags that contain only &nbsp. The description is enclosed in a container with the class name of desc_container. Below is an exampl ...

Is it possible to trigger a click on the Submit button using the 'browser.find_element_by_class_name' in simulation?

The structure of the page's source code is shown below: <div class="inner1"> <!--<h4>LOGIN:</h4>--> <div class="SubID" style="float:left; margin-left:30px;"> <label for="ID">Your <span class="subsc ...

Here is a list of selections that can be easily removed and have a child selection added

While this question may be a bit ambiguous, please bear with me as I explain my dilemma. I am utilizing React to develop a component that accepts an object with keys and values as a prop. Each value within the object is a list of values. This component ne ...

What is the best way to upload a file to Firebase Storage using React?

I am facing difficulty uploading a file to Firebase in order to retrieve its getDownloadURL. This is the code snippet I currently have: import React, {useState, useEffect} from 'react' import { Container, Button, Row, Col, Form, Alert } from &ap ...

The componentDidUpdate method is functioning by comparing the previous state with the current state on different triggers

I have a primary element that is invoking another element with specific attributes. // Primary Element <SecondaryElement className="EnterNumber-input" submitClicked={this.state.submitClicked} /> Upon clicking a button, I am modify ...

Guide on efficiently inserting values into an array of objects

I'm looking to extract specific values from the enum below enum p { XDR = 1, PT1M = 2, PT1M_ = 2, PT5M = 3, PT5M_ = 3, PT15M = 4, PT15M_ = 4, PT1H = 5, PT1H_ = 5, P1D = 6, P1D_ = 6, P7D = 7, P1W = 7, ...