<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Beginner's guide to writing end-to-end tests > 原文:[https://docs.gitlab.com/ee/development/testing_guide/end_to_end/beginners_guide.html](https://docs.gitlab.com/ee/development/testing_guide/end_to_end/beginners_guide.html) * [Before you write a test](#before-you-write-a-test) * [Determine if end-to-end tests are needed](#determine-if-end-to-end-tests-are-needed) * [Identify the DevOps stage](#identify-the-devops-stage) * [Create a skeleton test](#create-a-skeleton-test) * [The outer `context` block](#the-outer-context-block) * [The outer `RSpec.describe` block](#the-outer-rspecdescribe-block) * [The `describe` block](#the-describe-block) * [The `it` blocks (examples)](#the-it-blocks-examples) * [Write the test](#write-the-test) * [De-duplicate your code](#de-duplicate-your-code) * [Test setup using resources and page objects](#test-setup-using-resources-and-page-objects) * [Write the page object](#write-the-page-object) * [Run the spec](#run-the-spec) # Beginner’s guide to writing end-to-end tests[](#beginners-guide-to-writing-end-to-end-tests "Permalink") 在本教程中,您將學習如何為[GitLab 社區版](https://about.gitlab.com/install/?version=ce)和[GitLab 企業版](https://about.gitlab.com/install/)創建端到端( *e2e* )測試. 在本教程結束時,您將能夠: * 確定是否需要端到端測試. * Understand the directory structure within `qa/`. * 編寫一個基本的端到端測試,以驗證登錄功能. * 開發任何缺少的[頁面對象](page_objects.html)庫. ## Before you write a test[](#before-you-write-a-test "Permalink") 在編寫測試之前,必須將您的[GitLab 開發套件(GDK)](https://gitlab.com/gitlab-org/gitlab-development-kit)配置為運行規范. 端到端測試: * 包含在`qa/`目錄中. * 應該是獨立和[冪等的](https://en.wikipedia.org/wiki/Idempotence#Computer_science_meaning) . * 臨時創建[資源](resources.html) (例如項目,問題,用戶). * Test the UI and API interfaces, and use the API to efficiently set up the UI tests. **提示:**有關更多信息,請參閱[端到端測試最佳實踐](best_practices.html) . ## Determine if end-to-end tests are needed[](#determine-if-end-to-end-tests-are-needed "Permalink") 在編寫端到端測試之前,請為[GitLab 社區版](https://gitlab-org.gitlab.io/gitlab-foss/coverage-ruby/#_AllFiles)和[GitLab 企業版](https://gitlab-org.gitlab.io/gitlab/coverage-ruby/#_AllFiles)項目檢查特定功能的代碼覆蓋率. 在單元,功能或集成級別上是否存在足夠的測試范圍? 如果回答*是肯定的* ,那么你*就*需要一個終端到終端的測試. 有關 GitLab 中每個級別的測試分布的信息,請參見[測試級別](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/development/testing_guide/testing_levels.md) . * 請參閱[如何以正確的級別進行測試?](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/development/testing_guide/testing_levels.md#how-to-test-at-the-correct-level) " [測試級別"](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/development/testing_guide/testing_levels.md)文檔的"部分". * 查看功能更改的頻率. 如果較低級別的測試中已經包含了穩定的特性,那么這些特性不會經常更改,那么端到端測試可能就不值得考慮. * 最后,與參與實現功能和較低級別測試的開發人員討論建議的測試. **注意:**檢查[GitLab 社區版](https://gitlab-org.gitlab.io/gitlab-foss/coverage-ruby/#_AllFiles)和[GitLab 企業版](https://gitlab-org.gitlab.io/gitlab/coverage-ruby/#_AllFiles)覆蓋率項目,以檢查是否為此功能編寫了以前的測試. 為了分析代碼覆蓋率,您必須了解哪些應用程序文件實現了特定功能.**注意:**在本教程中,我們將編寫一個登錄端到端測試,即使它已經被較低級別的測試所覆蓋,因為這是大多數端到端流的第一步,并且最容易理解. ## Identify the DevOps stage[](#identify-the-devops-stage "Permalink") GitLab QA 端到端測試是由[DevOps 生命周期](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/qa/qa/specs/features/browser_ui)的不同[階段](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/qa/qa/specs/features/browser_ui)組織的. 確定應按[階段](https://about.gitlab.com/handbook/product/product-categories/#devops-stages)放置測試的位置,確定該測試屬于哪個功能,然后將其放置在該階段下的子目錄中. [![DevOps lifecycle by stages](https://img.kancloud.cn/3d/88/3d882abb3c41524cf9f4127f98f2482b_1109x502.png)](img/gl-devops-lifecycle-by-stage-numbers_V12_10.png) **注意:**如果該測試僅是企業版,則將在`features/ee`目錄中創建該測試,但遵循相同的 DevOps 生命周期格式. ## Create a skeleton test[](#create-a-skeleton-test "Permalink") 在本教程的第一部分中,我們將測試由 Manage 階段擁有的登錄名. 在`qa/specs/features/browser_ui/1_manage/login` ,創建文件`basic_login_spec.rb` . ### The outer `context` block[](#the-outer-context-block "Permalink") 參見[`RSpec.describe`外部塊](#the-outer-rspecdescribe-block) **棄用聲明:**遵循 RSpec 4.0 規范在`13.2`中[棄用](https://gitlab.com/gitlab-org/quality/team-tasks/-/issues/550)了外部`context` . 請改用`RSpec.describe` . ### The outer `RSpec.describe` block[](#the-outer-rspecdescribe-block "Permalink") 規格具有外部`RSpec.describe`指示 DevOps 階段. ``` # frozen_string_literal: true module QA RSpec.describe 'Manage' do end end ``` ### The `describe` block[](#the-describe-block "Permalink") 在我們的外部`RSpec.describe`內部,描述要測試的功能. 在這種情況下,請`Login` . ``` # frozen_string_literal: true module QA RSpec.describe 'Manage' do describe 'Login' do end end end ``` ### The `it` blocks (examples)[](#the-it-blocks-examples "Permalink") 每個測試套件包含至少一個`it`阻斷(實施例). 一個好方法,開始寫終端到終端的測試是編寫測試用例描述為`it`塊: ``` module QA RSpec.describe 'Manage' do describe 'Login' do it 'can login' do end it 'can logout' do end end end end ``` ## Write the test[](#write-the-test "Permalink") 一個重要的問題是"我們要測試什么?" 更重要的是,"我們如何測試?" 首先登錄. ``` # frozen_string_literal: true module QA RSpec.describe 'Manage' do describe 'Login' do it 'can login' do Flow::Login.sign_in end it 'can logout' do Flow::Login.sign_in end end end end ``` [運行規范后](#run-the-spec) ,我們的測試應登錄并結束; 那么我們應該回答"我們要測試什么?"這個問題. ``` # frozen_string_literal: true module QA RSpec.describe 'Manage' do describe 'Login' do it 'can login' do Flow::Login.sign_in Page::Main::Menu.perform do |menu| expect(menu).to be_signed_in end end it 'can logout' do Flow::Login.sign_in Page::Main::Menu.perform do |menu| menu.sign_out expect(menu).not_to be_signed_in end end end end end ``` **我們要測試什么?** 1. 我們可以登錄嗎? 2. 我們可以注銷嗎? **我們如何測試?** 1. 檢查用戶頭像是否出現在頂部導航中. 2. 檢查用戶頭像*是否未*出現在頂部導航中. **注意:**在幕后, `be_signed_in`是一個[謂詞匹配器](https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/built-in-matchers/predicate-matchers) ,可[實現對用戶頭像的檢查](https://gitlab.com/gitlab-org/gitlab/-/blob/master/qa/qa/page/main/menu.rb#L74) . ## De-duplicate your code[](#de-duplicate-your-code "Permalink") 將測試重構為使用`before`塊進行測試設置,因為它復制了對`sign_in`的調用. ``` # frozen_string_literal: true module QA RSpec.describe 'Manage' do describe 'Login' do before do Flow::Login.sign_in end it 'can login' do Page::Main::Menu.perform do |menu| expect(menu).to be_signed_in end end it 'can logout' do Page::Main::Menu.perform do |menu| menu.sign_out expect(menu).not_to be_signed_in end end end end end ``` `before`塊本質上是一個`before(:each)`并且在每個示例之前運行,確保我們現在在每個測試的開始處登錄. ## Test setup using resources and page objects[](#test-setup-using-resources-and-page-objects "Permalink") 接下來,讓我們測試登錄以外的其他功能. 讓我們測試"計劃"階段擁有的"問題",因此在`qa/specs/features/browser_ui/3_create/issues` [創建一個](#identify-the-devops-stage)名為`issues_spec.rb` . ``` # frozen_string_literal: true module QA RSpec.describe 'Plan' do describe 'Issues' do let(:issue) do Resource::Issue.fabricate_via_api! do |issue| issue.title = 'My issue' issue.description = 'This is an issue specific to this test' end end before do Flow::Login.sign_in issue.visit! end it 'can close an issue' do Page::Project::Issue::Show.perform do |show| show.click_close_issue_button expect(show).to be_closed end end end end end ``` 請注意以下要點: * 在我們的示例開始時,我們將在`page/issue/show.rb` [頁面](page_objects.html) . * 我們的測試僅在需要時制造需要的東西. * 該問題是通過 API 偽造的,以節省時間. * GitLab 更喜歡`let()`不是實例變量. 查看[最佳做法](../best_practices.html#let-variables) . * `be_closed`尚未在`page/project/issue/show.rb`中實現,但將在下一步中實現. 該問題被偽裝成[Resource](resources.html) ,它是您可以通過 UI 或 API 創建的 GitLab 實體. 其他示例包括: * A [Merge Request](https://gitlab.com/gitlab-org/gitlab/-/blob/master/qa/qa/resource/merge_request.rb). * A [User](https://gitlab.com/gitlab-org/gitlab/-/blob/master/qa/qa/resource/user.rb). * A [Project](https://gitlab.com/gitlab-org/gitlab/-/blob/master/qa/qa/resource/project.rb). * A [Group](https://gitlab.com/gitlab-org/gitlab/-/blob/master/qa/qa/resource/group.rb). ## Write the page object[](#write-the-page-object "Permalink") [Page Object](page_objects.html)是我們套件中的一個類,代表 GitLab 中的一個頁面. **登錄**頁面就是一個例子. 由于我們的" **問題顯示"**頁面的頁面對象已經存在,請添加`closed?` 方法. ``` module Page::Project::Issue class Show view 'app/views/projects/issues/show.html.haml' do element :closed_status_box end def closed? has_element?(:closed_status_box) end end end ``` 接下來,在視圖中定義元素`closed_status_box` ,以便頁面對象可以看到它. ``` -#=> app/views/projects/issues/show.html.haml .issuable-status-box.status-box.status-box-issue-closed{ ..., data: { qa_selector: 'closed_status_box' } } ``` ## Run the spec[](#run-the-spec "Permalink") 在運行規范之前,請確認: * GDK 已安裝. * GDK 在本地 3000 端口上運行. * 尚未應用其他[RSpec 元數據標簽](rspec_metadata_tests.html) . * 您的工作目錄是 GDK GitLab 安裝中的`qa/` . 要運行該規范,請運行以下命令: ``` bundle exec bin/qa Test::Instance::All http://localhost:3000 -- <test_file> ``` Where `<test_file>` is: * 運行"登錄"示例時,請輸入`qa/specs/features/browser_ui/1_manage/login/login_spec.rb` . * 運行"問題"示例時,請執行`qa/specs/features/browser_ui/2_plan/issues/issue_spec.rb` .
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看