Forum Discussion

KB1's avatar
KB1
Champion Level 2
2 years ago

In Headless mode it is not possible to add attachments from a dialog.

We are currently working on creating a test case that involves opening a dialog and selecting a file to use as an attachment. While the test succeeds when run with a visible browser (headed test), it fails when executed in a headless mode (without a visible browser).


I saw another forum post: File upload in headless execution - SmartBear Community
I wanted to know if someone else had this same problem and if so how did you fix it.


So in short I want testcomplete to drag and drop the file on the document

 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    To perform drag and drop actions, requires screen coordinates. I doubt it is possible to do that in headless mode

    • KB1's avatar
      KB1
      Champion Level 2

      You have any other suggestions? it's really important that this works.

       

      because in a headless test that interface is not visible for TC to click on.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        because in a headless test that interface is not visible for TC to click on.

        UI does not exist in headless mode.

        You have just two options possible:

        -- Change your test code so it does not need UI for the action (like inclusion of login/password into URL to avoid authorization dialog for Selenium);

        -- Do not use headless mode.

         

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Is there anyway of interacting with the DOM element? Is it possible to use API call to POST a file?

     

    • KB1's avatar
      KB1
      Champion Level 2

      Thank you for the best help I've ever had.....

    • KB1's avatar
      KB1
      Champion Level 2

      Sorry I thought you were being sarcastic in the other comment haha.

      But yeah that is possible I can see the POST

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Sorry, I just assumed you knew about DOM elements and API's.

         

        See Sending and Receiving HTTP Requests From Script Tests

         

        Here's a small example of POST'ing a JSON message to the URL. 

        function httpPostRequest()
        {
            var requestBody = JSON.stringify({
                title: 'SmartBear',
                body: 'TestComplete',
                userId: 1,
            });
            
            var aqHttpRequest = aqHttp.CreatePostRequest("https://jsonplaceholder.typicode.com/posts");
            
            aqHttpRequest.SetHeader("Content-Type", "application/json");
            aqHttpRequest.SetHeader("Accept", "application/json;charset=utf-8");
            aqHttpRequest.SetHeader("Accept-Charset", "utf-8");
            
            var aqHttpResponse = aqHttpRequest.Send(requestBody);
            
            Log.Message(aqHttpResponse.StatusCode);
            Log.Message(aqHttpResponse.Text);
        }

        You can do something similar, providing your website doesn't require authentication, that is when it gets tricky. You need to construct the POST Header, you can copy the information that you see in DevTools; you then need to attach your file in binary format (I think it's Base64 see post https://community.smartbear.com/t5/TestComplete-Questions/Encrypt-Decrypt-Base64-string-in-TestComplete/td-p/235262). Hopefully, you should be able to upload your file ğŸ¤”. You might require help from your developers!

         

        I don't have dotNET package installed in TC, so I can't provide an example.