saucelab 中的 webdriverIO 文件上传失败

webdrvierIO file uploading is failing in saucelab

WebdrvierIO 文件上传失败,

代码:

const testFilePath = 'C:/Users/num/Downloads/name-src-ips-work-manager-IPSEsignScenarios/name-src-ips-work-manager-IPSEsignScenarios/test/support/data/ClientGeneralAccountAgreement.pdf';
        //const testFilePath = `../support/data/ClientGeneralAccountAgreement.pdf`;
        const fileUpload = $('.form-upload-textbox');
        browser.execute(
            // assign style to elem in the browser
            (el) => el.style.display = 'block',
            // pass in element so we don't need to query it again in the browser
            fileUpload
        );
        fileUpload.waitForDisplayed();

        //const filePath = path.join(__dirname, 'path/to/your/file');
        fileUpload.setValue(testFilePath);

    browser.pause(8000);

错误日志:

script is working in local execution whereas failing in sauce lab [chrome 79.0.3945.79 Windows #0-0] invalid argument: File not found : ./test/support/data/BestInterestAdviceModel.pdf (Session info: chrome=79.0.3945.79) (Driver info: chromedriver=79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}),platform=Windows NT 10.0.10586 x86_64) [chrome 79.0.3945.79 Windows #0-0] Error: invalid argument: File not found : ./test/support/data/BestInterestAdviceModel.pdf [chrome 79.0.3945.79 Windows #0-0] (Session info: chrome=79.0.3945.79) [chrome 79.0.3945.79 Windows #0-0] (Driver info: chromedriver=79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}),platform=Windows NT 10.0.10586 x86_64) [chrome 79.0.3945.79 Windows #0-0] at endReadableNT (_stream_readable.js:1064:12) [chrome 79.0.3945.79 Windows #0-0] at [chrome 79.0.3945.79 Windows #0-0] at documentUpload (/builds/test-engineering/testing-projects/testing-src/name-src-ips-work-manager/test/support/utils/index.js:78:14) [chrome 79.0.3945.79 Windows #0-0] at some (/builds/test-engineering/testing-projects/testing-src/name-src-ips-work-manager/test/support/pages/wizardPage.js:54:9) [chrome 79.0.3945.79 Windows #0-0] at Array.some () [chrome 79.0.3945.79 Windows #0-0] at WizardPage.selectAndUploadForm (/builds/test-engineering/testing-projects/testing-src/name-src-ips-work-manager/test/support/pages/wizardPage.js:52:16) [chrome 79.0.3945.79 Windows #0-0] at World. (/builds/test-engineering/testing-projects/testing-src/name-src-ips-work-manager/test/support/step_definitions/common.js:17:20)

您不能像在本地计算机上那样在云中上传文件(不管是 Sauce Labs 还是其他云供应商)。云 VM 无权访问您的本地文件系统。

Sauce Labs 结合 WebdriverIO 有 2 种可能的解决方案。

  1. Chrome only: 有一个 Chrome only solution with browser.uploadFile(localPath)

  2. Pre-运行 可执行文件: 通过 Sauce Labs,您可以使用 Pre-运行 可执行文件将文件上传到VM,然后使用该文件上传 在你的申请中。

你可以在这里查看它们https://github.com/saucelabs-sample-test-frameworks/WebdriverIO-download-upload

NOTE: You should wonder if testing uploading a file is really something you need to do through the frontend. UI tests tend to be flaky and testing file uploads make them even more flaky.