summaryrefslogtreecommitdiff
path: root/qa/qa/vendor/jenkins/page/configure_job.rb
blob: 657197957208b9bc37fc7238cfaad15e248c4f6d (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# frozen_string_literal: true

require 'capybara/dsl'

module QA
  module Vendor
    module Jenkins
      module Page
        class ConfigureJob < Page::Base
          attr_accessor :job_name

          def path
            "/job/#{@job_name}/configure"
          end

          def configure(scm_url:)
            set_git_source_code_management_url(scm_url)
            set_git_branches_to_build("*/#{Runtime::Env.default_branch}")
            click_build_when_change_is_pushed_to_gitlab
            set_publish_status_to_gitlab

            Support::Retrier.retry_until(sleep_interval: 0.5) do
              click_save
              wait_for_configuration_to_save
            end
          end

          private

          def set_git_source_code_management_url(repository_url)
            select_git_source_code_management
            set_repository_url(repository_url)
          end

          def set_git_branches_to_build(branches)
            find('.setting-name', text: "Branch Specifier (blank for 'any')").find(:xpath, "..").find('input').set branches
          end

          def click_build_when_change_is_pushed_to_gitlab
            find('label', text: 'Build when a change is pushed to GitLab').find(:xpath, "..").find('input').click
          end

          def set_publish_status_to_gitlab
            click_add_post_build_action
            select_publish_build_status_to_gitlab
          end

          def click_save
            click_on 'Save'
          end

          def select_git_source_code_management
            find('#radio-block-1').click
          end

          def set_repository_url(repository_url)
            find('.setting-name', text: "Repository URL").find(:xpath, "..").find('input').set repository_url
          end

          def click_add_post_build_action
            click_on "Add post-build action"
          end

          def select_publish_build_status_to_gitlab
            click_link "Publish build status to GitLab"
          end

          def wait_for_configuration_to_save
            QA::Support::Waiter.wait_until(max_duration: 10, raise_on_failure: false) do
              !page.current_url.include?(path)
            end
          end
        end
      end
    end
  end
end