How to use current_page method of Howitzer.Web Package

Best Howitzer_ruby code snippet using Howitzer.Web.current_page

page_spec.rb

Source:page_spec.rb Github

copy

Full Screen

...105 expect(session).to receive(:title)106 subject107 end108 end109 describe '.current_page' do110 subject { described_class.current_page }111 context 'when matched_pages has no pages' do112 before { allow(described_class).to receive(:matched_pages).and_return([]) }113 it { is_expected.to eq(described_class::UnknownPage) }114 end115 context 'when matched_pages has more than 1 page' do116 let(:foo_page) { double(inspect: 'FooPage') }117 let(:bar_page) { double(inspect: 'BarPage') }118 before do119 allow_any_instance_of(described_class).to receive(:check_validations_are_defined!).and_return(true)120 allow(session).to receive(:current_url).and_return('http://test.com')121 allow(session).to receive(:title) { 'Test site' }122 allow(described_class).to receive(:matched_pages).and_return([foo_page, bar_page])123 end124 it do125 expect { subject }.to raise_error(126 Howitzer::AmbiguousPageMatchingError,127 "Current page matches more that one page class (FooPage, BarPage).\n" \128 "\tCurrent url: http://test.com\n\tCurrent title: Test site"129 )130 end131 end132 context 'when matched_pages has only 1 page' do133 let(:foo_page) { double(to_s: 'FooPage') }134 before { allow(described_class).to receive(:matched_pages).and_return([foo_page]) }135 it { is_expected.to eq(foo_page) }136 end137 end138 describe '.displayed?' do139 subject { described_class.displayed? }140 context 'when page is opened' do141 before { allow(described_class).to receive(:opened?).and_return(true) }142 it { is_expected.to eq(true) }143 end144 context 'when page is not opened' do145 before do146 allow(described_class).to receive(:current_page).and_return('FooPage')147 allow(session).to receive(:current_url).and_return('http://test.com')148 allow(session).to receive(:title).and_return('Test site')149 allow(described_class).to receive(:opened?).and_return(false)150 end151 it do152 expect { subject }.to raise_error(153 Howitzer::IncorrectPageError,154 "Current page: FooPage, expected: #{described_class}.\n" \155 "\tCurrent url: http://test.com\n\tCurrent title: Test site"156 )157 end158 end159 end160 describe '.current_url' do...

Full Screen

Full Screen

page.rb

Source:page.rb Github

copy

Full Screen

...52 # Tries to identify current page name or raise the error if ambiguous page matching53 # @return [String] a page name54 # @raise [UnknownPage] when no any matched pages55 # @raise [AmbiguousPageMatchingError] when matched more than 1 page56 def self.current_page57 page_list = matched_pages58 return UnknownPage if page_list.count.zero?59 return page_list.first if page_list.count == 160 raise Howitzer::AmbiguousPageMatchingError, ambiguous_page_msg(page_list)61 end62 # Waits until a web page is opened63 # @param timeout [Integer] time in seconds a required web page to be loaded64 # @return [Boolean]65 # @raise [IncorrectPageError] when timeout expired and the page is not displayed66 def self.displayed?(timeout = Howitzer.page_load_idle_timeout)67 end_time = ::Time.now + timeout68 until ::Time.now > end_time69 return true if opened?70 sleep(0.5)71 end72 raise Howitzer::IncorrectPageError, incorrect_page_msg73 end74 # @return [String] current page url from browser75 def self.current_url76 Capybara.current_session.current_url77 end78 # Returns an expanded page url for the page opening79 # @param params [Array] placeholders and their values80 # @param url_processor [Class] custom url processor. For details see Addressable gem81 # @return [String]82 # @raise [NoPathForPageError] if an url is not specified for the page83 def self.expanded_url(params = {}, url_processor = nil)84 if defined?(path_value)85 return "#{site_value}#{Addressable::Template.new(path_value).expand(params, url_processor)}"86 end87 raise Howitzer::NoPathForPageError, "Please specify path for '#{self}' page. Example: path '/home'"88 end89 # Provides access to meta information about entities on the page90 # @return [Meta::Entry]91 def meta92 @meta ||= Meta::Entry.new(self)93 end94 class << self95 protected96 # DSL to specify an relative path pattern for the page opening97 # @param value [String] a path pattern, for details please see Addressable gem98 # @see .site99 # @example100 # class ArticlePage < Howitzer::Web::Page101 # url '/articles/:id'102 # end103 # ArticlePage.open(id: 10)104 # @!visibility public105 def path(value)106 define_singleton_method(:path_value) { value.to_s }107 private_class_method :path_value108 end109 # DSL to specify a site for the page opening110 # @note By default it specifies Howitzer.app_uri.site as a site111 # @param value [String] a site as combination of protocol, host and port112 # @example113 # class AuthPage < Howitzer::Web::Page114 # site 'https:/example.com'115 # end116 #117 # class LoginPage < AuthPage118 # path '/login'119 # end120 # @!visibility public121 def site(value)122 define_singleton_method(:site_value) { value }123 private_class_method :site_value124 end125 private126 def incorrect_page_msg127 "Current page: #{current_page}, expected: #{self}.\n" \128 "\tCurrent url: #{current_url}\n\tCurrent title: #{instance.title}"129 end130 def ambiguous_page_msg(page_list)131 "Current page matches more that one page class (#{page_list.join(', ')}).\n" \132 "\tCurrent url: #{current_url}\n\tCurrent title: #{instance.title}"133 end134 end135 site Howitzer.app_uri.site136 def initialize137 check_validations_are_defined!138 current_window.maximize if Howitzer.maximized_window &&139 !%w[chrome headless_chrome].include?(Capybara.current_driver)140 end141 # Reloads current page in a browser...

Full Screen

Full Screen

web_page.rb

Source:web_page.rb Github

copy

Full Screen

...74 #75 # *Returns:*76 # * +string+ - page name77 #78 def self.current_page79 page_list = matched_pages80 if page_list.count.zero?81 UnknownPage82 elsif page_list.count > 183 log.error Howitzer::AmbiguousPageMatchingError,84 "Current page matches more that one page class (#{page_list.join(', ')}).\n" \85 "\tCurrent url: #{current_url}\n\tCurrent title: #{title}"86 elsif page_list.count == 187 page_list.first88 end89 end90 ##91 #92 # Waits until web page is not opened, or raise error after timeout93 #94 # *Parameters:*95 # * +time_out+ - Seconds that will be waiting for web page to be loaded96 #97 def self.wait_for_opened(timeout = settings.timeout_small)98 end_time = ::Time.now + timeout99 self.opened? ? return : sleep(0.5) until ::Time.now > end_time100 log.error Howitzer::IncorrectPageError, "Current page: #{current_page}, expected: #{self}.\n" \101 "\tCurrent url: #{current_url}\n\tCurrent title: #{title}"102 end103 ##104 # Returns expanded page url105 #106 # *Parameters:*107 # * +params+ - Params for url expansion.108 #109 def self.expanded_url(params = {})110 if url_template.nil?111 fail ::Howitzer::PageUrlNotSpecifiedError, "Please specify url for '#{self}' page. Example: url '/home'"112 end113 "#{app_url unless self == ::BlankPage}#{Addressable::Template.new(url_template).expand(params)}"114 end...

Full Screen

Full Screen

current_page

Using AI Code Generation

copy

Full Screen

1Howitzer::Web.current_page?(Page::SomePage)2Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage)3Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage, Page::YetAnotherPage)4Howitzer::Web.current_page?(Page::SomePage)5Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage)6Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage, Page::YetAnotherPage)7Howitzer::Web.current_page?(Page::SomePage)8Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage)9Howitzer::Web.current_page?(Page::SomePage, Page::AnotherPage, Page::YetAnotherPage)10Howitzer::Web.current_page?(Page::SomePage)

Full Screen

Full Screen

current_page

Using AI Code Generation

copy

Full Screen

1 def current_page?(page)2 Howitzer::Web.current_page?(page)3 def current_page?(page)4 def current_page?(page)5 def current_page?(page)6 def current_page?(page)7 def current_page?(page)8 def current_page?(page)9 def current_page?(page)10 def current_page?(page)11 def current_page?(page)

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