Forum Discussion

zeekbiboo's avatar
zeekbiboo
New Contributor
11 days ago

Marking new checkboxes

Hi! I'm new to testcomplete. I'm working on some web tests and I'm learning how to use testcomplete at all.

Well, I wanted to do a test with some checkboxes, the page works in such a way that there are 5 checkboxes per page, being able to increase this number with a list. Once a person is selected and a request is created, their checkbox is disabled so that the chosen user only has one request in progress. Then the next testcomplete run tells me the error that the checkbox is not accessible since it sees it disabled.

Is it possible to tell testcomplete to look for the closest checkbox that is available so that it automatically selects it? 

Oh, sometimes when I use the object spy tool to manually tell testcomplete to check another box that is available at that time simply ignores me and launches the same error, even when I do the highlight thing to see if my mark was on the right spot. Idk why this happens, maybe is a code error

I'm only using keyword test bc I'm so noob with code and scripts. Thank u in advance and have a great day ☀️

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    This might present an opportunity to dabble in scripts.  What you're describing could be accomplished in a very simple script.  That script could then be called/run from your keyword test.  Your keyword test would still be the thing you'd run from the execution plan.  Your simple script would just take care of the checkbox checking part.

    It could be accomplished in ~half a dozen lines in a script.  For instance, the FindChild method would let you find a checkbox that's enabled.  Once found, you could click it directly in the script or in your Keyword test using a project variable.

    Hassan_Ballan's suggestion is a good one too.  However, it might become untenable if the number of check boxes grew well beyond five.  That would require many name mappings.

    • Hassan_Ballan's avatar
      Hassan_Ballan
      Regular Contributor

      JDR2500 you are right in your assessment; however, as a new user and not code savvy I thought a simpler approach would go a long way with zeekbiboo.

      There are many ways to deliver and without specifics it would also be hard to suggest the best approach. I will try to make an example for all interested to pitch in and be on the same page.

    • Marsha_R's avatar
      Marsha_R
      Moderator

      I like this solution, plus I would suggest that you clear out all the checkboxes at some point, maybe at the end of the test, so you know for certain that you are starting with all of them enabled the next time.

    • zeekbiboo's avatar
      zeekbiboo
      New Contributor

      I was thinking the same yesterday, at the end of the day the scripts makes your test go easier and fluent I guess. 

      I'm gonna do some research and start with little footsteps bc as Hassan_Ballan said I'm new to code and those things, so starting simple is the way I like.

      Thank u so much for ur answer and time.

      • Hassan_Ballan's avatar
        Hassan_Ballan
        Regular Contributor

        I envision you can do it by using a single mapping to be used for all checkboxes that always find the first enabled checkbox no matter how long is the list.

        For below examples: In browser change checkbox state, in the TestComplete NameMapping make edits and use the buttons Refresh and Highlight to validate

        1-https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_checkbox_checked2 demonstrate checkbox checked and unchecked
        change the name mapping selector to CSS and set value to
        input:not(:checked)[type='checkbox']

        2-https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_checkbox_disabled2 demonstrate checkbox enabled and disabled
        change the name mapping selector to CSS and set value to
        input:not(:disabled)[type='checkbox']

         

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Regular Contributor

    Hello,

     Refer to https://support.smartbear.com/testcomplete/docs/testing-with/exploring-apps/object-spy/index.html for using Spy. Inspect Spy object detection to look for a property that checks the sate, for example enabled=true. Yo may need to switch the view from basic to advanced view.

    You need to address it in two steps:
    1-The checkbox row, as you have 5 you need to have 5 different mappings one for each
    2-The checkbox state enabled or disabled added to detection properties 

    You could create KeywordTests with following simple logic:
    If checkbox1 property enabled equal true, click it and go to Label
    If checkbox2 property enabled equal true, click it and go to Label
    If checkbox4 property enabled equal true, click it and go to Label
    If checkbox5 property enabled equal true, click it
    Label

    • Hassan_Ballan's avatar
      Hassan_Ballan
      Regular Contributor

      Of course there is also a simpler way to avoid all the if statements, but that requires NameMapping manual manipulation for selectors element XPath, and that also require HTML investigation.

      In the following sample project that use w3schools page for multiple checkbox:
      1-Added on the project level variable "row"
      2-In NameMapping I mapped all three CheckBoxes and manually added a new node ("checkboxVehicleX" with parameterized XPath using the "row" variable) 
      3-In the testcase I set the "row" variable value to 1 and rest cache
      4-Than I use the "checkboxVehicleX" property Exists=true to loop thru and check the box, increment the value and reset the cache

      zeekbiboo if you can dig such project example details, perhaps you can compare your check-boxes elements to find similarities and differences to simulate same approach.

    • zeekbiboo's avatar
      zeekbiboo
      New Contributor

      hi,

      I really appreciate ur solution and thank you for guiding me. I'll dig on some examples like those mentioned, again thank you so much for ur time.

  • scot1967's avatar
    scot1967
    Regular Contributor

    If you haven't seen these articles they may help... 

    Working with Textboxes...

    https://support.smartbear.com/testcomplete/docs/app-objects/specific-tasks/web/check-box.html

    "Is it possible to tell testcomplete to look for the closest checkbox that is available so that it automatically selects it? "

    https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/ai/ocr-action.html#description

    When you add the operation to a keyword test, you specify an area whose text content you want to recognize, the text fragment that identifies the needed part of the area and the method that will simulate user actions.