640.md 1.5 KB
Newer Older
Lab机器人's avatar
readme  
Lab机器人 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# Flows in GitLab QA

> 原文:[https://docs.gitlab.com/ee/development/testing_guide/end_to_end/flows.html](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/flows.html)

# Flows in GitLab QA[](#flows-in-gitlab-qa "Permalink")

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

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

```
# QA::Flow::Login

def sign_in(as: nil)
  Runtime::Browser.visit(:gitlab, Page::Main::Login)
  Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: as) }
end

# When used in a test

it 'performs a test after signing in as the default user' do
  Flow::Login.sign_in

  # Perform the test
end 
```

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

```
# QA::Flow::Login

def while_signed_in(as: nil)
  Page::Main::Menu.perform(&:sign_out_if_signed_in)

  sign_in(as: as)

  yield

  Page::Main::Menu.perform(&:sign_out)
end

# When used in a test

it 'performs a test as one user and verifies as another' do
  user1 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
  user2 = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2)

  Flow::Login.while_signed_in(as: user1) do
    # Perform some setup as user1
  end

  Flow::Login.sign_in(as: user2)

  # Perform the rest of the test as user2
end 
```