How to use current_url method of Howitzer.Web Package

Best Howitzer_ruby code snippet using Howitzer.Web.current_url

web_page_spec.rb

Source:web_page_spec.rb Github

copy

Full Screen

...44 let(:page) { double }45 subject { described_class.instance.title }46 before do47 allow_any_instance_of(described_class).to receive(:check_validations_are_defined!) { true }48 allow(described_class.instance).to receive(:current_url) { 'google.com' }49 end50 it do51 expect(described_class.instance).to receive(:page) { page }52 expect(page).to receive(:title)53 subject54 end55 end56 describe '.current_url' do57 let(:page) { double }58 subject { described_class.current_url }59 it do60 expect(described_class).to receive(:page) { page }61 expect(page).to receive(:current_url) { 'google.com' }62 is_expected.to eq('google.com')63 end64 end65 describe '.current_url' do66 let(:page) { double }67 subject { described_class.current_url }68 it do69 expect(described_class).to receive(:page) { page }70 expect(page).to receive(:current_url) { 'google.com' }71 is_expected.to eq('google.com')72 end73 end74 describe '.text' do75 let(:page) { double }76 let(:find) { double }77 subject { described_class.text }78 it do79 expect(described_class).to receive(:page) { page }80 expect(page).to receive(:find).with('body') { find }81 expect(find).to receive(:text) { 'some body text' }82 is_expected.to eq('some body text')83 end84 end85 describe '.current_page' do86 subject { described_class.current_page }87 context 'when matched_pages has no pages' do88 before { allow(described_class).to receive(:matched_pages) { [] } }89 it { is_expected.to eq(described_class::UnknownPage) }90 end91 context 'when matched_pages has more than 1 page' do92 let(:foo_page) { double(inspect: 'FooPage') }93 let(:bar_page) { double(inspect: 'BarPage') }94 before do95 allow(described_class).to receive(:current_url) { 'http://test.com' }96 allow(described_class).to receive(:title) { 'Test site' }97 allow(described_class).to receive(:matched_pages) { [foo_page, bar_page] }98 end99 it do100 expect(log).to receive(:error).with(101 Howitzer::AmbiguousPageMatchingError,102 "Current page matches more that one page class (FooPage, BarPage).\n" \103 "\tCurrent url: http://test.com\n\tCurrent title: Test site"104 ).once105 subject106 end107 end108 context 'when matched_pages has only 1 page' do109 let(:foo_page) { double(to_s: 'FooPage') }110 before { allow(described_class).to receive(:matched_pages) { [foo_page] } }111 it { is_expected.to eq(foo_page) }112 end113 end114 describe '.wait_for_opened' do115 subject { described_class.wait_for_opened }116 context 'when page is opened' do117 before { allow(described_class).to receive(:opened?) { true } }118 it { is_expected.to be_nil }119 end120 context 'when page is not opened' do121 before do122 allow(described_class).to receive(:current_page) { 'FooPage' }123 allow(described_class).to receive(:current_url) { 'http://test.com' }124 allow(described_class).to receive(:title) { 'Test site' }125 allow(settings).to receive(:timeout_small) { 0.1 }126 allow(described_class).to receive(:opened?) { false }127 end128 it do129 expect(log).to receive(:error).with(130 Howitzer::IncorrectPageError,131 "Current page: FooPage, expected: WebPage.\n\tCurrent url: http://test.com\n\tCurrent title: Test site"132 )133 subject134 end135 end136 end137 describe '.expanded_url' do138 context 'when params present' do139 subject { web_page.expanded_url(id: 1) }140 context 'when page url specified' do141 context 'when BlankPage' do142 let(:web_page) { ::BlankPage }143 before do144 stub_const('::BlankPage', described_class)145 allow(web_page).to receive(:url_template) { 'about:blank' }146 end147 it { is_expected.to eq('about:blank') }148 end149 context 'when other page' do150 let(:web_page) { described_class }151 before do152 stub_const('::BlankPage', double)153 allow(web_page).to receive(:url_template) { '/users{/id}' }154 end155 it { is_expected.to eq('http://my.website.com/users/1') }156 end157 end158 context 'when page url missing' do159 subject { described_class.expanded_url }160 before { stub_const('::BlankPage', double) }161 it do162 expect { subject }.to raise_error(163 ::Howitzer::PageUrlNotSpecifiedError,164 "Please specify url for '#{described_class}' page. Example: url '/home'"165 )166 end167 end168 end169 context 'when params missing' do170 subject { described_class.expanded_url }171 before do172 allow(described_class).to receive(:url_template) { '/users' }173 stub_const('::BlankPage', double)174 end175 it { is_expected.to eq('http://my.website.com/users') }176 end177 end178 describe '.url' do179 subject { described_class.send(:url, value) }180 before { subject }181 context 'when value is number' do182 let(:value) { 1 }183 it { expect(described_class.instance_variable_get(:@url_template)).to eq('1') }184 end185 context 'when value is string' do186 let(:value) { '/users' }187 it { expect(described_class.instance_variable_get(:@url_template)).to eq('/users') }188 end189 end190 describe '#initialize' do191 subject { described_class.send(:new) }192 before do193 expect_any_instance_of(described_class).to receive(:check_validations_are_defined!).once { true }194 end195 context 'when maximized_window is true' do196 before { allow(settings).to receive(:maximized_window) { true } }197 it do198 expect_any_instance_of(described_class).to receive_message_chain('page.driver.browser.manage.window.maximize')199 subject200 end201 end202 context 'when maximized_window is false' do203 before { allow(settings).to receive(:maximized_window) { false } }204 it do205 expect_any_instance_of(described_class).not_to receive('page')206 subject207 end208 end209 end210 describe 'inherited callback' do211 let!(:page_class) do212 Howitzer::Utils::PageValidator.instance_variable_set(:@pages, [])213 Class.new(described_class)214 end215 it { expect(Howitzer::Utils::PageValidator.pages).to eq([page_class]) }216 it 'can not be instantiated with new' do217 expect { page_class.new }.to raise_error(NoMethodError, "private method `new' called for #{page_class}")218 end219 end220 describe '#tinymce_fill_in' do221 subject { described_class.instance.tinymce_fill_in(name, options) }222 let(:name) { 'name' }223 let(:options) { { with: 'some content' } }224 before do225 allow(described_class.instance).to receive(:current_url) { 'google.com' }226 allow(settings).to receive(:driver) { driver_name }227 end228 context 'when correct driver specified' do229 let(:driver_name) { 'selenium' }230 let(:page) { double }231 let(:driver) { double }232 let(:browser) { double }233 let(:switch_to) { double }234 let(:find) { double }235 let(:native) { double }236 it do237 expect(described_class.instance).to receive(:page).exactly(3).times { page }238 expect(page).to receive(:driver).ordered { driver }239 expect(driver).to receive(:browser).ordered { browser }240 expect(browser).to receive(:switch_to).ordered { switch_to }241 expect(switch_to).to receive(:frame).with('name_ifr').once242 expect(page).to receive(:find).with(:css, '#tinymce').ordered { find }243 expect(find).to receive(:native).ordered { native }244 expect(native).to receive(:send_keys).with('some content').once245 expect(page).to receive(:driver) { driver }246 expect(driver).to receive(:browser) { browser }247 expect(browser).to receive(:switch_to) { switch_to }248 expect(switch_to).to receive(:default_content)249 subject250 end251 end252 context 'when incorrect driver specified' do253 let(:driver_name) { 'ff' }254 let(:page) { double }255 it do256 expect(described_class.instance).to receive(:page) { page }257 expect(page).to receive(:execute_script).with("tinyMCE.get('name').setContent('some content')")258 subject259 end260 end261 end262 describe '#click_alert_box' do263 subject { described_class.instance.click_alert_box(flag_value) }264 before do265 allow(settings).to receive(:driver) { driver_name }266 allow(settings).to receive(:timeout_tiny) { 0 }267 allow(described_class.instance).to receive(:current_url) { 'google.com' }268 end269 context 'when flag true and correct driver specified' do270 let(:flag_value) { true }271 let(:page) { double }272 let(:alert) { double }273 let(:driver) { double }274 let(:browser) { double }275 let(:switch_to) { double }276 let(:driver_name) { 'selenium' }277 it do278 expect(described_class.instance).to receive(:page) { page }279 expect(page).to receive(:driver).ordered { driver }280 expect(driver).to receive(:browser).ordered { browser }281 expect(browser).to receive(:switch_to).ordered { switch_to }282 expect(switch_to).to receive(:alert).ordered { alert }283 expect(alert).to receive(:accept).once284 subject285 end286 end287 context 'when flag false and correct driver specified' do288 let(:flag_value) { false }289 let(:page) { double }290 let(:alert) { double }291 let(:driver) { double }292 let(:browser) { double }293 let(:switch_to) { double }294 let(:driver_name) { 'selenium' }295 it do296 expect(described_class.instance).to receive(:page) { page }297 expect(page).to receive(:driver).ordered { driver }298 expect(driver).to receive(:browser).ordered { browser }299 expect(browser).to receive(:switch_to).ordered { switch_to }300 expect(switch_to).to receive(:alert).ordered { alert }301 expect(alert).to receive(:dismiss).once302 subject303 end304 end305 context 'when flag true and wrong driver specified' do306 let(:flag_value) { true }307 let(:page) { double }308 let(:driver_name) { 'ff' }309 it do310 expect(described_class.instance).to receive(:page) { page }311 expect(page).to receive(:evaluate_script).with('window.confirm = function() { return true; }')312 subject313 end314 end315 context 'when flag false and wrong driver specified' do316 let(:driver_name) { 'ff' }317 let(:flag_value) { false }318 let(:page) { double }319 it do320 expect(described_class.instance).to receive(:page) { page }321 expect(page).to receive(:evaluate_script).with('window.confirm = function() { return false; }')322 subject323 end324 end325 end326 describe '#js_click' do327 subject { described_class.instance.js_click('.some_class') }328 before do329 allow(settings).to receive(:timeout_tiny) { 0.1 }330 allow(described_class.instance).to receive(:current_url) { 'google.com' }331 end332 let(:page) { double }333 it do334 expect(described_class.instance).to receive(:page) { page }335 expect(page).to receive(:execute_script).with("$('.some_class').trigger('click')")336 subject337 end338 end339 describe '#reload' do340 let(:wait_for_url) { double }341 subject { described_class.instance.reload }342 let(:visit) { double }343 before do344 allow(described_class.instance).to receive(:current_url) { 'google.com' }345 stub_const('WebPage::URL_PATTERN', 'pattern')346 allow(wait_for_url).to receive('pattern') { true }347 end348 it do349 expect(log).to receive(:info) { "Reload 'google.com'" }350 expect(described_class.instance).to receive(:visit).with('google.com')351 subject352 end353 end354end...

Full Screen

Full Screen

page_validator_spec.rb

Source:page_validator_spec.rb Github

copy

Full Screen

...230 end231 end232 context 'when all matches' do233 before do234 allow(web_page_class).to receive(:current_url) { 'http://test.com/foo' }235 allow(web_page_class).to receive(:title) { 'Foo page' }236 allow(web_page_class).to receive(:first_element).with(:login) { true }237 end238 it { is_expected.to be_truthy }239 end240 context 'when first does not match' do241 before do242 expect(web_page_class).to receive(:current_url).once { 'http://test.com/bar' }243 expect(web_page_class).to receive(:title).never244 expect(web_page_class).to receive(:first_element).never245 end246 it { is_expected.to be_falsey }247 end248 end249 end250 describe '#matched_pages' do251 let!(:web_page1_class) do252 Class.new do253 include Howitzer::Utils::PageValidator254 def self.name255 'TestWebPage1Class'256 end...

Full Screen

Full Screen

web_page.rb

Source:web_page.rb Github

copy

Full Screen

...54 #55 # *Returns:*56 # * +string+ - Current url57 #58 def self.current_url59 page.current_url60 end61 ##62 #63 # Returns body text of html page64 #65 # *Returns:*66 # * +string+ - Body text67 #68 def self.text69 page.find('body').text70 end71 ##72 #73 # Tries to identify current page name or raise error if ambiguous page matching74 #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 end115 class << self116 protected117 ##118 #119 # DSL to specify page url120 #121 # *Parameters:*122 # * +value+ - url pattern, for details please see Addressable gem123 #124 def url(value)125 @url_template = value.to_s126 end127 private128 attr_reader :url_template129 end130 def initialize131 check_validations_are_defined!132 page.driver.browser.manage.window.maximize if settings.maximized_window133 end134 ##135 #136 # Fills in field that using Tinymce API137 #138 # *Parameters:*139 # * +name+ - Frame name that contains Tinymce field140 # * +Hash+ - Not required options141 #142 def tinymce_fill_in(name, options = {})143 if %w(selenium selenium_dev sauce).include?(settings.driver)144 browser_tinymce_fill_in(name, options)145 else146 page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')")147 end148 end149 ##150 #151 # Accepts or declines JS alert box by given flag152 #153 # *Parameters:*154 # * +flag+ [TrueClass,FalseClass] - Determines accept or decline alert box155 #156 def click_alert_box(flag)157 if %w(selenium selenium_dev sauce).include? settings.driver158 alert = page.driver.browser.switch_to.alert159 flag ? alert.accept : alert.dismiss160 else161 page.evaluate_script("window.confirm = function() { return #{flag}; }")162 end163 end164 ##165 #166 # Clicks on button or link using JS event call167 #168 # *Parameters:*169 # * +css_locator+ - Css locator of link or button170 #171 def js_click(css_locator)172 page.execute_script("$('#{css_locator}').trigger('click')")173 sleep settings.timeout_tiny174 end175 ##176 #177 # Reloads current page178 #179 def reload180 log.info "Reload '#{current_url}'"181 visit current_url182 end183 ##184 #185 # Returns Page title186 #187 # *Returns:*188 # * +string+ - Page title189 #190 def title191 page.title192 end193 private194 def browser_tinymce_fill_in(name, options = {})195 page.driver.browser.switch_to.frame("#{name}_ifr")...

Full Screen

Full Screen

current_url

Using AI Code Generation

copy

Full Screen

1Howitzer::Web::Page.new(:foo) { current_url }2Howitzer::Web::Page.new(:foo).current_url3Howitzer::Web::Page.new(:foo) { |page| page.current_url }4Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url5Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url6Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url7Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url

Full Screen

Full Screen

current_url

Using AI Code Generation

copy

Full Screen

1Howitzer::Web::Page.new(:foo) { current_url }2Howitzer::Web::Page.new(:foo).current_url3Howitzer::Web::Page.new(:foo) { |page| page.current_url }4Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url5Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url6Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url7Howitzer::Web::Page.new(:foo) { |page| page.current_url }.current_url

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