Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using binding.irb, how to make it work ? #281

Open
jean-francois-labbe opened this issue Feb 23, 2024 · 7 comments
Open

Error when using binding.irb, how to make it work ? #281

jean-francois-labbe opened this issue Feb 23, 2024 · 7 comments
Labels
question Further information is requested

Comments

@jean-francois-labbe
Copy link
Contributor

Usecase / What to achieve

I'm able to run a test but when I add binding.irb or binding.b in test the test doesn't start at all, same thing with a sleep 3

I tried with PWDEBUG=1 rspec but the error is the same.

Error message is:

Failure/Error: click_on I18n.t('views.sessions.new_account')

Playwright::Error:
  Element is not attached to the DOM
  Call log:
  attempting click action
    -   waiting for element to be visible, enabled and stable
    -   element is visible, enabled and stable
    -   scrolling into view if needed
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `raise'
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `wait_until_resolved!'
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1482:in `value!'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/connection.rb:118:in `send_message_to_server'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/channel.rb:35:in `block in send_message_to_server_result'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/channel.rb:67:in `with_logging'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/channel.rb:34:in `send_message_to_server_result'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/channel.rb:20:in `send_message_to_server'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright/channel_owners/element_handle.rb:121:in `click'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.41.1/lib/playwright_api/element_handle.rb:106:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-playwright-driver-0.5.1/lib/capybara/playwright/node.rb:363:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:172:in `block in click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:608:in `block in perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/base.rb:84:in `synchronize'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:608:in `perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-playwright-driver-0.5.1/lib/capybara/playwright/node.rb:12:in `perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:171:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/actions.rb:26:in `click_link_or_button'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/session.rb:774:in `click_on'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in `call'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in `click_on'
# ./spec/features/sign_up_spec.rb:82:in `block (3 levels) in <top (required)>'

Question

What should I do, change in the configuration to be able to use binding.irb ?

@jean-francois-labbe jean-francois-labbe added the question Further information is requested label Feb 23, 2024
@YusukeIwaki
Copy link
Owner

The behabior is unexpected since I myself use binding.pry for debugging described source codes.

Could you provide an example code for reproducing this issue?

@YusukeIwaki
Copy link
Owner

This example code doesn't trigger timeout.

$ bundle exec ruby a.rb 
From: /Users/yusuke-iwaki/Desktop/plrb/a.rb:8 :

     3: 
     4: Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
     5:   playwright.chromium.launch(headless: false) do |browser|
     6:     page = browser.new_page
     7:     page.goto('https://github.com/YusukeIwaki')
 =>  8:     binding.pry
     9:     page.screenshot(path: './YusukeIwaki.png')
    10:   end
    11: end

And the provided call stack shows

# /Users/.gem/ruby/3.1.4/gems/capybara-playwright-driver-0.5.1/lib/capybara/playwright/node.rb:363:in `click'

so it is probably capybara-playwright-driver's bug or spec.

@YusukeIwaki
Copy link
Owner

Sorry for my mistake, I found playwright-ruby-client >= 1.40.0 raises such error after we use wait_for_xxx or expect_xxx methods.
YusukeIwaki/capybara-playwright-driver#72

@jean-francois-labbe
Copy link
Contributor Author

jean-francois-labbe commented Feb 26, 2024

@YusukeIwaki Sorry for the delay. It looks like you found the cause of the issue. Is there anything I can do do help solve it ?

The spec looks like this:

  it "signed up user" do
    visit root_path

    detected_locale = find("select[name='lang']").value
    switch_locale_to(detected_locale) do
      click_on I18n.t('views.sessions.new_account') # breaks here when binding.b is set under.

      expect(page).to have_current_path(new_user_session_path(lang: detected_locale))
      fill_in 'user_first_name', with: 'John'
      fill_in 'user_last_name', with: 'Doe'
      fill_in 'user_email', with: '[email protected]'
      fill_in 'user_password', with: 'password'
      click_on I18n.t('views.sessions.sign_up')

      binding.b  # break point is here
      expect(page).to have_content(I18n.t('devise.registrations.signed_up'))
    end
  end

It is specific to the application, if needed I could try to create a minimal repository to reproduce the issue.

What is strange is that the binding.b is declared at the bottom of the test but the execption occurs on this line
click_on I18n.t('views.sessions.new_account')

When there is no binding.b the test is successful.

@jean-francois-labbe
Copy link
Contributor Author

jean-francois-labbe commented Feb 26, 2024

I tried with playwright-ruby-client version 1.39.1, it is a similar issue.

Failure/Error: click_on I18n.t('views.sessions.new_account')

Playwright::Error:
  Element is not attached to the DOM
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `raise'
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1268:in `wait_until_resolved!'
# /Users/.gem/ruby/3.1.4/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promises.rb:1482:in `value!'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/connection.rb:104:in `send_message_to_server'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/channel.rb:35:in `block in send_message_to_server_result'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/channel.rb:67:in `with_logging'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/channel.rb:34:in `send_message_to_server_result'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/channel.rb:20:in `send_message_to_server'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright/channel_owners/element_handle.rb:121:in `click'
# /Users/.gem/ruby/3.1.4/gems/playwright-ruby-client-1.39.1/lib/playwright_api/element_handle.rb:106:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-playwright-driver-0.5.1/lib/capybara/playwright/node.rb:363:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:172:in `block in click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:608:in `block in perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/base.rb:84:in `synchronize'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:608:in `perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-playwright-driver-0.5.1/lib/capybara/playwright/node.rb:12:in `perform_click_action'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/element.rb:171:in `click'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/node/actions.rb:26:in `click_link_or_button'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/session.rb:774:in `click_on'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in `call'
# /Users/.gem/ruby/3.1.4/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in `click_on'
# ./spec/features/sign_up_spec.rb:82:in `block (3 levels) in <top (required)>'

It may not only be related to the binding.b.

I can have same error when binding.b is removed and launching test with:
PWDEBUG=1 rspec ./spec/features/sign_up_spec.rb:77

and rapidly clicking on the play button.

@YusukeIwaki
Copy link
Owner

Sorry for late reply,

I found playwright-ruby-client >= 1.40.0 raises such error after we use wait_for_xxx or expect_xxx methods.
YusukeIwaki/capybara-playwright-driver#72

#292 would fix the issue and playwright-ruby-client 1.41.2 and 1.42.1 include the patch.
binding.pry would be available in the version.

@YusukeIwaki
Copy link
Owner

Playwright::Error:
Element is not attached to the DOM

This can be a bug of capybara-playwright-driver, however I recommend using web-first assertion provided by Playwright, instead of Capybara's assertion, if possible.
https://playwright-ruby-client.vercel.app/docs/api/locator_assertions

page.driver.with_playwright_page do |page|
  page.get_by_text(I18n.t('views.sessions.sign_up')).click
  expect(page.locator('.flash')).to have_text(I18n.t('devise.registrations.signed_up'))
end

Playwright's auto-waiting feature is more precise than Capybara's behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants