Webdriverio V9:-无法在无头模式下上传文件

问题描述 投票:0回答:1

最近我从 v8 更新到了 v9,文件上传在非无头模式下工作正常。但相同的代码在无头模式下会失败。如果有人帮忙的话那就太好了。

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

代码:

    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();
    }

日志:

[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
javascript selenium-webdriver file-upload webdriver-io
1个回答
0
投票

我可以在不使用 uploadfile() 的情况下上传文件

    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();
    }

github

上也有同样的问题
© www.soinside.com 2019 - 2024. All rights reserved.