YusukeIwaki / playwright-ruby-client

Playwright client for Ruby
https://playwright-ruby-client.vercel.app/
MIT License
337 stars 34 forks source link

Data seeding creation and clean up #189

Closed humbienri closed 2 years ago

humbienri commented 2 years ago

Apologies for the simplistic question as I am not a Ruby or RoR dev.

Your documentation makes no mention of data seeding or data creation and such test automation matters. Which is fine as it may be out of scope and something that is handled and should be known by Rails folks? Maybe?

Am I correct in thinking that the data "aspect" of tests would still be done via tooling in the RoR ecosystem? Factory_bot for example?

I ask because similar tooling to your tool, cypress-on-rails and cypress-rails, seem to at least mention the HOW-TO of data in their READMEs?

Any thoughts on this matter please?

Thank you @YusukeIwaki

YusukeIwaki commented 2 years ago

Hi, thank you for taking an interest in this Gem.

At first, this playwright-ruby-client is not a testing framework as it is, but just a browser automation tool. On the other hand, cypress-on-rails and cypress-rails are helper libraries for Cypress testing framework.

When we want to implement tests with playwright-ruby-client, we have to prepare test runner (RSpec/Minitest) and Capybara (optional) as is described in the article below https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration_with_null_driver Then FactoryBot works as a fixture (test data) generator there. The example code in the article above actually uses FactoryBot.

require 'rails_helper'

describe 'example', driver: :null do
  let!(:user) { FactoryBot.create(:user) } # <--- FactoryBot is actually used here
  let(:page) { @playwright_page }

  it 'can browse' do
    page.goto("/tests/#{user.id}")
    page.wait_for_selector('input').type('hoge')
    page.keyboard.press('Enter')
    expect(page.text_content('#content')).to include('hoge')
  end
end

Test data is automatically cleaned up after each test is finished. (For more detail, search for "transactional test" feature of Rails)

humbienri commented 2 years ago

Hello again,

Sorry I'd not responded sooner. Things get busy and I lost track a bit. Back though.

I do understand that this client is not a testing framework. I also understand that Cypress is both an browser automation framework or library as well as a test runner. So no I am not asking if this client is the same as, or equivalent to, Cypress. I realize it is not. Thank you for your insights though.

If I am understanding you correctly, it seems you are saying that this playwright-ruby-client can be used WITH Factory Bot without really having to do anything special or doing extra settings or configurations to the playwright-ruby-client gem? Seem like the ruby-client is completely separate from the Factory Bot gem and they really don't need to know about each other or talk to each other at all, which is unlike the cypress helper tools I mentioned before?

Thanks again sir!

humbienri commented 2 years ago

Hello again,

Please, another point of clarification as I struggle to figure out how to integrate this client library into a body of work of pre-existing specs already in usage.

By using this gem, we lose the ability to use Capybara? I am getting some errors about visit not being a defined method or NotImplemented, if I remember correctly.

Thanks again.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

humbienri commented 2 years ago

Any thoughts please @YusukeIwaki ?

YusukeIwaki commented 2 years ago

@humbienri Very sorry for late response.

By using this gem, we lose the ability to use Capybara? I am getting some errors about visit not being a defined method or NotImplemented, if I remember correctly.

This Gem doesn't provide Capybara functionality, so visit will raise NameError.

I also created Capybara driver of this Gem: https://github.com/YusukeIwaki/capybara-playwright-driver You can use it if you just try Playwright with existing specs using Capybara. But keep in mind that Playwright's awesome features (auto-waiting, intuitive selectors, and so on) are almost unavailable via Capybara DSL. https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration

Instead, I strongly suggest using Playwright without Capybara DSL, as is described in the guide below: https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration_with_null_driver

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.