Created
October 6, 2016 14:16
-
-
Save enriquesanchezb/f336eb2c4b16b4068992c33cd267a306 to your computer and use it in GitHub Desktop.
Appium Actor models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pages | |
def initialize(driver) | |
@driver = driver | |
end | |
end | |
class LoginPage < Pages | |
def fill_form | |
puts "#{@driver} fill form" | |
end | |
def submit | |
puts "#{@driver} submit" | |
end | |
end | |
class MainPage < Pages | |
def shown? | |
puts "#{@driver} true" | |
end | |
end | |
class ActorFactory | |
def ActorFactory.create actor,driver | |
{ :Android => AndroidActor, :iOS => IOSActor }[actor].new(driver) | |
end | |
def method_missing(m, *args, &block) | |
className = "#{m.capitalize}Page" | |
object = Kernel.const_get(className).new(@driver) | |
if block_given? | |
object.instance_eval &block | |
end | |
object | |
end | |
end | |
class AndroidActor < ActorFactory | |
def initialize(driver) | |
puts "Connecting android" | |
@driver = "Android + #{driver}" | |
end | |
end | |
class IOSActor < ActorFactory | |
def initialize(driver) | |
puts "Connecting iOS" | |
@driver = "iOS + #{driver}" | |
end | |
end | |
# ------------------------------- # | |
rider_android_one = ActorFactory.create :Android, "Android Capabilities 1" | |
rider_android_two = ActorFactory.create :Android, "Android Capabilities 2" | |
rider_ios_one = ActorFactory.create :iOS, "iOS Capabilities 1" | |
rider_android_one.login do | |
fill_form | |
submit | |
end | |
rider_android_two.login do | |
fill_form | |
end | |
rider_ios_one.main.shown? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment