Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
##What is the Object Repository? The Object Repository contains a mapping between logical names and selectors for application objects, where each selector is defined by two identifying parameters:
- The type of identifier - for example, id or xpath
- The identifier specifier - continuing the example above, username or //*[@name='welcomeData'], respectively
Read below to learn about:
Object definition format
Each object is defined in the following format (preserve the space locations):
<object-logical-id> = <locatorID>=<specifier>
object-logical-id is the logical name for the object, used by the test script to identify the object. This name is determined solely by the writer of the object definition, and should reflect the object usage to enable easy detection by test writer.
locatorID is the used specification type. For example, id, name, or xpath. The supported specification types are listed in QAF.
specifier is the value of the locator specified by the locatorID. This value depends on the object definition in the application object tree.
Note that no quotation marks are used in object definitions in the Object Repository.
Our best practice recommendation is to organize the Object Repository into page classes, i.e. to define the set of the objects relevant for each of the application pages, separately.
- To define a username field object by its id, where the object's id property value is username, you can define the object-logical-id (object name in your tests) to be field.user, set the locatorID (specification type) to id, and the specifier (id property value) to username, resulting with the complete object definition:
field.user = id=username
- To define a button object by the xpath //*[@type='submit'], you can define the object-logical-id (object name in your tests) to be button.submit, set the locatorID (specification type) to xpath, and the specifier (xpath value) to //*[@type='submit'], resulting with the complete object definition:
button.submit = xpath=//*[@type='submit']
The format of the Quantum Object Repository files is based on the QAF Repository.
##Creating an Object Repository Create a new file under the top resources/ folder of the project, and name it with a .loc extension. We recommend using your application name, or naming by your application pages, for easy detection of application objects by the test developer.
For each application object you wish to define:
Determine an _object-logical-id_ **uniquely** to reflect the object's purpose in your application, and with consideration to its future ease of use.
Set the value of the _locatorID_ using either Perfecto's **Object Spy**, or any other tool such as Firebug / Firepath, Chrome developer tools etc.
Set the value of the _specifier_ according to the specification method you used for the _locatorID_.
You may create a few Object Repositories, either for different tests, or for different application pages.
##Using objects from the Object Repository Quantum tests, both Cucumber (features) and Java, use logical names for objects in the test steps definition. These names are "translated" to Java object selectors by the runner, using the mapping in the Object Repository.
Example: We'll begin with the BDD (Cucumber) version of the example, and later to its Java equivalent.
In BDD, let's assume you insert into the test's feature file the step
Then I enter-text ".*" to ".*"
which you want to use for setting your application username field to "Myname".
Assuming the Object Repository contains this field's object definition as
field.user = id=username
replace the first .* with Myname, and the second - with field.user (leave the " around the value and object). The step would now look like
Then I enter-text "Myname" to "field.user"
In run time, this step is translated by the BDD runner to the java code ``` getDriver().findElement (By.id("username")).sendkeys("Myname"); ``` and "Myname" is entered into your application's username field.
In the Java equivalent, when using the predefined step
you'll replace the value by "Myname" and the locator with "field.user", resulting with
This is also translated in run time (by the Java runner) to
The getDriver() method is part of the QAF methodology. You can simply relate to it as the equivalent of a driver created in standard java tests.