mirror of
https://github.com/copyrighttxt/watrbx-game-engine.git
synced 2026-09-07 05:57:47 +00:00
GEEKING
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
username: abc1@xyz.com
|
||||
password: Test@123
|
||||
@@ -0,0 +1,2 @@
|
||||
username: abc@xyz.com
|
||||
password: Test@123
|
||||
@@ -0,0 +1,49 @@
|
||||
module DataHelper
|
||||
# Read basics on YAML - http://www.seleniumframework.com/test-data/test-data-with-yaml/
|
||||
def data_yml_hash
|
||||
@data_yml = YAML.load_file "#{data_default_directory}/#{yml_file}"
|
||||
end
|
||||
|
||||
# Read basics on excel parsing - http://www.seleniumframework.com/test-data/test-data-with-excel/
|
||||
def data_excel_hash(data_sheet)
|
||||
workbook = RubyXL::Parser.parse data_default_directory + '/' + excel_file
|
||||
sheet = workbook[data_sheet]
|
||||
header_row = sheet.sheet_data[0]
|
||||
@data_excel = sheet.get_table(header_row)
|
||||
end
|
||||
|
||||
# Json parsing reference - http://www.seleniumframework.com/test-data/test-data-with-json/
|
||||
def data_json_hash
|
||||
@data_json = JSON.parse data_default_directory + '/' + json_file
|
||||
end
|
||||
|
||||
def data_directory_set(dir)
|
||||
@data_directory = dir
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def yml_file
|
||||
ENV['DATA_YML_FILE'] ? ENV['DATA_YML_FILE'] : 'default.yml'
|
||||
end
|
||||
|
||||
def excel_file
|
||||
ENV['DATA_EXCEL_FILE'] ? ENV['DATA_EXCEL_FILE'] : 'default.xlsx'
|
||||
end
|
||||
|
||||
def json_file
|
||||
ENV['DATA_JSON_FILE'] ? ENV['DATA_JSON_FILE'] : 'default.json'
|
||||
end
|
||||
|
||||
def xml_file
|
||||
ENV['DATA_XML_FILE'] ? ENV['DATA_XML_FILE'] : 'default.xml'
|
||||
end
|
||||
|
||||
def data_default_directory
|
||||
@data_directory ||= 'lib/config/data'
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_accessor :data_yml, :data_excel, :data_json, :data_xml, :data_directory
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
module PageHelper
|
||||
# http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/
|
||||
# http://stackoverflow.com/questions/3424782/ruby-on-rails-how-do-i-check-if-a-variable-in-an-instance-of-a-class
|
||||
# http://www.wellho.net/mouth/2601_Ruby-is-a-v-instance-of-what-is-the-difference-.html
|
||||
def visit(page_class, &block)
|
||||
on(page_class, true, &block)
|
||||
end
|
||||
|
||||
def on(page_class, visit = false, &block)
|
||||
page_class = class_from_string(page_class) if page_class.is_a? String
|
||||
page = page_class.new @browser, visit
|
||||
yield page if block
|
||||
page
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# http://stackoverflow.com/questions/3163641/get-a-class-by-name-in-ruby
|
||||
|
||||
def class_from_string(str)
|
||||
str.split('::').inject(Object) do |mod, class_name|
|
||||
mod.const_get(class_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user