Forum Discussion

ciscowaas's avatar
ciscowaas
Occasional Contributor
13 years ago

How to record using objects not co-ordinates

Hi ,



For the following scenario I have seen different behaviors in Win XP and Win7. The recorded script has co-ordinates in case of Win7, but in Win XP, I see the object/actual file name. I need to avoid co-ordinates, how can I do that ?



Test scenario:

Open a network share \\x.x.x.x\dir

Click on some folder X

Double Click on file.doc

Read the file and Close the doc and close the explorer window



Please let me know if anyone tried it before





Thanks

Afroze

5 Replies

  • Hi,



    It looks like you're trying to work with Windows Explorer's UI. If so, this is unreliable since its structure is unstable and is different in different OS versions.



    For your scenario, a better approach is to open the target file without actually clicking it. For example:



    var wshShell = Sys.OleObject("WScript.Shell");

    wshShell.Run("\\\\x.x.x.x\\dir\\X\\file.doc");

  • ciscowaas's avatar
    ciscowaas
    Occasional Contributor
    Thanks Jared. but, our requirement is to open Windows Explorer UI and then click open the file. We optimize the CIFS/SMB traffic, so the behavior differs between opening a UI/double click the file and directly opening a file



    Thats the reason we went with testComplete, otherwise we used JS for testcases to directly open a file and perform operations



    Any other suggestion you have for me ?



    Thanks

    Afroze
  • Hi,



    In this case, post here the script recorded under XP and the one recorded under Windows 7. We need this to check what is wrong exactly.
  • ciscowaas's avatar
    ciscowaas
    Occasional Contributor
    Here are the 2 scripts one with XP and other Win7



    Test scenario:

    Open a network share \\x.x.x.x\dir

    copy a file and paste it in local disk C:\



    Win XP:



    function copy_file_to_local_from_server(p_str_src_path,p_str_dest_path,p_str_file_name)

    {

      var explorer;

      var btnStart;

      var sysListView32;

      var comboBox;

      var edit;

      var wndCabinetWClass;

      var folderView;

      explorer = Aliases.explorer;

      btnStart = explorer.wndShell_TrayWnd.btnStart;

      btnStart.ClickButton();

      sysListView32 = explorer.wndDV2ControlHost.DesktopSFTBarHost.SysListView32;

      sysListView32.ClickItem("Run...", 0);

      comboBox = explorer.dlgRun.ComboBox;

      comboBox.SetText(p_str_src_path);

      edit = comboBox.Edit;

      edit.Keys("[Enter]");

      wndCabinetWClass = explorer.wndCabinetWClass1;

      folderView = wndCabinetWClass.SHELLDLL_DefView.DUIViewWndClassName.DirectUIHWND.CtrlNotifySink.FolderView;

      folderView.ClickItemR(p_str_file_name, 0);

      folderView.PopupMenu.Click("Copy");

      wndCabinetWClass.Close();

      btnStart.ClickButton();

      sysListView32.ClickItem("Run...", 0);

      comboBox.SetText(p_str_dest_path);

      edit.Keys("[Enter]");

      wndCabinetWClass = explorer.wndCabinetWClass;

      folderView = wndCabinetWClass.SHELLDLL_DefView.DUIViewWndClassName.DirectUIHWND.CtrlNotifySink.FolderView;

      folderView.ClickR(350, 300);

      folderView.PopupMenu.Click("Paste");

      wndCabinetWClass.Close();

    }

    // in the above code, we replaced the real file names/ip values with variables, didn't change any thing else in the code



    Win7:

    function Test1()

    {

      var explorer;

      var wndStart;

      var directUIHWND;

      var wndtesting;

      var directUIHWND2;

      explorer = Aliases.explorer;

      wndStart = explorer.wndStart;

      wndStart.ClickButton();

      directUIHWND = explorer.wndDV2ControlHost.DesktopOpenBoxHost.SearchBox.SearchEditBoxWrapperClass.DirectUIHWND;

      directUIHWND.Click(44, 8);

      directUIHWND.Keys("\\\\2.75.253.4\\testing[Enter]");

      wndtesting = explorer.wndCabinetWClass1;

      directUIHWND2 = wndtesting.testing.DUIViewWndClassName.DirectUIHWND.CtrlNotifySink.ShellView.DirectUIHWND;

      directUIHWND2 = wndtesting.ats_cifs_exploratory.DUIViewWndClassName.DirectUIHWND.CtrlNotifySink.ShellView.DirectUIHWND;

      directUIHWND2.ClickR(63, 81);

      directUIHWND2.PopupMenu.Click("Copy");

      wndStart.ClickButton();

      directUIHWND.Click(68, 14);

      directUIHWND.Keys("C:\\[Enter]");

      directUIHWND = wndtesting.ShellTabWindowClass.DUIViewWndClassName.DirectUIHWND.CtrlNotifySink.ShellView.DirectUIHWND;

      directUIHWND.ClickR(142, 28);

      directUIHWND.PopupMenu.Click("Paste");

      explorer.dlgCopyFile.DirectUIHWND.Click(154, 129);

      wndtesting.Close();

      wndtesting.Close();

    }
  • Hi,



    You can try adding the window class of explorer's control which displays the list of files to the 'Win32 Controls and Windows | List view' Object Mapping group (see the Object Mapping help topic). After that, look at this object in the Object Browser. If it has listview-specific properties (such as wItem), and you can get their values, your test should be recorded in the way it was recorded under XP. Otherwise, try enabling MSAA for Explorer's list view (see the Using Microsoft Active Accessibility help topic). This should expose more properties, methods and child objects which should help you to create more reliable scripts.