Git Product home page Git Product logo

Comments (4)

Daniel-ltw avatar Daniel-ltw commented on May 22, 2024
      sleep(@browser.slowmo) if slowmoable && @browser.slowmo > 0

Is this part of addressing this?
Was thinking of just doing a sleep on slowmo define time, we can just do an interval loop to wait on a specific element on the page to show.

Because of this sleep, my current test run seems to take too long to complete.

from ferrum.

Daniel-ltw avatar Daniel-ltw commented on May 22, 2024

This is my hacky attempt in my own spec_helper.rb. Rather than just using slowmo.

def wait_for(css_element, visibility: :all)
  @staled_retries ||= 120
  element = first(css_element, visible: visibility, wait: 0.3)
  warn_log "Found #{css_element}"
  yield(element) if block_given?
  element
rescue Capybara::ElementNotFound, Capybara::ExpectationNotMet => e
  warn_log "#{css_element} stale for: #{@staled_retries}"
  if @staled_retries.zero?
    page_path = save_page
    screenshot_path = save_screenshot
    debug_log "Page at #{page_path}"
    debug_log "Screenshot at #{screenshot_path}"
    raise e
  else
    @staled_retries -= 1
    sleep(0.2)
    retry
  end
end

from ferrum.

shreeve avatar shreeve commented on May 22, 2024

I've been using this... seems like something like this should be in Ferrum.

module Ferrum
  class Frame
    module DOM

      #
      # Finds a node using XPath or a CSS path selector, with waiting.
      #
      # @param [String] selector
      #   The XPath or CSS path selector.
      #
      # @param [Integer] init
      #   How long we should wait before starting to look.
      #
      # @param [Integer] wait
      #   How long we should wait for node to appear.
      #
      # @param [Integer] step
      #   How long to wait between checking.
      #
      # @return [Node, nil]
      #   The matching node.
      #
      # @example
      #   browser.with("a[aria-label='CA']", init:1, wait:5, step:0.2) # => Node
      #
      def with(selector, init:nil, wait:1, step:0.1)
        sleep(init) if init
        meth = selector.start_with?("/") ? :at_xpath : :at_css
        until node = send(meth, selector) rescue nil
          (wait -= step) > 0 ? sleep(step) : break
        end
        node
      end
    end
  end
end

I use it like this:

site.with("#iux-identifier-user-id", init: 2, wait:8, step: 0.5).focus.type(user)

from ferrum.

shreeve avatar shreeve commented on May 22, 2024

This is quite a bit simpler than #236, granted this one is just pure Ruby version and doesn't use js timeouts, etc.

from ferrum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.