This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
@@ -0,0 +1,15 @@
def something_present(text)
begin
@wait = Selenium::WebDriver::Wait.new(timeout: WAITTIME)
@wait.until { find_element(:accessibility_id, text).displayed? }
@something_displayed = find_element(:accessibility_id, text).displayed?
rescue
@something_displayed = false
end
@something_displayed
end
def debug
require 'pry'
binding.pry
end
@@ -0,0 +1,14 @@
class GamePage < GenericBasePage
if ENV['OS'] == 'ios'
element(:games_navbar) { |b| b.button_exact('GAMES') }
element(:game_button) { |b| b.find_ele_by_attr('UIALink', 'name', 'Swimming test') }
# element(:play_button) { |b| b.ele_index('UIALink', 2) }
# element(:play_button) { |b| b.find_ele_by_attr('UIALink', 'name', 'Play') }
# element(:play_button) { |b| b.find_element(:xpath, '//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAWebView[1]/UIALink[2]/UIAStaticText[1]') }
element(:play_button) { |b| b.find_element(:xpath, "//UIAStaticText[@name='Play']") }
else
element(:games_navbar) { |b| b.text_exact('Games') }
element(:game_button) { |b| b.find_element(:accessibility_id, 'Swimming test Swimming test 0 Playing ') }
element(:play_button) { |b| b.find_element(:accessibility_id, 'Play') }
end
end
@@ -0,0 +1,51 @@
class GenericBasePage
def initialize(browser, visit = false)
@browser = browser
goto if visit
# respond_to? is a Ruby method for detecting whether the class has a particular method on it
expected_element if respond_to? :expected_element
has_expected_title? if respond_to? :has_expected_title?
end
def method_missing(sym, *args, &block)
@browser.send sym, *args, &block
end
def self.page_url(url)
define_method 'goto' do
@browser.goto url
end
end
# This is a class level method
class << self
alias direct_url page_url
end
# Even this is a class method. Just another way to specify. So either class << self or self.method are same
# Class methods are for anything that does not deal with an individual instance of a class
def self.expected_element(type, identifier, timeout = 30)
define_method 'expected_element' do
@browser.send(type.to_s, identifier).wait_until_present timeout
end
end
def self.expected_title(expected_title)
define_method 'has_expected_title?' do
has_expected_title = expected_title.is_a?(Regexp) ? expected_title =~ @browser.title : expected_title == @browser.title
raise "Expected title '#{expected_title}' instead of '#{@browser.title}'" unless has_expected_title
end
end
def self.element(element_name)
define_method element_name.to_s do
# yield self enters block, associated with method call, passing current object as argument to the block
yield self
end
end
class << self
alias value element
alias action element
end
end
@@ -0,0 +1,7 @@
class LaunchPage < GenericBasePage
element(:login) { |b| b.button('Login') }
element(:signup) { |b| b.button('Sign Up') }
element(:playnow) { |b| b.button('Play Now') }
element(:moreinfo) { |b| b.button('More Info') }
element(:version) { |b| b.last_text }
end
@@ -0,0 +1,37 @@
class LoginPage < GenericBasePage
include PageHelper
include DataHelper
element(:username) { |b| b.first_textfield }
element(:password) { |b| b.last_textfield }
if ENV['OS'] == 'android'
element(:signin_button) { |b| b.button_exact('Login') }
else
element(:signin_button) { |b| b.button_exact('Log in') }
end
def login(usrname = 'usertest01', passwd = 'hackproof')
username.send_keys usrname
password.send_keys passwd
hide_keyboard if ENV['OS'] == 'android'
signin_button.click
end
def login_yml(options = {})
options = options.with_indifferent_access
options.to_hash.reverse_merge! data_yml_hash.with_indifferent_access
username.send_keys data_yml_hash['username']
password.send_keys data_yml_hash['password']
signin_button.click
end
def launch_login(usrname, passwd)
on(LogoutPage).logout unless login_button_present
wait { on(LaunchPage).login }.click
login(usrname, passwd)
end
def login_button_present
exists { on(LaunchPage).login }
end
end
@@ -0,0 +1,31 @@
class LogoutPage < GenericBasePage
include PageHelper
element(:more) { |b| b.find_element(:accessibility_id, 'MORE') }
# 9 for tablet, 7 for iphone
if ENV['FF'] == 'phone'
element(:settings) { |b| b.button(7) }
else
element(:settings) { |b| b.button(9) }
end
element(:logoutlink) { |b| b.find_element(:accessibility_id, 'Logout') }
element(:confirm_logout) { |b| b.button_exact('Log Out') }
def logout
if on(LoginPage).login_button_present
sleep 20 if ENV['OS'] == 'android'
puts 'AUTO: already logout'
else
more.click
case ENV['OS']
when 'ios'
settings.click
logoutlink.click
when 'android'
logoutimage.click
end
confirm_logout.click
end
wait_true { on(LaunchPage).login }.displayed?
end
end
@@ -0,0 +1,35 @@
class ProfilePage < GenericBasePage
include PageHelper
element(:more) { |b| b.find_element(:accessibility_id, 'MORE') }
# 1 for tablet, 2 for iphone
if ENV['FF'] == 'phone'
element(:profile) { |b| b.button(2) }
element(:my_game) { |b| b.find_ele_by_attr('UIALink', 'name', 'Basic Character Automation') }
element(:play_button) { |b| b.find_ele_by_attr('UIALink', 'name', 'Play') }
else
element(:profile) { |b| b.button(1) }
element(:my_game) { |b| b.ele_index('UIALink', 9) }
element(:play_button) { |b| b.find_element(:xpath, "//UIAStaticText[@name='Play']") }
end
element(:creations) { |b| b.find_ele_by_attr('UIALink', 'name', 'Creations') }
element(:grid_view) { |b| b.button('Grid View') }
def profile_game
more.click
case ENV['OS']
when 'ios'
wait { profile }.click
wait { creations }.click
wait { grid_view }.click if ENV['FF'] == 'phone'
wait { my_game }.click
if ENV['FF'] == 'phone'
wait { play_button }.click
else
wait { play_button }
Appium::TouchAction.new.tap(x: 815, y: 315).perform
end
when 'android'
end
end
end
@@ -0,0 +1,65 @@
class SignupPage < GenericBasePage
include PageHelper
include DataHelper
element(:accept_button) { |b| b.button_exact('Accept') }
element(:signup_button) { |b| b.button_exact('Sign Up') }
element(:validating_button) { |b| b.button('Validating') }
case ENV['OS']
when 'android'
element(:username) { |b| b.textfield('signupUsername') }
element(:password) { |b| b.textfield('signupPassword') }
element(:confirm_password) { |b| b.textfield('signupPasswordConfirm') }
element(:male_button) { |b| b.button('rbxGenderPickerMale') }
element(:female_button) { |b| b.button('rbxGenderPickerFemale') }
element(:month) { |b| b.find_element(:xpath, '//android.widget.RelativeLayout[1]/android.widget.Spinner[1]/android.widget.TextView[1]') }
element(:day) { |b| b.text('--') }
element(:year) { |b| b.text('----') }
when 'ios'
element(:username) { |b| b.textfield(1) }
element(:password) { |b| b.textfield(2) }
element(:confirm_password) { |b| b.textfield(3) }
element(:male_button) { |b| b.button('Gender Male') }
element(:female_button) { |b| b.button('Gender Female') }
element(:birthday_button) { |b| b.button(4) }
element(:month) { |b| b.first_ele('UIAPickerWheel') }
element(:day) { |b| b.find_element(:xpath, '//UIAPickerWheel[2]') }
element(:year) { |b| b.last_ele('UIAPickerWheel') }
end
def sign_up(usrname, passwd)
name = Random.firstname + Random.lastname + Random.number(999).to_s
usrname = 'Appium' + name[0..13] if usrname == 'new'
username.send_keys usrname
password.send_keys passwd
confirm_password.send_keys passwd
case ENV['OS']
when 'android'
hide_keyboard
male_button.click
month.click
wait { text('Aug.') }.click
day.click
wait { text('1') }.click
year.click
wait { text('2012') }.click
# wait { signup_button }.click
# sleep 20 # wait for processing in GT2 and click twice, maybe capcha issues.
when 'ios'
female_button.click
birthday_button.click
# workaround on iOS for issue https://groups.google.com/forum/#!topic/appium-discuss/uYdRTdQDvpU
if ENV['FF'] == 'tablet' # iPad Mini
swipe(start_x: 306, start_y: 405, end_x: 306, end_y: 329, duration: 500)
swipe(start_x: 511, start_y: 405, end_x: 511, end_y: 329, duration: 500)
else
swipe(start_x: 80, start_y: 270, end_x: 80, end_y: 170, duration: 500) # June
swipe(start_x: 150, start_y: 270, end_x: 150, end_y: 170, duration: 500) # 11
end
year.send_keys '2006'
accept_button.click
end
wait { signup_button }.click
usrname
end
end