Adding ids to HTML tags for QA automation
Asked Answered
C

5

10

I have a query In our application we have lots of HTML tags. During development many tags were not given any id because of no requirement.Now the QA team wants to automate the test cases using QTP. In most of the cases this tool doesn't recognizes because it does not find ids for most of the HTML tags.Now we are asked to add ids to all the HTML tags. I want to know if there will be any effect adding id attribute to these tags. Even positive impact are welcome

Charlatan answered 11/8, 2009 at 10:46 Comment(2)
Duplicate: #1231238Intertwine
Add tags "automated-tests", "gui-automation"Oysterman
G
8

I do not think there will be any either positive or negative effect : maybe the size of the HTML page will increase a bit, but probably not that much.

Still, are you sure you need to put "id" attributes on every HTML tag of your pages ? Wouldn't only a few of those be enough ? Like on form fields, on links, on error-messages ; and that's probably about it ?

One thing you must take care, though, is that "id", as in "identifers", must be unique ; which implies it might be good, before starting adding them, to define some kind of "id-policy", to say, for instance, that "ids for elements of that kind should be named that way".

And, for your next projects : have developpers add those when theyr're developping ;-)
(And following the policy, of course)


Now that I'm thinking about it : a positive effect might be that it'll be easier to write Javascript code interacting with your HTML document -- but that'll be true for next projects or evolutions for this one, when those id are already present in the HTML at the time developpers put the JS code in place...

Grammer answered 11/8, 2009 at 10:55 Comment(1)
+1 for the must be unique note. I've been shocked to find many developers believing that this is "just a guideline" and that duplicates are fine. I've tried to advise, but they seem content to sail the Titanic anyway.Pinhead
O
4

Since there are no QTP related answers yet.

GUI recognition in QTP is object-oriented. In order to identify an object QTP needs a unique combination of object's properties, and checking them better to be as fast as possible - that is why HTML ID would be ideal.

Now, where it is especially critical - for objects that do not have other unique identifiers. The most typical example - html tables. Their contents is dynamic, their number on the page may vary. By adding HTML ID you allow recognition mechanism get straight to the right table.

Objects with other unique properties can be recognized well without HTML ID. For example, if you have a single "submit" link on the page QTP will successfully recognize it by inner text.

So the context-specific answer: don't start adding ids to every single tag. Ask automation guys to prepare a list of objects they have problem with. And add ids to those objects.

PS. It also depends on automation programming skills. There are descriptive programming and dynamic recognition methods. They allow retrieving the right objects even without ids provided.

Oysterman answered 11/8, 2009 at 12:13 Comment(0)
F
2

As Albert said, QTP doesn't rely solely on elements' id, in fact due to the fact that many web applications generate different ids for each session, (as far as I remember) the id property isn't part of the default description for most web test objects.

QTP is pretty good at recognizing most simple web controls and if you're facing problems it may be the case that a Web Extensibility project will help you bridge the gap between the semantics of your web application and the raw HTML it is created in. If a complex control is recognized by QTP as a WebElement (which is actually the div that contains the span that drives the code) you will understandably have object recognition problems since there are many divs on the page but probably many less complex controls.

Fanechka answered 11/8, 2009 at 18:12 Comment(0)
H
1

If you are talking about side-effects - NO. Adding ids won't cause any problems (apart from taking up some extra bytes of course)

If you really have the need to add ids, go ahead and add them.

Hushaby answered 11/8, 2009 at 10:53 Comment(0)
P
0

http://www.w3.org/TR/html4/struct/links.html#anchors-with-id says:

The id and name attributes share the same name space. This means that they cannot both define an anchor with the same name in the same document. It is permissible to use both attributes to specify an element's unique identifier for the following elements: A, APPLET, FORM, FRAME, IFRAME, IMG, and MAP. When both attributes are used on a single element, their values must be identical.
Paronym answered 11/8, 2009 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.