Issue with uploading files in headless mode using Webdriverio V9

After upgrading from v8 to v9, I encountered an issue with file uploads in headless mode. The code worked fine in non-headless mode, but failed in headless mode. I would appreciate any assistance with this.

    capabilities: [
        {
            maxInstances: 1,
            browserName: 'chrome',
            acceptInsecureCerts: true,
            'goog:chromeOptions': {
                args: [
                    'headless', 'disable-gpu',
                    '--window-size=1920,1080'
                ],
            },
        },

Code:

    async uploadFile(file) {
        const filePath = path.join(process.cwd(), DEFAULT_FILEPATH, file);
        console.debug("File path: ", filePath);
        const remoteFilePath = await browser.uploadFile(filePath);
        await fileuploadPage.inputFileUpload.setValue(remoteFilePath);
        await fileuploadPage.submitButton.click();
    }

log:

[0-0] RUNNING in chrome - file:///src/test/specs/sanitySuite/test.dscreation.sanity.js
[0-0] File path:  /home/mahadev/Desktop/WDIO_V9_upgrade/ui_automation/src/utilities/files/Reorder.csv
[0-0] Error in "Mammoth Data Source Creation Sanity Tests.File upload @sanity"
Error: The uploadFile command is not available in chrome-headless-shell
    at async Utils.uploadFile (file:///home/mahadev/Desktop/WDIO_V9_upgrade/ui_automation/src/utilities/utils.js:63:32)
    at async Context.<anonymous> (file:///home/mahadev/Desktop/WDIO_V9_upgrade/ui_automation/src/test/specs/sanitySuite/test.dscreation.sanity.js:98:9)
[0-0] FAILED in chrome - file:///src/test/specs/sanitySuite/test.dscreation.sanity.js

 "spec" Reporter:
------------------------------------------------------------------
[chrome-headless-shell 126.0.6478.126 linux #0-0] Running: chrome-headless-shell (v126.0.6478.126) on linux
[chrome-headless-shell 126.0.6478.126 linux #0-0] Session ID: 5b0e1cf78bc61aeeb43979a0a73bc7f6
[chrome-headless-shell 126.0.6478.126 linux #0-0]
[chrome-headless-shell 126.0.6478.126 linux #0-0] » /src/test/specs/sanitySuite/test.dscreation.sanity.js
[chrome-headless-shell 126.0.6478.126 linux #0-0] Mammoth Data Source Creation Sanity Tests
[chrome-headless-shell 126.0.6478.126 linux #0-0]    ✖ File upload @sanity
[chrome-headless-shell 126.0.6478.126 linux #0-0]
[chrome-headless-shell 126.0.6478.126 linux #0-0] 1 failing (14.8s)
[chrome-headless-shell 126.0.6478.126 linux #0-0]
[chrome-headless-shell 126.0.6478.126 linux #0-0] 1) Mammoth Data Source Creation Sanity Tests File upload @sanity
[chrome-headless-shell 126.0.6478.126 linux #0-0] The uploadFile command is not available in chrome-headless-shell
[chrome-headless-shell 126.0.6478.126 linux #0-0] Error: The uploadFile command is not available in chrome-headless-shell

Answer №1

Yes, I have found a way to upload files without using the uploadFile() function.

    async uploadFile(file){
        const filePath = path.join(process.cwd(), DEFAULT_FILEPATH, file);
        console.debug(`File path: ${filePath}`);
        await fileuploadPage.inputFileUpload.addValue(filePath);
        await fileuploadPage.submitButton.click();
    }

You can also find the same question posted on GitHub.

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

Finding the occurrences of elements in an array using JavaScript

While browsing Stack Overflow, I stumbled upon a question that has yet to be answered: How can I count the occurrences of elements in a specific array using JavaScript?. let array = [6, 1, 5, 1, 1, 8, 2, 4, 6, 0] // Elements in array getOccurrence(array) ...

encountering difficulties with installing dependencies using yarn or npm

After cloning a repository, I attempted to install the dependencies using npm install or yarn but encountered the following errors: For Yarn: https://gyazo.com/2fdf52c4956df2e565cc0b1cedf24628 For npm install: https://gyazo.com/a1d197e9ead89dbe4a7d3c5b8f ...

Rest assured, with Ajax Security, your protection is in good

I am currently developing a browser game that heavily utilizes AJAX instead of page refreshes. The combination of PHP and JavaScript is being employed for this project. However, during the course of my work, I became aware of the potential security vulnera ...

The computed function in Vue.js fails to provide a return value

I'm currently experimenting with a basic to-do list using vue.js. My goal is to calculate the total sum of all price values within an array. I created a small function under computed, but it seems like something isn't working correctly. Here&apos ...

three.js fur effect not appearing on screen

I have been working on understanding and implementing fur in three.js. I came across an example at which I used as a reference to comprehend the code. The model loads successfully, but the issue arises when the fur texture doesn't load. I have check ...

Emphasize the present selection along with all prior items in a menu

Attached is my menubar for a unique web design concept I am working on. My webpage is designed as a fully scrollbar page shift type, meaning it is a single page containing six sections that are scrollable by selecting menu items. Currently, when I click ...

A guide on utilizing Puppeteer for capturing screenshots of web pages with embedded videos

Currently, I am using Puppeteer to access a website and capture a screenshot of a video. Unfortunately, the default Chromium browser that Puppeteer uses does not support certain video types. I have managed to get it working by launching Puppeteer with a l ...

What is the best way to set up an on-change listener for material-ui's <CustomInput...>?

I'm currently utilizing the React dashboard created by Creative Tim. I have a question regarding how to set up an onChange listener for a Here is the code snippet for the custom input class: import React from "react"; import classNames from "classna ...

The React.useCallback hook in Cube.js is missing a dependency, specifically 'pivotConfig'. This could potentially cause unexpected behavior in the application

After multiple attempts at creating a straightforward dashboard using Cube.js with Windows 10 and MySQL version 8, I am feeling frustrated. Initially, I experimented with a JavaScript backend, struggled through the installation process for days, then attem ...

Surprising pause in the menu transition animation

Currently, I am in the process of developing a menu that seems to have some flaws. One issue is that it appears a bit choppy, but the more concerning problem is the half-second delay after clicking an item before it animates. The concept behind this menu ...

Retrieve weight measurements from a serial port by using Node JS

I'm a novice in node.js and I'm trying to retrieve weight data from a serial port. I have nodejs(v14.19.0) and npm(6.14.16) installed, and I'm attempting to obtain weight data using localhost:8080/get_weight. However, the script isn't f ...

What is the proper way to delete a callback from a promise object created by $q.defer() in AngularJS?

When working with AngularJS, the $q.defer() promise object has the ability to receive multiple notify callbacks without overwriting previous ones. var def = $q.defer(); def.promise.then(null, null, callback1); def.promise.then(null, null, callback2); If ...

The updating of input and output does not happen instantly; there is a delay before changes

Having an issue with updating input values in React. When using the setState method, the console log does not show the updated input value immediately. For instance, typing "a n" into the input only logs "a" after the second keystroke... Although I under ...

Distance between cursor and the conclusion of the text (autofocus)

I discovered a method to automatically position the cursor at the end of a string using autofocus: <input name="adtitle" type="text" id="adtitle" value="Some value" autofocus="" onfocus="this.setSelectionRange(this.value.length,this.value.length);"> ...

Refreshing the display in an AngularJS directive

I've developed a custom directive for handling file uploads in my AngularJS application. The directive is used in multiple places, including on the same page more than once. Each instance of the directive is supposed to display the uploaded file name ...

Is there a way to display the specific information of a flatlist item in a pop-up window?

Welcome to the HomesScreen.js! This section handles rendering the flat list elements. import { StatusBar } from 'expo-status-bar'; import { Button, Image, Modal, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { ...

Find the corresponding value of a given id in Python

Is there a way to retrieve the title and its corresponding href based on a specific id provided as input? Check out this example code snippet stored in a .Json file: [ { "id": 1, "title": "Argentina", "hre ...

Is it possible to link multiple references to a single Element/Node?

I am working on a function component that needs to pass the incoming ref from the parent to a div it is rendering. Additionally, I want to create and assign a separate ref inside the component to the same div. However, due to an element only accepting one ...

Exploring selenium for automating tests on a Facebook Messenger bot. Tips for efficiently identifying user input and bot responses within the chat interface

We are currently working on automating the testing process of a Facebook Messenger bot by using Selenium. Our main challenge is locating the messenger's text box using XPath, but unfortunately, we have been unsuccessful so far. Below is the snippet ...

Categorize messages based on the date they were last read in Angular

I am looking to organize my chat application messages by date, similar to the layout in Microsoft Teams app. Here is an example of the message data: [ { "id": 577, "source": { "userID": 56469, ...