Class: RubyRaider::CommonFileGenerator

Inherits:
FileGenerator show all
Defined in:
lib/generators/files/common_file_generator.rb

Class Method Summary collapse

Methods inherited from FileGenerator

generate_file

Class Method Details

.config_fileObject



113
114
115
116
117
118
# File 'lib/generators/files/common_file_generator.rb', line 113

def self.config_file
  config_file = ERB.new <<~EOF
    browser: :chrome
  EOF
  config_file.result(binding)
end

.generate_common_files(name) ⇒ Object



5
6
7
8
9
# File 'lib/generators/files/common_file_generator.rb', line 5

def self.generate_common_files(name)
  generate_file('config.yml', "#{name}/config", config_file)
  generate_file('Rakefile', name.to_s, rake_file)
  generate_file('Readme.md', name.to_s, readme_file)
end

.rake_fileObject



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/generators/files/common_file_generator.rb', line 120

def self.rake_file
  rake_file = ERB.new <<~EOF
    require 'yaml'

    desc 'Selects browser for automation run'
    task :select_browser, [:browser] do |_t, args|
      config = YAML.load_file('config/config.yml')
      config['browser'] = args.browser
      File.write('config/config.yml', config.to_yaml)
    end
  EOF
  rake_file.result(binding)
end

.readme_fileObject



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/generators/files/common_file_generator.rb', line 11

def self.readme_file
  rake_file = ERB.new <<~EOF
    What is Raider?
    ===========

    Raider is a tool to make the setup and start of automation projects in ruby easier, with one command you are
    ready to go

    # Pre-requisites:

    Install RVM:
    https://rvm.io/rvm/install

    # How to use the framework:

    If you want to run all the tests from your terminal do:
    *rspec spec/*

    If you want to run all the tests in parallel do:
    *parallel_rspec spec/*

    # How are specs organized:

    We use 'context' as the highest grouping level to indicate in which part of the application we are as an example:

    *context 'On the login page'/*

    We use 'describe' from the user perspective to describe an action that the user can or cannot take:

    *describe 'A user can'/*

    or

    *describe 'A user cannot'/*

    This saves us repetition and forces us into an structure

    At last we use 'it' for the specific action the user can or cannot perform:

    it 'login with right credentials'

    If we group all of this together it will look like

    ```ruby
    context 'On the login page' do
      describe 'A user can' do
        it 'login with the right credentials' do
        end
    #{'   '}
      end
    #{'  '}
      describe 'A user cannot' do
        it 'login with the wrong credentials' do
        end
      end
    end
    ```
    #{'    '}
    This is readed as 'On the login page a user can login with the right credentials' and 'On the login page a user cannot login with the wrong credentials'

    # How pages are organized:

    ```ruby#{' '}
    require_relative '../abstract/base_page'

    class MainPage < BasePage

      using Raider::WatirHelper

      def url(_page)
        '/'
      end

      # Actions

      def change_currency(currency)
        currency_dropdown.select currency
      end

      # Validations

      def validate_currency(currency)
        expect(currency_dropdown.include?(currency)).to be true
      end

      private

      # Elements

      def currency_dropdown
        browser.select(class: %w[dropdown-menu currency])
      end
    end
    ```

    Pages are organized in Actions (things a user can perform on the page), Validations (assertions), and Elements.
    Each page has to have a url define, and each page is using the module WatirHelper to add methods on runtime to the Watir elements

  EOF
  rake_file.result(binding)
end