Class: Playwright::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/scene.rb

Overview

Playwright::Scene

Scene is the service layer between your test and page object models. It allows common interactions to be duplicated in tests without letting the tests know too much about the page.

class PurchaseProduct < Playwright::Scene
  sender_accessor :buyer

  def purchase_product(product)
    LoginHelper.(buyer)
    ProductPage.purchase(product.id)
    stage.orders.find_or_add(product.orders.last)
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage, sender, receiver) ⇒ Scene

Returns a new instance of Scene.



21
22
23
24
25
# File 'lib/playwright/scene.rb', line 21

def initialize(stage, sender, receiver)
  @stage = stage
  @sender = sender
  @receiver = receiver
end

Instance Attribute Details

#receiverObject

Returns the value of attribute receiver.



19
20
21
# File 'lib/playwright/scene.rb', line 19

def receiver
  @receiver
end

#senderObject

Returns the value of attribute sender.



19
20
21
# File 'lib/playwright/scene.rb', line 19

def sender
  @sender
end

#stageObject (readonly)

Returns the value of attribute stage.



18
19
20
# File 'lib/playwright/scene.rb', line 18

def stage
  @stage
end

Class Method Details

.receiver_accessor(name) ⇒ Object

Aliases the receiver method to better describe who is receiving the action.

class OrderScene < Playwright::Scene
  receiver_accessor :seller

  def deliver_order(order)
    LoginHelper.(seller)
  end
end


52
53
54
# File 'lib/playwright/scene.rb', line 52

def self.receiver_accessor(name)
  define_method(name, instance_method(:receiver))
end

.sender_accessor(name) ⇒ Object

Aliases the sender method to better describe who the action is coming from.

class OrderScene < Playwright::Scene
  sender_accessor :buyer

  def purchase_product(product)
    LoginHelper.(buyer)
  end
end


37
38
39
# File 'lib/playwright/scene.rb', line 37

def self.sender_accessor(name)
  define_method(name, instance_method(:sender))
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



56
57
58
59
# File 'lib/playwright/scene.rb', line 56

def ==(other) # :nodoc:
  return false unless other.is_a?(Scene)
  stage == other.stage && sender == other.sender && receiver == other.receiver
end