Module: E2E

Defined in:
lib/e2e.rb,
lib/e2e/dsl.rb,
lib/e2e/rails.rb,
lib/e2e/driver.rb,
lib/e2e/server.rb,
lib/e2e/element.rb,
lib/e2e/session.rb,
lib/e2e/version.rb,
lib/e2e/minitest.rb,
lib/e2e/assertions.rb,
lib/e2e/drivers/playwright.rb

Defined Under Namespace

Modules: Assertions, DSL, Drivers, Minitest, Rails Classes: Config, Driver, Element, Error, Server, Session

Constant Summary collapse

VERSION =
"0.6.1"

Class Method Summary collapse

Class Method Details

.configObject



29
30
31
# File 'lib/e2e.rb', line 29

def config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/e2e.rb', line 25

def configure
  yield(config)
end

.enable_shared_connection!Object

We only want to apply this when Rails is present and we want to enable it.



21
22
23
24
25
26
# File 'lib/e2e/rails.rb', line 21

def E2E.enable_shared_connection!
  return unless defined?(ActiveRecord::Base)

  ActiveRecord::Base.extend(E2E::Rails::ActiveRecordSharedConnection)
  ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
end

.reset_session!Object



20
21
22
23
# File 'lib/e2e.rb', line 20

def reset_session!
  @session&.quit
  @session = nil
end

.serverObject



33
34
35
36
37
38
39
# File 'lib/e2e.rb', line 33

def server
  @server ||= if config.app
    srv = Server.new(config.app)
    srv.start
    srv
  end
end

.sessionObject



16
17
18
# File 'lib/e2e.rb', line 16

def session
  @session ||= Session.new
end

.wait_until(timeout: config.wait_timeout, interval: 0.05) ⇒ Object

Retry a block until it returns truthy or timeout is reached



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/e2e.rb', line 43

def self.wait_until(timeout: config.wait_timeout, interval: 0.05)
  deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
  loop do
    result = yield
    return result if result

    if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
      return false
    end

    sleep interval
  end
end