如何使用Karate UI Automation上传pdf文件?

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

相关问题:Can upload / download files at Karate Driver?,能否请您帮我创建空手道Ui代码,以便在此结构中上传excel pdf:

<div class="col-sm-6">
                    <div class="form-group shiny-input-container">
                      <label>Faça o upload do seu arquivo</label>
                      <div class="input-group">
                        <label class="input-group-btn">
                          <span class="btn btn-default btn-file">
                            Browse...
                            <input id="file_input" name="file_input" type="file" style="display: none;" data-shinyjs-resettable-id="file_input" data-shinyjs-resettable-type="File" data-shinyjs-resettable-value="" class="shinyjs-resettable shiny-bound-input">
                          </span>
                        </label>
                        <input type="text" class="form-control" placeholder="No file selected" readonly="readonly">
                      </div>
                      <div id="file_input_progress" class="progress progress-striped active shiny-file-input-progress">
                        <div class="progress-bar"></div>
                      </div>
                    </div>
                  </div>

我试图在下面使用此源代码但未成功:

* def uri = 'http://the-internet.herokuapp.com/upload'
    * def uploadSelector = '#file-upload'
    * def submitSelector = '#file-submit'

    # this function is for getting the full path of a file that is necessary to use with selenium sendKeys method when
    # a file. I agree with the fact that every folder in Karate would contain the files used within the feature. Nevertheless
    # having it results in a duplication of files if a lot of features use the same files. In this example I put the file in a
    # separate folder. Maybe a Karate builtin function for retrieving the full path of a file in this specific case would be
    # useful
    * def fullPathFile =
      """
            function(arg) {
             return Java.type('examples.Utility').getFullPath(arg);
            }
      """


  * def pdfFile = fullPathFile('files/pdf-test.pdf')

    Given driver uri
    And waitFor(uploadSelector).input(pdfFile)
    When submit().click(submitSelector)
    And delay(5000)
    Then match driver.text('#content > div > h3') == 'File Uploaded!'
    And match driver.text('#uploaded-files') contains 'pdf-test.pdf'
user-interface karate
1个回答
0
投票

文件上传是浏览器自动化中要解决的一个众所周知的难题。我们需要社区提供一些帮助,但是这是我刚刚使用空手道机器人进行实验的一个演示:https://github.com/intuit/karate/tree/develop/karate-robot

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.