Class: RubyRaider::WatirFileGenerator
- Inherits:
-
FileGenerator
- Object
- FileGenerator
- RubyRaider::WatirFileGenerator
- Defined in:
- lib/generators/files/watir_file_generator.rb
Class Method Summary collapse
- .abstract_component ⇒ Object
- .abstract_page ⇒ Object
- .example_component ⇒ Object
- .example_page ⇒ Object
- .gemfile_template ⇒ Object
- .generate_watir_files(name) ⇒ Object
Methods inherited from FileGenerator
Class Method Details
.abstract_component ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/generators/files/watir_file_generator.rb', line 129 def self.abstract_component abstract_file = ERB.new <<~EOF require_relative '../../helpers/raider' class AbstractComponent def initialize(component) @component = component end end EOF abstract_file.result(binding) end |
.abstract_page ⇒ Object
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 112 113 |
# File 'lib/generators/files/watir_file_generator.rb', line 80 def self.abstract_page abstract_file = ERB.new <<~EOF require 'rspec' require_relative '../../helpers/raider' class AbstractPage include RSpec::Matchers extend Raider::PomHelper def browser Raider::BrowserHelper.browser end def visit(*page) browser.goto full_url(page.first) end def full_url(*page) "#\{base_url}#\{url(*page)}" end def base_url 'https://automationteststore.com/' end def url(_page) raise 'Url must be defined on child pages' end end EOF abstract_file.result(binding) end |
.example_component ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/generators/files/watir_file_generator.rb', line 115 def self.example_component page_file = ERB.new <<~EOF require_relative '../abstract/abstract_component' class HeaderComponent < AbstractComponent def customer_name @component.text end end EOF page_file.result(binding) end |
.example_page ⇒ Object
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 |
# File 'lib/generators/files/watir_file_generator.rb', line 33 def self.example_page page_file = ERB.new <<~EOF require_relative '../abstract/abstract_page' require_relative '../components/header_component' class LoginPage < AbstractPage using Raider::WatirHelper def url(_page) 'index.php?rt=account/login' end # Actions def login(username, password) username_field.set username password_field.set password login_button.click_when_present end # Components def header HeaderComponent.new(browser.element(class: 'menu_text')) end private # Elements def username_field browser.text_field(id: 'loginFrm_loginname') end def password_field browser.text_field(id: 'loginFrm_password') end def login_button browser.button(visible_text: 'Login') end end EOF page_file.result(binding) end |
.gemfile_template ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/files/watir_file_generator.rb', line 13 def self.gemfile_template gemfile = ERB.new <<~EOF # frozen_string_literal: true source 'https://rubygems.org' gem 'activesupport' gem 'allure-rspec' gem 'allure-ruby-commons' gem 'parallel_split_test' gem 'parallel_tests' gem 'rake' gem 'rspec' gem 'selenium-webdriver' gem 'watir' gem 'webdrivers' EOF gemfile.result(binding) end |
.generate_watir_files(name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/generators/files/watir_file_generator.rb', line 5 def self.generate_watir_files(name) generate_file('abstract_page.rb', "#{name}/page_objects/abstract", abstract_page) generate_file('abstract_component.rb', "#{name}/page_objects/abstract", abstract_component) generate_file('login_page.rb', "#{name}/page_objects/pages", example_page) generate_file('header_component.rb', "#{name}/page_objects/components", example_component) generate_file('Gemfile', name.to_s, gemfile_template) end |