5

Background: As automation testers in selenium world, we have to work on multiple languages/frameworks(wrappers over selenium) in different projects however there is an one thing which remains common across are locators which are essentially tool/framework/language agnostic object description using Xpath or CSS.

Problem Statement:What is the suggested canonical way to define objects/locators in big enterprise level automation projects where common page objects will be utilized across multiple project teams which might be using different UI automation tools like proprietary(UFT)/open source(Selenium) in fact different flavors of selenium frameworks across languages from geographically distributed remote locations.

  • I am considering maintaining xml or json based object locators and define an interface for setters and getters. – Vishal Aggarwal Nov 18 '17 at 19:12
5

It will depend on your circumstances.

Generally I consider categories such as:

  • common identifiers used throughout the application. Examples may include login, logout, help, submit button, etc.

  • identifiers that are used by forms and shared between different workflows

  • identifiers that are specific to the data that a given workflow collects

  • identifier that are specific to one page of one workflow and don't appear in other pages

I store them in a .yml file (so any language could read that) such as

$ cat ~/app/spec/page_objects.yml
...
search_field: "input[name='q']"
...

I'm use rubyist so I'ver chosen to create dynamic methods from this in a PageObject class like this:

class PageObject
  def initialize
    load_page_object_file('spec/page_objects.yml')
  end 
  private
  def load_page_object_file(file)
    page_object = YAML.load(File.read(file))
    page_object.each do |name, locator|
      self.class.__send__ :define_method, name do locator end 
    end 
  end 
end

and then require that file and then instantiate the object with

p = PageObject.new

and then I use the identifiers in this way

fill_in p.search_field, with: 'test'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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