Forum Discussion

kmp2x's avatar
kmp2x
New Contributor
15 years ago

Dealing with dynamic objects

I have several pages needing testing where a set of buttons get dynamically generated (depending on inputs like current date and a preset schedule).  The identifying tags for these objects are always unique - the developers tell me this is required from following a .NET standard - and, as far as I can see, there is no way to know which button does what just by looking at the ID tags.  In a manual test in this situation, the tester would read the text on the page that is parallel with the button to know which one they wanted to click and where it would lead; since the ID tags are being dynamically generated and are unique, I am having trouble figuring out how to write code that will be able to look at the button objects and know which one it wants to click on in order to get to the particular page that is needed for the next step in the test.



The associated text is not always the same either - it's a matter of English comprehension, and I really would prefer to avoid that level of parsing to get past this.



Basically I am curious if anyone has any advice in how to approach this problem - even if it's just "give it up, it's not automatable".


4 Replies

  • There may well be a way to make assumptions based on the layout or ordering of the buttons that you could use, but without knowing a lot more about the app it would be impossible for anyone to make any more specific suggestions along those lines.



    So that leaves only the button text to work with. If you can determine what text is expected on the button you want, then you can use the FindChild method to find the button with that text. But it sounds as if you have doubts about whether you actually can determine the text of the button. I'm not sure what you mean when you say that its a matter of English comprehension; is it not deterministic? Can you not predict what text will appear from a given set of inputs? In principal, that is all that you need to do; it should not be a matter of parsing the text that is on the buttons, but rather of predicting what text should be on the button you want and searching for that.




    If it is deterministic, then there should be no reason to claim that it is inherently non-automatable. But that doesn't mean that automation will be trivial to implement :)







  • Hello Peterson




    What your developers said is correct the ID’s are dynamically generated in .Net when the page is rendered in the browser. You can never rely on them. You have to look for static properties.




    From what you have said I tried to think of a simple example that can match the scenario. 




    Consider a drop down that has the list of continents of the world and when you select some continent a collection of buttons are displayed with text adjacent to the button that tells which country the button corresponds to and let us say when you click any button the details of the respective country are loaded in the following page.  (see the screen shot attached for visualizing). One can only know which button to click and what to expect by reading the adjacent text.(I think thats what you meant by English comprehension) In such a scenario (Like Tony wrote in his post about predicting the outputs) you have to let your script know all the options available and what your script can expect - A simple Switch Case statement will do the job. To perform the click on the right button you ll have to let the script read the adjacent text and match with your exhaustive list of possibilities in you switch case statement.(Almost all such organizations will be in a table so you could browse the cells of the table and click on the button in the cell you need).




    If the combinations are explosive for you to handle what you could do is adopt a intelligent mechanism. you have to override your click function with say - ClickIfRenderd - and this will attempt to click the button only if it is visible on the page else just does nothing and moves to the next line of code. Note that in this case you have write the script of all the buttons that are in the design doc of your application.




    Thankyou




  • kmp2x's avatar
    kmp2x
    New Contributor

    >Hello Peterson


    This is completely off topic, but this has happened several times to me with people from southwest Asia, and it bothers me enough that I want to ask, why do you use this form of address?




    My name is "Kent Peterson". Kent is the personal name, Peterson is the family name. To address a man solely by his family name, without the "Mister", is appropriate in a situation where you are his clear superior in a clear and strict hierarchy, such as the military- it implies superiority. Between two strangers, that form of address is really somewhat insulting - it gets a "just who do you think you are" reaction. Either "Mr. Peterson" (formal) or "Kent" (informal) would be fine (and in fact the internet generally lends itself to informality).  



    It just instantly gets my back up to be talked to that way, and I don't think that's the intended reaction, but as I said it has happened with multiple people from that part of the world.  



    Anyway, thank you both for the advice, you've confirmed what I was pretty sure of already. Going to talk to our devs some more.