1

I have heard as well as followed concept of keeping UI objects in external filed (xml or properties files in java). But there are times when I need to keep the objects with in test because I use them dynamically.

For example consider one html table with div having uniquq id. The div could have n number of links. I need to read their innertext. So I would be doing -

for(int i=0; i<=CSSCount(div[id='unique']>a);i++) {
    print(selenium.getText(css=div[id='unique']>a:nth-child(i)))

}

So I have app object available in test class it self, that is - css=div[id='unique']>li:nth-child(i) as I need to iterate through its elements. Is it possible to externalize such app objects also?

2 Answers 2

2

Apart from stuartf's comment, I would suggest an approach where when you want to implement things like "as I need to iterate through its elements" to implement them on a generic method and not inside the Test class so as to reuse it (and then it is dynamic).

1
  • Yup I do that, in fact I follow page object model and keep page interaction module out side test.
    – Tarun
    Commented May 11, 2011 at 2:53
1

What you want to do here is change the approach to finding the object, rather than finding the object by id add a consistent class attribute to the each of the divs that you are interested in and find by class rather than the id attribute.

for(int i=0; i<=CSSCount(div[class='row']>a);i++) {
    print(selenium.getText(css=div[class='row']>a:nth-child(i)))
}

Then you can place the 'row' attribute or whatever you decide to call it in a external resource file.

Hope this helps!

1
  • actually I was talking about externalizing entire object that would be - css=div[class='row']>a:nth-child(i)
    – Tarun
    Commented May 11, 2011 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.