How to use me method of Howitzer.Web Package

Best Howitzer_ruby code snippet using Howitzer.Web.me

section_dsl.rb

Source:section_dsl.rb Github

copy

Full Screen

1require 'howitzer/web/capybara_context_holder'2module Howitzer3 module Web4 # This module combines section dsl methods5 module SectionDsl6 include CapybaraContextHolder7 def self.included(base) # :nodoc:8 base.extend(ClassMethods)9 end10 # This module holds section dsl class methods11 module ClassMethods12 # This class is for private usage only13 class SectionScope14 attr_accessor :section_class15 # Instantiates an anynomous or named section and executes block code in the section scope16 def initialize(name, *args, **options, &block)17 @args = args18 @options = options19 self.section_class =20 if block21 Class.new(Howitzer::Web::BaseSection)22 else23 "#{name}_section".classify.constantize24 end25 instance_eval(&block) if block_given?26 end27 # # Defines an element on the section28 # # @see Howitzer::Web::ElementDsl::ClassMethods#element29 def element(*args, **options)30 section_class.send(:element, *args, **options)31 end32 # Delegates a section describing to the section class33 def section(name, *args, **options, &block)34 section_class.send(:section, name, *args, **options, &block)35 end36 # Returns selector arguments for the section.37 # @note If anonymous section uses, then inline selector should be specified.38 # Otherwise arguments should be defined with `.me` dsl method in named section39 # @return [Array]40 # @raise [ArgumentError] when finder arguments were not specified41 def finder_args42 return @args if @args.present?43 @finder_args ||= (section_class.default_finder_args || raise(ArgumentError, 'Missing finder arguments'))44 end45 # Returns selector options for the section.46 # @note If anonymous section uses, then inline selector should be specified.47 # Otherwise arguments should be defined with `.me` dsl method in named section48 # @return [Array]49 # @raise [ArgumentError] when finder arguments were not specified50 def finder_options51 @options if @args.present? # it is ok to have blank options, so we rely here on the argments52 @finder_options ||= (section_class.default_finder_options || {})53 end54 end55 protected56 # DSL method which defines named or anonymous section within a page or a section57 # @note This method generates following dynamic methods:58 #59 # <b><em>section_name</em>_section</b> - equals capybara #find(...) method60 #61 # <b><em>section_name</em>_sections</b> - equals capybara #all(...) method62 #63 # <b><em>section_name</em>_sections.first</b> - equals capybara #first(...) method64 #65 # <b>has_<em>section_name</em>_section?</b> - equals capybara #has_selector(...) method66 #67 # <b>has_no_<em>section_name</em>_section?</b> - equals capybara #has_no_selector(...) method68 # @note It is possible to use nested anonymous sections69 # @param name [Symbol, String] an unique section name70 # @param args [Array] original Capybara arguments. For details, see `Capybara::Node::Finders#all.71 # (In most cases should be ommited for named sections because the section selector is specified72 # with `#me` method. But must be specified for anonymous sections)73 # @param options [Hash] original Capybara options. For details, see `Capybara::Node::Finders#all.74 # (In most cases should be ommited for named sections because the section selector is specified75 # with `#me` method. But may be specified for anonymous sections)76 # @param block [Proc] this block can contain nested sections and elements77 # @example Named section78 # class MenuSection < Howitzer::Web::Section79 # me :xpath, ".//*[@id='panel']"80 # end81 # class HomePage < Howitzer::Web::Page82 # section :menu83 # end84 # HomePage.on { is_expected.to have_menu_section }85 # @example Anonymous section86 # class HomePage < Howitzer::Web::Page87 # section :info_panel, '#panel' do88 # element :edit_button, '.edit'89 # element :title_field, '.title'90 #91 # def edit_info(title: nil)92 # edit_button_element.click93 # title_field_element.set(title)94 # end95 # end96 # end97 # HomePage.on { info_panel.edit_info(title: 'Test Title') }98 # @example Anonymous nested section99 # class HomePage < Howitzer::Web::Page100 # section :info_panel, '#panel' do101 # element :edit_button, '.edit'102 #103 # section :form, '.form' do104 # element :title_field, '.title'105 # end106 # end107 # end108 # HomePage.on { info_panel_section.edit_info(title: 'Test Title') }109 # @!visibility public110 def section(name, *args, **options, &block)111 scope = SectionScope.new(name, *args, **options, &block)112 define_section_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)113 define_sections_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)114 define_has_section_method(name, *scope.finder_args, **scope.finder_options)115 define_has_no_section_method(name, *scope.finder_args, **scope.finder_options)116 end117 private118 def define_section_method(klass, name, *args, **options)119 define_method("#{name}_section") do |**block_options|120 kwdargs = options.transform_keys(&:to_sym).merge(block_options.transform_keys(&:to_sym))121 if kwdargs.present?122 klass.new(self, capybara_context.find(*args, **kwdargs))123 else124 klass.new(self, capybara_context.find(*args))125 end126 end127 end128 def define_sections_method(klass, name, *args, **options)129 define_method("#{name}_sections") do |**block_options|130 kwdargs = options.transform_keys(&:to_sym).merge(block_options.transform_keys(&:to_sym))131 if kwdargs.present?132 capybara_context.all(*args, **kwdargs).map { |el| klass.new(self, el) }133 else134 capybara_context.all(*args).map { |el| klass.new(self, el) }135 end136 end137 end138 def define_has_section_method(name, *args, **options)139 define_method("has_#{name}_section?") do |**block_options|140 kwdargs = options.transform_keys(&:to_sym).merge(block_options.transform_keys(&:to_sym))141 if kwdargs.present?142 capybara_context.has_selector?(*args, **kwdargs)143 else144 capybara_context.has_selector?(*args)145 end146 end147 end148 def define_has_no_section_method(name, *args, **options)149 define_method("has_no_#{name}_section?") do |**block_options|150 kwdargs = options.transform_keys(&:to_sym).merge(block_options.transform_keys(&:to_sym))151 if kwdargs.present?152 capybara_context.has_no_selector?(*args, **kwdarg)153 else154 capybara_context.has_no_selector?(*args)155 end156 end157 end158 end159 end160 end161end162require 'howitzer/web/base_section'...

Full Screen

Full Screen

login_page.rb

Source:login_page.rb Github

copy

Full Screen

...3 path '/users/sign_in'4 validate :title, /\ADemo web application - Login form\z/5 # Demo web application - Login form6 validate :url, %r{/sign_in/?\z}7 element :email_input, :fillable_field, 'user_email'8 element :password_input, :fillable_field, 'user_password'9 element :remember_me, 'label[for="user_remember_me"]'10 element :login_btn, '[name=commit]'11 element :sign_up_link, :link, 'new_user_sign_up'12 element :forgot_password_link, :link, 'Forgot password?'13 def fill_form(email: nil, password: nil, remember_me: nil)14 Howitzer::Log.info 'Fill in Login Form with data:' \15 "email: #{email}, password: #{password}, remember_me: #{remember_me}"16 email_input_element.set(email) unless email.nil?17 password_input_element.set(password) unless password.nil?18 remember_me_element.set(true) unless remember_me.nil?19 self20 end21 def submit_form22 Howitzer::Log.info 'Submit Login Form'23 login_btn_element.click24 end25 def navigate_to_signup26 sign_up_link_element.click27 end28 def login_as(email, password, remember_me: false)29 Howitzer::Log.info "Login with: Email=#{email}, Password=#{password}, Remember Me=#{remember_me}"30 fill_form(email: email, password: password, remember_me: remember_me)31 submit_form32 HomePage.given33 end34 def navigate_to_forgot_password_page35 Howitzer::Log.info 'Navigate to forgot password page'36 forgot_password_link_element.click37 end38end...

Full Screen

Full Screen

section.rb

Source:section.rb Github

copy

Full Screen

1require 'howitzer/web/base_section'2require 'howitzer/meta'3module Howitzer4 module Web5 # This class uses for named sections which possible to reuse in different pages6 class Section < BaseSection7 # Provides access to meta information about entities in section8 # @return [Meta::Entry]9 def meta10 @meta ||= Meta::Entry.new(self)11 end12 class << self13 protected14 # DSL method which specifies section container selector represented by HTML element.15 # Any elements described in sections will start in this HTML element.16 # @param args [Array] original Capybara arguments. For details, see `Capybara::Node::Finders#all.17 # @param options [Array] original Capybara options. For details, see `Capybara::Node::Finders#all.18 # @raise [ArgumentError] if no arguments were passed19 # @example20 # class MenuSection < Howitzer::Web::Section21 # me :xpath, ".//*[@id='panel']",22 # end23 # @!visibility public24 def me(*args, **options)25 raise ArgumentError, 'Finder arguments are missing' if args.blank?26 @default_finder_args = args27 @default_finder_options = options28 self29 end30 end31 end32 end33end

Full Screen

Full Screen

me

Using AI Code Generation

copy

Full Screen

1Howitzer::Web::MainPage.me!(timeout: 15)2 has_selector?(:xpath, "//div[@id='main']")3Howitzer::Web::MainPage.me!(timeout

Full Screen

Full Screen

me

Using AI Code Generation

copy

Full Screen

1Howitzer::Web::MainPage.me!(timeout: 15)2 has_selector?(:xpath, "//div[@id='main']")3Howitzer::Web::MainPage.me!(timeout

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Howitzer_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful