From d5618d00adfc3057c34db311a67a23232413fc7b Mon Sep 17 00:00:00 2001 From: Steven Schmid Date: Thu, 15 Jun 2023 10:14:06 +0200 Subject: [PATCH] Do not retry -> rescue (and timeout in case of removal) on existing nodes Fixes intermittent failures and improves performance in tests with dynamic content by disabling rescue and retry in Ferrum::Frame::Runtime#call --- lib/ferrum/frame/runtime.rb | 3 ++- spec/frame/runtime_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ferrum/frame/runtime.rb b/lib/ferrum/frame/runtime.rb index 48752138..9a3a61c7 100644 --- a/lib/ferrum/frame/runtime.rb +++ b/lib/ferrum/frame/runtime.rb @@ -100,7 +100,8 @@ def evaluate_on(node:, expression:, by_value: true, wait: 0) private def call(expression:, arguments: [], on: nil, wait: 0, handle: true, **options) - errors = [NodeNotFoundError, NoExecutionContextError] + # do not rescue -> retry if we operate on an existing node + errors = on ? [] : [NodeNotFoundError, NoExecutionContextError] Utils::Attempt.with_retry(errors: errors, max: INTERMITTENT_ATTEMPTS, wait: INTERMITTENT_SLEEP) do params = options.dup diff --git a/spec/frame/runtime_spec.rb b/spec/frame/runtime_spec.rb index bbe8bce9..5c60ea11 100644 --- a/spec/frame/runtime_spec.rb +++ b/spec/frame/runtime_spec.rb @@ -196,6 +196,17 @@ end end + describe "#evaluate_on" do + it "does not retry if node is not around anymore" do + browser.go_to("/ferrum/table") + node = browser.at_xpath(".//td") + + browser.go_to("/ferrum/table") + expect(Ferrum::Utils::Attempt).to receive(:with_retry).with(hash_including(errors: [])).and_call_original + expect { browser.evaluate_on(node: node, expression: "this.textContent") }.to raise_error(Ferrum::NodeNotFoundError) + end + end + describe "#add_script_tag" do it "adds by url" do browser.go_to