首页 > 解决方案 > testcafe - 上传文件

问题描述

我需要测试上传屏幕,但 .setFilesToUpload 有问题。没有文件正在上传。

编辑:如果我调试,解锁页面,单击上传文件并选择任何其他文件,该字段将填充脚本文件

我试过了

.setFilesToUpload(Selector('input').withAttribute('type','file'), '../src/assets/logo.png')

.setFilesToUpload(选择器(“#customInputFile”),“../src/assets/icon.png”)

但在这两种情况下,都没有上传文件。屏幕等待它,但没有任何反应。

<template>
  <div>
    <div class="file-container" v-if="!image">
      <label>{{ label }}</label>
      <div class="input-group">
        <input
          type="text"
          @dragover="handleDragAndDrop"
          @dragenter="handleDragAndDrop"
          @dragleave="handleDragAndDrop($event, true)"
          @drop="onFileChange"
          v-bind:class="{ error: dataError }"
          :placeholder="dataPlaceholder"
          :value="dataFileName"
          readonly

        />
        <span class="input-group-btn">
          <button class="file-button" type="button" @click="launchFilePicker">
            SELECT A FILE
          </button>
        </span>
      </div>
      <input
        type="file"
        :value="filePayload"
        @input="onFileChange"
        ref="file"
        id="customInputFile"
        style="display: none"

      />
      <span v-if="dataError" class="errorMessage">{{ dataErrorMessage }}</span>
    </div>
    <div class="file-container" v-else>
      <img :src="image" />
      <button @click="removeImage">Remove image</button>
    </div>
  </div>
</template>

我需要上传文件并通过测试。

标签: vue.jstestingautomated-testse2e-testingtestcafe

解决方案


我只需要在我的输入上添加 onChange 来调用我的脚本,这只是在输入上。

非常感谢


推荐阅读