Forum Discussion

meghaphophalia's avatar
meghaphophalia
Occasional Contributor
3 years ago

how to import image from system on my application

On my application I want to upload image so for that what steps and code should I add . How to automate this steps.Please refer image.

How to define path in code to upload that image.

Writing code in java script and application is in delphi language.

3 Replies

  • Hey meghaphophalia!

     

    We have a built in method called 'OpenFile' you can use on objects to upload files, like the Open File dialog in windows. 

     

    Below are 2 documents that cover working with Open and Save file dialogs and the OpenFile method itself that you can use to accomplish what you are looking for.

     

    Working With Open File and Save File Dialogs;

    https://support.smartbear.com/testcomplete/docs/app-objects/specific-tasks/openfile-savefile-dialogs.html

     

    OpenFile Method;

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/openfile-method-window-object.html

    • meghaphophalia's avatar
      meghaphophalia
      Occasional Contributor

      I user this code-

      After clicking on open button in application -

       

      Aliases.FR4.FormImageMgr.SpeedButton1.Click() --Click on ... as shown in above attached picture 
      let openWindow = process.Window('#32770','Open')
      openWindow.OpenFile(Project.Path+"...\\Test_Data\\product.jpg")

       

      but it throws error for Process keyword .Can you lemme what to configure about process .

       

       

  • Hi meghaphophalia!

     

    Looks like how you are instantiating your openWindow variable is incorrect. 

     

    What we need to do is create a variable that contains just the 'Sys.Process' for your application, then we run the OpenFile method on your object in the variable. 

     

    Here is the example from the above documentation you can use to build this out.

    function WorkWithFiles()
    {
      var notepad = Sys.Process("notepad");
      var wndNotepad = notepad.Window("Notepad");
      
      // Open a file in Notepad
      wndNotepad.MainMenu.Click("File|Open...");
      notepad.Window("#32770", "Open").OpenFile("C:\\MyFile.txt");
    
      // Save the file to the desktop
      var strDesktop = WshShell.SpecialFolders.Item("Desktop");
      wndNotepad.MainMenu.Click("File|Save as...");
      notepad.Window("#32770", "Save As").SaveFile(strDesktop + "\\MyFile.txt");
    }