Object repository is place where we store all information related to an object. Typically in Quick Test Professional it is an optional part.[Descriptive programming]. But we use it regularly. We depend on QTP to identify object during run time and play back time.
The below written posts you help you to get more details about the same:
- https://www.techtravelhub.com/2010/08/object-identification-in-qtp-while.html
- https://www.techtravelhub.com/2010/09/file-system-operations-in-qtp.html
- https://www.techtravelhub.com/2010/09/object-identification-configuration.html
But when it comes to selenium there are way to store Object’s properties.
In selenium we generally store the xpath or relative paths or locator information.
usrname_txt=//*[@id='username']
passwd_txt=//*[@id='passwd']
The ways you can store these are..
- Excel-Here you need POI jar to read and write
- Notepad/CSV-File operation in java
- XML-File operation
- Class page wise
- Using Inner class[Nested class concept]
Excel will typically Look like-
LogicalName | PropertyType | Propertyvalue |
!Yahoo Home Page | ||
usrname_txt | xpath | //*[@id=’username’] |
passwd_txt | xpath | //*[@id=’passwd’] |
XML format
!Yahoo Home Page
<Object name> usrname_txt <Property type> xpath < Property Value>//*[@id=’username’]
<Object name> findppl_txt <Property type> classname < Property value> searchIconBorder
Notepad format-
username,xpath,//*[@id=’username’]
password,xpath,//*[@id=’passwd’]
Class Page Wise
Class LoginPage{
String userName=By.xpath(//*[@id=’username’])
String password=by.xpath(//*[@id=’passwd’])
…….
……..
}
But these are ok when you are a learner or your test is significantly low in size or time. These methods are not effective when your test is very big in nature or say test will be running for 3 days or 4 days.Also they need either a 3rd party jar like-POI or java’s file handling operation which are not great for architecture point of view when time is a constraint.
So What could be the solution..
I would prefer the inbuilt nested class structure approach should be taken when your test is really big.
let me explain how..
public static class LoginPage{
private static class Login{
String userName=By.xpath(//*[@id='username'])
String password=by.xpath(//*[@id='passwd'])
}
private static class bodyElement{
.......
........
}
Well the advantages for this approach are-
- Since they are static they will be loaded when you are trying to run login class.
- All objects will be available in Primary memory so no delay in execution of the test.
- Readability will be easy but your test will remain huge
- Less dependency on the external jars so delay in getting the data.
- your primary memory will be free from the unwanted code.
- Let JVM decide which objects and data will present on the memory instead of us!!!
- Garbage collection will be effectively fast.[Note we do not have any control on that programming] so helping GC by reducing load will be good from architecture point of view.
}