Forum Discussion

ninadnaik's avatar
ninadnaik
New Contributor
2 years ago

File upload in headless execution

Hi Everyone !

 

We are using TestComplete to configure the test cases and TestExecute to execute test cases of VM. We recently added (recorded) test case which contain information upload using file upload dialogue box on a web page. The test case executes successfully in head mode but fails in headless mode (Chrome). In the headless mode, the test case fails at the step of clicking on the "Choose File" button with error "Unable to click the control". We tried with keys command but file is not uploaded. We have following element on the web page -

 

<input type="file" file-upload="" ng-model="tempVO.uploadFile" name="tempVO.uploadFile" ng-init="tempVO.uploadFile=''" groupid="" data-opt="noValue" 
class="ng-pristine ng-scope ng-invalid ng-invalid-required ng-touched" aria-invalid="true" style="">

 

We have written following script -

 

var ichrome= Sys.Process("chrome", 1)
var page = ichrome.Page("*")

fileuploadfield = page.FindChildByXPath("//*[@type='file']")
fileuploadfield.Keys("D:\\workspace\\TestComplete\\test_upload.xls")

 

The above script is not giving any error but file is not getting uploaded.

 

Thanks in advance

7 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I guess the Open Dialog is an actual GUI, so in headless mode that won't work ğŸ¤”

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Is there any other way that we can perform file upload in headless mode?

       

      This is the source file of that file upload object.

      div data-testid="DropZone" class="jss202">
         <div class="jss199">
            <div class="jss196">
               <div role="button" tabindex="0" style="height: 100%; width: 100%; justify-content: center; display: flex; align-items: center;">
                  <input data-testid="dropZone" multiple="" type="file" autocomplete="off" tabindex="-1" style="display: none;">
                  <div class="jss198">
                     <span class="MuiButtonBase-root MuiIconButton-root jss205" tabindex="0" role="button" aria-disabled="false">
                        <span class="MuiIconButton-label">
                           <svg class="MuiSvgIcon-root jss204 MuiSvgIcon-colorPrimary MuiSvgIcon-fontSizeSmall" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
                              <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm5 11h-4v4h-2v-4H7v-2h4V7h2v4h4v2z"></path>
                           </svg>
                        </span>
                        <span class="MuiTouchRipple-root"></span>
                     </span>
                     <span class="MuiBox-root jss212 jss200">
                        <p class="MuiTypography-root jss206 MuiTypography-body1">Drag and drop files here, or click to browse</p>
                     </span>
                  </div>
               </div>
            </div>
         </div>
      </div>

       When I use this code as below it's not working as it says that particular object not found

      Aliases.uploadPage.FindElement("input[data-testid='dropZone']").SendKeys("path for file")

      Is something wrong I am doing here?

       

      Screenshots of the webpage

       

    • ninadnaik's avatar
      ninadnaik
      New Contributor

      Yes, we are are using supported browser. All test cases are working fine, except upload file.

      • tvklovesu's avatar
        tvklovesu
        Frequent Contributor

        Hi ninadnaik , I am experiencing similar issue where I need to upload a file on to my webpage and when I run from local it runs fine. But when I run the test on headless from Remote server which has Test execute on Linux machine it's not able to file the file uploader pop-up. 

        Have you able to figure out how to upload the file?

        TIA

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      rraghvani, I looked into that and that's again same as what I tried. The issue here is that I am running the test on selenium grid in Linux machine. There is not Explorer in the machine and will not have any dialog box opened. I want something that can upload file without the dialog box

      Thanks