在运行RSpec测试时,我无法让Capybara单击SCA/3DS“完全身份验证”按钮。不触发SCA的类似测试通过得很好,如果我运行VNC来查看Firefox正在做什么,则按钮是可见的,我可以自己在浏览器中单击它。
我的问题似乎非常类似于什么是在这里讨论的评论,但解决方案不起作用:我尝试过更改所使用的浏览器,并将iframe遍历扁平化。
测试代码:
scenario "SCA required" do
create_payment_method(account, payment_method: "stripe", last_four: "1234")
visit "/billing"
click_on "Enter Card Payment"
within "#main-content" do
within_frame(find("iframe")) do # Stripe payment form is in an iframe.
find("input#Field-numberInput").set("4000002760003184") # SCA-required test card.
find("input#Field-expiryInput").set("1234")
find("input#Field-cvcInput").set("123")
find("input#Field-postalCodeInput").set("12345")
end
end
find("button#submit").click
# Stripe nests the popup in several layers of iframes.
stripe_frame = find("body > div > iframe") # Popup is prepended to the body element.
switch_to_frame(stripe_frame)
challenge_frame = find("iframe#challengeFrame")
switch_to_frame(challenge_frame)
fullscreen_frame = find("iframe.FullscreenFrame")
switch_to_frame(fullscreen_frame)
click_on "Complete authentication"
switch_to_frame(:top)
expect(page).to have_content "ends in 3184"
end
这里有什么方法可以调试Selenium在引擎盖下做什么吗?在运行click_on "Complete authentication"
时,我没有看到页面上有任何移动,但是如果我自己单击Firefox实例中由Selenium控制的按钮,它就会工作。
运行click_on "Complete authentication"
将返回单击的元素,当我进入Pry并调用native.dom_attribute("id")
时,该元素似乎是预期的元素。
我可以在浏览器容器的日志中看到某种错误:
1654078084345 Marionette WARN TimedPromise timed out after 500 ms: stacktrace:
TimedPromise/<@chrome://remote/content/marionette/sync.js:239:19
TimedPromise@chrome://remote/content/marionette/sync.js:224:10
interaction.flushEventLoop@chrome://remote/content/marionette/interaction.js:431:10
webdriverClickElement@chrome://remote/content/marionette/interaction.js:179:31
这有点奇怪,因为它提到了@chrome,但这是一个无头Firefox实例。
发布于 2022-05-31 16:06:46
通过使用JavaScript直接单击按钮解决了这一问题:
execute_script(%Q{ document.querySelector("button#test-source-authorize-3ds").click() })
然而,这丝毫不能解释为什么click_on
不工作,如果有什么原因,这使它更奇怪的是,它没有。如果有人有更好的解决方案或探究Capybara/Selenium失败的原因,那将是值得欢迎的。
发布于 2022-05-31 16:49:27
假设click_on
调用没有返回错误,那么我猜按钮在准备单击之前已经被单击了。在调用“click_on”/在帧中导航之前,您可以先睡几秒钟来测试这一点。如果修复了它,那么您需要查看按钮上的哪些更改,以指示页面已经完成了它正在做的任何工作,并且该按钮已经准备好被单击。
https://stackoverflow.com/questions/72450808
复制相似问题