How to organize Object repository and multiple browser in selenium?
Is there any approach in selenium to handle Object Repository. Also I am looking a way to deal with multiple browser. please find the below scenario:
Scenario1: I want to place all object locators under one place (page wise) then I can use these page and create library functions using these objects. This will help me to avoid changes in library function even if the object changes (as need to change only locator).
Scenario2: I would like to create functions which can deal with multiple browser. If the function require to act on specific browser then it should be able to activate and perform action on that browser.
(I have used QTP, Silk test, RFT. There is common concept of OR (object repository).)
I have attached very basic diagram to understand the scenario.
Any pointers will be really useful.
Last edited by shyamgh; 03-04-2014 at 03:31 AM.
Reason: Adding attachment
Most people will use PageObject / PageFactory pattern.
All interaction code is written using the WebDriver interface. So different webdrivers can be substituted at run time. If you have say variation in content / page logic being served up. Then you can take PageFactory one step further and do an AbstractPageFactory pattern.
Thanks for quick reply.
Its good suggestion, however, I have used selenium RC and new to WebDriver. Can anyone help me with raw sample code for the above solution, it will be really a great help.
Which Language are you scripting on?
Depending on that you could use a property file(Java) or simple file(Ruby, Python) or Yaml file to hold the property/value pairs, load & access the pairs later.
Actually, I am looking for an approach about how to organize OR+Library+Test with robust implementation (object locators read from XML/property file as you suggested).
Some information, the AUT has multiple pages. So I was thinking about an approach in which there would be page wise OR and library functions. However should the Page OR be placed separate from library function or how should it be?
Please find attached samples (code I taken from google search) for more information.
LoginPage: Page wise Repository I am trying to create.
SampleTest: Utilization of this OR. (currently I have placed function in same test file, it will be in library)
Looking for suggestion about better approach of this implementation.
Any pointers are really valuable.
The idea of object mapping in QTP and other native tools is there because object mappings on native devices are sensitive to mappings of their parent elements. With Web Apps, this isn't the case, you have more powerful XPath and CSS selectors, so a separate mapping layer with XML hierarchy is not needed.
I think you're on the right track originally. Just store they locators either as By objects, or strings. Then pass them into to create those objects at instantiation. (In Webdriver you can use the @WebElement() annotation to handle this.)
I would recommend having all the locators in a separate file. Whether you want have a separate file for each page or all in one file is up to you. It's just a matter of importing/loading a single or multiple module/file into the test.
Pass the Objects from the OR module/file to the Functions from the Test.
There are no attachments in your post.
The attachments are in the very first post. As per you suggestion we can have this structure, however the main issue I think is overhead of passing OR to functions which has to be done by caller-test. So here the test case handle OR instead of function. Lets take below example:
-AUT has 20 pages
-Each page has 30 object (locators in file we can say).
-For each page there are 20 functions acting on objects.
-There are 50 test cases/page
in this kind of scenario, what is best component to take responsibility of object information? Is it test or function?
If we say this has to be done by test case then the overhead of test case will increase as it has to first collect each object information before calling function as well as manage data. Also the function design will be complex as per this implementation, as function has to take object information and then act on that object.
Can you give raw example based on above scenario?
Take a look at the PageObject based Python Tests from Mozilla.
Locators are placed within PageObjects & you don't have to pass them from the test.
Hope this helps.
A good way of thinking of PageObjects is to think of it as writing a backend API service. PageObject basically takes UI actions (in selenium) and expose them in object form as API calls that can be consumed by your test.
I think mozilla's example overcomplicates things by their use of pointers.
Personally I prefer to use Lambdas in Python., it simplifies the mappings section of the page object.
In those two examples, I basically created 2 page objects that encapsulates "search" as a service call.
Tags for this Thread