Forum Discussion

Craig_Horne's avatar
Craig_Horne
Occasional Contributor
13 years ago

How to set ClientX and ClientY for a recorded button action to -1

Hello,



On a recorded test I wish to be able to set the clientx and clienty for the buttons to -1. This is so where ever the button is on screen it will click the middle of the button. I have created a template that gets the text off the button so it will find that button where ever it is on the screen but because the clientX and clientY are not -1 it will not always click the button.



What I want to do is if someone records a test and it is a button click it will set the clientX and clientY to -1 automatically. Is this something I am able to do without manually changing the properties one by one in the keyword test.



Thanks

Craig

9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    There's no way to do this automatically.



    However, it sounds to me like you're doing a "record and playback" method of developing tests.  My suggestion would be a two step process.



    1)  Manually mapping your components in NameMapping/Aliases

    2)  Manually adding "On Screen Actions" to your keyword tests where you can designate the co-ordinates as you go.



    The only other option, as far as I know, is to do what you suggested, that being going back and re-editing your scripts by hand.
  • Craig_Horne's avatar
    Craig_Horne
    Occasional Contributor
    Ok thanks for that its a shame there is no way to do this as we have people who just want to record their test and don't want to get down to the nitty gritty of things. But the recording of tests are not that good unless the screen is in the exact same place which is why I went down the root of mapping the buttons and creating templates. The setting of the X & Y would have been icing on the cake.



    Thanks for the kind reply.

    Craig
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Well, location of the component on the screen doesn't really have anything to do with the X Y in the click.  That's a relative X Y to the size of the component.  so, if you have a Button.Click(5,10), that's 5 pixels down and 10 pixels right from the top left corner of the button.  Now, if you have screen resolution differences so that the pixels of the button itself are different, that's a different story.  
  • Craig_Horne's avatar
    Craig_Horne
    Occasional Contributor
    My problem is that the button could either be a large button with text and picture or depending on what other buttons there are it could be just an icon sized button. This is why I wanted it to default to -1 as then it just clicks the centre regardless of the button size.
  • Craig_Horne's avatar
    Craig_Horne
    Occasional Contributor
    And the recorded action could be recorded with a large button but when the playback happens the button could be small so the default setting of -1 would solve this major pain.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    So you're playback environment is non-standardized?  That's a little odd.
  • Craig_Horne's avatar
    Craig_Horne
    Occasional Contributor
    Well what happens is we have a ribbon with buttons in for example but the number of buttons will depend on the roles you have when opening up the application so they may move and shift. So instead of having to record the same button clicks but with all the various roles I mapped the buttons so they would be found regardless of where they are on the screen. But because the x and y are not set to -1 it does not work as I would like. Plus we need to test the app at different screen resolutions again affecting the x and y on a button and dont want to record all the same things two or three times.



    Craig
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Ah, gotcha.  That makes more sense then.  Thanks for the clarification!
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Hi Craig,


    As far as I know, if TestComplete recognizes a control as a button, it should record the ClickButton method for it, that is, it should not record coordinates. I don't know what controls your tested application uses, but you can try mapping your button object to an appropriate button object in the Object Mapping properties of your test project. See Object Mapping.