Flows in GitLab QA

原文:https://docs.gitlab.com/ee/development/testing_guide/end_to_end/flows.html

Flows in GitLab QA

流是经常使用的动作序列. 它们是比页面对象更高的抽象级别. 流可以包含多个页面对象或任何其他相关代码.

例如,登录流封装了每个浏览器 UI 测试中包含的两个步骤.

  1. # QA::Flow::Login
  2. def sign_in(as: nil)
  3. Runtime::Browser.visit(:gitlab, Page::Main::Login)
  4. Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: as) }
  5. end
  6. # When used in a test
  7. it 'performs a test after signing in as the default user' do
  8. Flow::Login.sign_in
  9. # Perform the test
  10. end

QA::Flow::Login提供了更有用的流程,使测试可以轻松切换用户.

  1. # QA::Flow::Login
  2. def while_signed_in(as: nil)
  3. Page::Main::Menu.perform(&:sign_out_if_signed_in)
  4. sign_in(as: as)
  5. yield
  6. Page::Main::Menu.perform(&:sign_out)
  7. end
  8. # When used in a test
  9. it 'performs a test as one user and verifies as another' do
  10. user1 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
  11. user2 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2)
  12. Flow::Login.while_signed_in(as: user1) do
  13. # Perform some setup as user1
  14. end
  15. Flow::Login.sign_in(as: user2)
  16. # Perform the rest of the test as user2
  17. end