How to manage elements for testing

Hi everyone,

Now i’m using Appium for testing. So before when i want to find_element with text is Deny Request (just example), i just did:

find_element(:name, 'Deny Request')

But when the app grow bigger, UI change a lot. So if we hard code like that, it’s hard to maintain. So i want to do something like create one file to manage all elements in all screens, but still don’t know which way is best practice we should do.

My idea is create a yml file to save all the text we have in the app, also the id, class as well. So when we want to access any element, we just need to call the right value in that yml file.
The yml file may be like that:

text:
  login:
    signin: "Sign in"
    signup: "Sign up"
  settings:
    alert: "Alert sound"

Anybody has better solution, please help me. Thanks alot.

HI @Vu_Van_Ly,

you can go for page object model, where page objects are grouped by each screen

1 Like

right now i come up with the idea i have before:

text:
  landing:
    language: MY/EN
    en: English
    my: ျမန္မာ
    signin_email: Sign in with email
  signin_email:
    title: Email connect
    email: Email
    forgot_pass: Forgot password?
    signup: Sign up with your email
    not_register: Not yet registered with your email?

I will have an ui.yml file to manage all the text related to UI. And there is a file utils.rb to have some methods like:

require 'settingslogic'
require_relative 'constants'

PACKAGE = 'com.squar.mychat.integration' unless defined?(PACKAGE)
APP_NAME = 'MyChat Integration'
class MyChat < Settingslogic
  source "spec/ui.yml"
end
# Class in android
def pid(id)
  "#{PACKAGE}:#{id}"
end

def fclasses(class_name)
  find_elements(:class, class_name)
end

def fclass(class_name)
  find_element(:class, class_name)
end

def fname(name)
  find_element(:name, name)
end

def fapp_id(app_id)
  find_element(:id, "#{PACKAGE}:id/#{app_id}")
end

def fapp_ids(app_id)
  find_elements(:id, "#{PACKAGE}:id/#{app_id}")
end

def fid(id)
  find_element(:id, id)
end

def fids(id)
  find_elements(:id, id)
end

I use Settingslogic gem to so can access the ui much more fast and convenience.
So we can access element like this:

text(MyChat.text.landing.language).click