Module: Appom::SmartWait

Defined in:
lib/appom/smart_wait.rb

Overview

Smart waiting functionality for Appom automation framework Provides intelligent wait conditions and strategies

Defined Under Namespace

Classes: ConditionalWait, WaitConditions

Constant Summary collapse

DEFAULT_INTERVAL =
0.25

Class Method Summary collapse

Class Method Details

.until_clickable(*find_args, timeout: Appom.max_wait_time) ⇒ Object

Create a wait with clickable condition



366
367
368
369
370
371
372
373
# File 'lib/appom/smart_wait.rb', line 366

def until_clickable(*find_args, timeout: Appom.max_wait_time)
  wait = ConditionalWait.new(
    timeout: timeout,
    condition: WaitConditions.clickable(nil),
    description: 'clickable',
  )
  wait.for_element(*find_args)
end

.until_condition(*find_args, timeout: Appom.max_wait_time, description: 'custom condition', &condition_block) ⇒ Object

Create a wait for custom condition



406
407
408
409
410
411
412
413
414
# File 'lib/appom/smart_wait.rb', line 406

def until_condition(*find_args, timeout: Appom.max_wait_time,
                    description: 'custom condition', &condition_block)
  wait = ConditionalWait.new(
    timeout: timeout,
    condition: condition_block,
    description: description,
  )
  wait.for_element(*find_args, &condition_block)
end

.until_count_equals(*find_args, count:, timeout: Appom.max_wait_time) ⇒ Object

Create a wait for element count



396
397
398
399
400
401
402
403
# File 'lib/appom/smart_wait.rb', line 396

def until_count_equals(*find_args, count:, timeout: Appom.max_wait_time)
  wait = ConditionalWait.new(
    timeout: timeout,
    condition: WaitConditions.count_equals(count),
    description: "count equals #{count}",
  )
  wait.for_elements(*find_args)
end

.until_invisible(*find_args, timeout: Appom.max_wait_time) ⇒ Object

Create a wait for invisible element



386
387
388
389
390
391
392
393
# File 'lib/appom/smart_wait.rb', line 386

def until_invisible(*find_args, timeout: Appom.max_wait_time)
  wait = ConditionalWait.new(
    timeout: timeout,
    condition: WaitConditions.invisible,
    description: 'invisible',
  )
  wait.for_element(*find_args)
end

.until_text_matches(*find_args, text:, exact: false, timeout: Appom.max_wait_time) ⇒ Object

Create a wait for specific text



376
377
378
379
380
381
382
383
# File 'lib/appom/smart_wait.rb', line 376

def until_text_matches(*find_args, text:, exact: false, timeout: Appom.max_wait_time)
  wait = ConditionalWait.new(
    timeout: timeout,
    condition: WaitConditions.text_matches(text, exact: exact),
    description: "text #{exact ? 'equals' : 'matches'} '#{text}'",
  )
  wait.for_element(*find_args)
end

.wait_for_element_clickable(element, timeout: Appom.max_wait_time) ⇒ Object



435
436
437
438
# File 'lib/appom/smart_wait.rb', line 435

def wait_for_element_clickable(element, timeout: Appom.max_wait_time)
  condition = WaitConditions.element_clickable(element)
  wait_until(condition, timeout: timeout)
end

.wait_for_element_visible(element, timeout: Appom.max_wait_time) ⇒ Object



430
431
432
433
# File 'lib/appom/smart_wait.rb', line 430

def wait_for_element_visible(element, timeout: Appom.max_wait_time)
  condition = WaitConditions.element_visible(element)
  wait_until(condition, timeout: timeout)
end

.wait_for_stable_element(element, timeout: Appom.max_wait_time, stable_duration: 1.0) ⇒ Object



450
451
452
453
454
# File 'lib/appom/smart_wait.rb', line 450

def wait_for_stable_element(element, timeout: Appom.max_wait_time, stable_duration: 1.0)
  condition = -> { element.displayed? && element.enabled? }
  wait = ConditionalWait.new(timeout: timeout)
  wait.wait_for_stable_condition(condition, stable_duration: stable_duration, timeout: timeout)
end

.wait_for_text_present(element, text, timeout: Appom.max_wait_time) ⇒ Object



440
441
442
443
# File 'lib/appom/smart_wait.rb', line 440

def wait_for_text_present(element, text, timeout: Appom.max_wait_time)
  condition = WaitConditions.text_present(element, text)
  wait_until(condition, timeout: timeout)
end

.wait_for_text_to_change(element, initial_text, timeout: Appom.max_wait_time) ⇒ Object



445
446
447
448
# File 'lib/appom/smart_wait.rb', line 445

def wait_for_text_to_change(element, initial_text, timeout: Appom.max_wait_time)
  condition = WaitConditions.text_changed(element, initial_text)
  wait_until(condition, timeout: timeout)
end

.wait_until(condition, timeout: Appom.max_wait_time, backoff_factor: nil, max_interval: nil) ⇒ Object



420
421
422
423
424
425
426
427
428
# File 'lib/appom/smart_wait.rb', line 420

def wait_until(condition, timeout: Appom.max_wait_time, backoff_factor: nil, max_interval: nil)
  wait = ConditionalWait.new(timeout: timeout)
  if backoff_factor && max_interval
    wait.wait_until_with_backoff(condition, timeout: timeout, backoff_factor: backoff_factor,
                                            max_interval: max_interval,)
  else
    wait.wait_until(condition, timeout: timeout)
  end
end