Re: [wtr-general] Re: problem when locating the element
Sure On Sat, 2 Feb, 2019, 3:02 AM Lakshya Kapoor Awesome! You can checkout some example code and a demo here - > https://kapoorlakshya.github.io/introducing-ffmpeg-screenrecorder > > On Friday, February 1, 2019 at 10:24:00 AM UTC-8, rajagopalan madasami > wrote: >> >> Hi, I have done my framework work, now I am going to include your >> recorder into my project. >> >> On Tue, 6 Nov, 2018, 11:41 PM Lakshya Kapoor > >>> Perfect time to share a gem I am working on :) >>> >>> https://github.com/kapoorlakshya/ffmpeg-screenrecorder >>> >>> This should help you create a video recording of your test execution. >>> You can then host it on streamable or YouTube. >>> >>> On Tuesday, November 6, 2018 at 10:05:04 AM UTC-8, rajagopalan madasami >>> wrote: Hi Justin, I can share my screen if you want. You can take control of my system. Do you have team viewer or do you have any business skype? I can share my screen via that. On Tue 6 Nov, 2018, 11:27 PM Justin Ko >>> > Any chance you can capture a video of the test? It's hard to reconcile > this discussion and logs without seeing anything. > > Justin > > On Tuesday, November 6, 2018 at 12:37:01 PM UTC-5, rajagopalan > madasami wrote: >> >> I am calling this function >> >> def waitForPageLoad >> >> @b.wait_until(timeout: @Page_Load) {@b.execute_script("return >> (jQuery.active === 0)").eql? true} >> end >> >> function in every click function like >> >> def clickButton(locator, action, name, data) >> puts "ClickButton : #{name}" >> loc = getLocator(locator) >> @b.button(loc.first => loc.last).click >> waitForPageLoad >> end >> >> Do you see the clickButton method >> >> calls waitForPageLoad at the end so it waits for the spinner disappear. >> So it doesn't click on the spinner. Even if it clicks at the >> >> spinner it retry it because I have included >> Selenium::WebDriver::Error::ElementClickInterceptedError >> >> rescue Selenium::WebDriver::Error::ElementNotVisibleError, >> Selenium::WebDriver::Error::ElementNotInteractableError,Selenium::WebDriver::Error::ElementClickInterceptedError >> raise_present unless Wait.timer.remaining_time.positive? >> raise_present unless %i[wait_for_present wait_for_enabled >> wait_for_writable].include?(precondition) >> retry >> >> So all I am seeing here is, It perfectlys lands on a page, and it >> successfully enters into the click method but it waits for 30 seconds >> and it fails. >> >> >> >> >> On Tue, 6 Nov 2018 at 22:51, Titus Fortner >> wrote: >> >>> Yes, this makes sense from the code perspective. >>> >>> What your site is doing is requiring you to accept an alert, then it >>> does some kind of processing, then it refreshes some/all of the page. >>> >>> Your code is trying to click the element before the refresh has >>> happened, and because of the way you are rescuing it, it is giving >>> you >>> misleading information. The element was located but couldn't be used, >>> then at the point it is trying to be used it is stale, and that >>> method >>> isn't relocating when stale. >>> >>> Can you raise an issue on Github with this gist? Something like >>> "Watir >>> should relocate stale elements when trying to click them" >>> >>> In the meantime, something like this should work: >>> >>> @b.alert.ok >>> @b.div(id: "spinnerOverlay").wait_while(&:present?) >>> @b.button(id: "NavContinue").click >>> >>> >>> On Tue, Nov 6, 2018 at 10:56 AM wrote: >>> > >>> > Hi Titus, >>> > >>> > Here is the gist url >>> > >>> > >>> https://gist.github.com/Rajagopalan-M/ba78aed6342c61d07968cfe195d3f4de >>> > >>> > -- >>> > -- >>> > Before posting, please read >>> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group >>> . >>> > In short: search before you ask, be nice. >>> > >>> > watir-...@googlegroups.com >>> > http://groups.google.com/group/watir-general >>> > watir-genera...@googlegroups.com >>> > --- >>> > You received this message because you are subscribed to the Google >>> Groups "Watir General" group. >>> > To unsubscribe from this group and stop receiving emails from it, >>> send an email to watir-genera...@googlegroups.com. >>> > For more options, visit https://groups.google.com/d/optout. >>> >>> -- >>> -- >>> Before posting, please read >>> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. >>> >>> In short: search before you ask, be nice. >>> >>> watir-...@googlegroups.com >>> http://groups.google.com/group/watir-general >>> watir-genera...@googlegroups.com >>> ---
[wtr-general] Re: Is there an autogenerated method in page-object that tell if the element is present?
Thanks Justin.. I have two more question though. 1. How does the the method in monkey_path.b takes precedence over the method in actual page-object gem? 2. There are may intances in the application where a div element receives the click rather than a button. eg div(:expand_perks_section_icon, :css => '.icon-plus-wrapper') This element is a div and receives the click as shown below. def expand_perks_section expand_perks_section_icon_element.when_present.click end Writing a separate method each time for such things is really a pain. Is there a better solution for such cases On Friday, 1 February 2019 00:11:33 UTC+11, NaviHan wrote: > > I have an element defined as > > div(:reward_history, :class => 'reward-history-header') > > > The page-object gem generated four methods for this element which are > > > 'reward_history', 'reward_history_element', and 'reward_history?' > > > > The fourth method 'reward_history?' check if the element exists in the > DOM? > > > But what if the element exists in the DOM but is hidden, which is > basically checking if the element is present? > > > Is there an autogenerated method for this? > > I tried 'reward_history(:?)' but didn't work > > As of now I have to write a method separately which does this > > def is_reward_history_present? > return reward_history_element.present? > end > > > > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[wtr-general] Re: Usage of block in hooks.rb
There is no difference in functionality from a Hooks perspective. They both work the same way, except that the in the second one you are getting access to the Scenario details (object). Actually, you can come both the *Before *hooks to achieve the same result: Before do|scenario| @browser = browser ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil DataMagic.load_for_scenario(scenario) @browser.window.maximize @browser.driver.manage.timeouts.implicit_wait = 0 @browser.cookies.clear @browser.driver.manage.window.maximize PageObject.default_element_wait=(10) PageObject.javascript_framework = :jquery #Selenium::WebDriver.logger.level = :info end #before scenario On Friday, February 1, 2019 at 4:07:08 AM UTC-8, NaviHan wrote: > > Hi Lakshya > > Here is the hooks.rb used in our project.. > > Eventhough the the browser is assigned to instance variable @browser we > still get to see all the details you mentioned. So Im not quite getting the > difference between the two Before hooks > > require 'rubygems' > require 'page-object' > require 'watir' > require 'page-object/page_factory' > require 'log4r' > require 'cucumber' > require 'selenium-webdriver' > require 'fig_newton' > require 'watir-screenshot-stitch' > require 'mini_magick' > > args = ['--allow-running-insecure-content'] > browser = Watir::Browser.new :chrome, options: {args: args} > $code_retry = 30 > > Before do > @browser = browser > end > > > Before do|scenario| > ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil > DataMagic.load_for_scenario(scenario) > @browser.window.maximize > @browser.driver.manage.timeouts.implicit_wait = 0 > @browser.cookies.clear > @browser.driver.manage.window.maximize > PageObject.default_element_wait=(10) > PageObject.javascript_framework = :jquery > #Selenium::WebDriver.logger.level = :info > end #before scenario > > > > > # "after all" > After do |scenario| > @browser.execute_script("javascript:localStorage.clear();") > @browser.cookies.clear > if (scenario.passed?) >puts 'Scenario Passed !' > else >puts 'Scenario Failed !' > end > end > > > > AfterStep('@screen') do >filename = DateTime.now.strftime("%d%b%Y%H%M%S") >@browser.screenshot.save > ("C:/Users/lohit.kotian/Documents/Automation/screenshots-cucumber/#{filename}.png") >#@browser.screenshot.save > ("C:/Jenkins/workspace/screenshots-cucumber/#{filename}.png") > end > > > Around('@multipletimes') do |scenario, block| > $counter = 0 > $total_times_to_run = 6 > while $counter < $total_times_to_run do > block.call > puts("Total times scripts were repeated = #$counter" ) > $counter +=1 > end > end > > > After do |scenario| > take_screenshot(@browser, scenario) > end > > at_exit do > browser.close > end > > # need to check this code for the full page screenshots as a part of the > enhancement > > def take_screenshot(browser, scenario) > time = Time.now.strftime("%Y-%m-%d_%H%M") > opts = {:page_height_limit => 5000} > if scenario.failed? > scenario_name = scenario.name.gsub(/[^\w\-]/, ' ') > screenshot_path = "#{scenario_name}" + "_failure_" + time > > @browser.screenshot.save_stitch("./screenshots/#{screenshot_path}.png", > browser, opts) > end > end > > > > > > On Tuesday, 29 January 2019 16:47:10 UTC+11, NaviHan wrote: >> >> Hi all >> >> Im just looking for some good documentation which explains the usage of >> blocks in hooks.rb >> >> For example "Before", "After" , "AfterStep" etc... >> >> Thanks in advance >> > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [wtr-general] Re: problem when locating the element
Awesome! You can checkout some example code and a demo here - https://kapoorlakshya.github.io/introducing-ffmpeg-screenrecorder On Friday, February 1, 2019 at 10:24:00 AM UTC-8, rajagopalan madasami wrote: > > Hi, I have done my framework work, now I am going to include your recorder > into my project. > > On Tue, 6 Nov, 2018, 11:41 PM Lakshya Kapoor wrote: > >> Perfect time to share a gem I am working on :) >> >> https://github.com/kapoorlakshya/ffmpeg-screenrecorder >> >> This should help you create a video recording of your test execution. You >> can then host it on streamable or YouTube. >> >> On Tuesday, November 6, 2018 at 10:05:04 AM UTC-8, rajagopalan madasami >> wrote: >>> >>> Hi Justin, I can share my screen if you want. You can take control of my >>> system. Do you have team viewer or do you have any business skype? I can >>> share my screen via that. >>> >>> On Tue 6 Nov, 2018, 11:27 PM Justin Ko >> Any chance you can capture a video of the test? It's hard to reconcile this discussion and logs without seeing anything. Justin On Tuesday, November 6, 2018 at 12:37:01 PM UTC-5, rajagopalan madasami wrote: > > I am calling this function > > def waitForPageLoad > > @b.wait_until(timeout: @Page_Load) {@b.execute_script("return > (jQuery.active === 0)").eql? true} > end > > function in every click function like > > def clickButton(locator, action, name, data) > puts "ClickButton : #{name}" > loc = getLocator(locator) > @b.button(loc.first => loc.last).click > waitForPageLoad > end > > Do you see the clickButton method > > calls waitForPageLoad at the end so it waits for the spinner disappear. > So it doesn't click on the spinner. Even if it clicks at the > > spinner it retry it because I have included > Selenium::WebDriver::Error::ElementClickInterceptedError > > rescue Selenium::WebDriver::Error::ElementNotVisibleError, > Selenium::WebDriver::Error::ElementNotInteractableError,Selenium::WebDriver::Error::ElementClickInterceptedError > raise_present unless Wait.timer.remaining_time.positive? > raise_present unless %i[wait_for_present wait_for_enabled > wait_for_writable].include?(precondition) > retry > > So all I am seeing here is, It perfectlys lands on a page, and it > successfully enters into the click method but it waits for 30 seconds and > it fails. > > > > > On Tue, 6 Nov 2018 at 22:51, Titus Fortner > wrote: > >> Yes, this makes sense from the code perspective. >> >> What your site is doing is requiring you to accept an alert, then it >> does some kind of processing, then it refreshes some/all of the page. >> >> Your code is trying to click the element before the refresh has >> happened, and because of the way you are rescuing it, it is giving you >> misleading information. The element was located but couldn't be used, >> then at the point it is trying to be used it is stale, and that method >> isn't relocating when stale. >> >> Can you raise an issue on Github with this gist? Something like "Watir >> should relocate stale elements when trying to click them" >> >> In the meantime, something like this should work: >> >> @b.alert.ok >> @b.div(id: "spinnerOverlay").wait_while(&:present?) >> @b.button(id: "NavContinue").click >> >> >> On Tue, Nov 6, 2018 at 10:56 AM wrote: >> > >> > Hi Titus, >> > >> > Here is the gist url >> > >> > >> https://gist.github.com/Rajagopalan-M/ba78aed6342c61d07968cfe195d3f4de >> > >> > -- >> > -- >> > Before posting, please read >> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group >> . >> > In short: search before you ask, be nice. >> > >> > watir-...@googlegroups.com >> > http://groups.google.com/group/watir-general >> > watir-genera...@googlegroups.com >> > --- >> > You received this message because you are subscribed to the Google >> Groups "Watir General" group. >> > To unsubscribe from this group and stop receiving emails from it, >> send an email to watir-genera...@googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> -- >> Before posting, please read >> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. >> >> >> In short: search before you ask, be nice. >> >> watir-...@googlegroups.com >> http://groups.google.com/group/watir-general >> watir-genera...@googlegroups.com >> --- >> You received this message because you are subscribed to the Google >> Groups "Watir General" group. >> To unsubscribe from this group and stop receiving
Re: [wtr-general] Re: problem when locating the element
Hi, I have done my framework work, now I am going to include your recorder into my project. On Tue, 6 Nov, 2018, 11:41 PM Lakshya Kapoor Perfect time to share a gem I am working on :) > > https://github.com/kapoorlakshya/ffmpeg-screenrecorder > > This should help you create a video recording of your test execution. You > can then host it on streamable or YouTube. > > On Tuesday, November 6, 2018 at 10:05:04 AM UTC-8, rajagopalan madasami > wrote: >> >> Hi Justin, I can share my screen if you want. You can take control of my >> system. Do you have team viewer or do you have any business skype? I can >> share my screen via that. >> >> On Tue 6 Nov, 2018, 11:27 PM Justin Ko > >>> Any chance you can capture a video of the test? It's hard to reconcile >>> this discussion and logs without seeing anything. >>> >>> Justin >>> >>> On Tuesday, November 6, 2018 at 12:37:01 PM UTC-5, rajagopalan madasami >>> wrote: I am calling this function def waitForPageLoad @b.wait_until(timeout: @Page_Load) {@b.execute_script("return (jQuery.active === 0)").eql? true} end function in every click function like def clickButton(locator, action, name, data) puts "ClickButton : #{name}" loc = getLocator(locator) @b.button(loc.first => loc.last).click waitForPageLoad end Do you see the clickButton method calls waitForPageLoad at the end so it waits for the spinner disappear. So it doesn't click on the spinner. Even if it clicks at the spinner it retry it because I have included Selenium::WebDriver::Error::ElementClickInterceptedError rescue Selenium::WebDriver::Error::ElementNotVisibleError, Selenium::WebDriver::Error::ElementNotInteractableError,Selenium::WebDriver::Error::ElementClickInterceptedError raise_present unless Wait.timer.remaining_time.positive? raise_present unless %i[wait_for_present wait_for_enabled wait_for_writable].include?(precondition) retry So all I am seeing here is, It perfectlys lands on a page, and it successfully enters into the click method but it waits for 30 seconds and it fails. On Tue, 6 Nov 2018 at 22:51, Titus Fortner wrote: > Yes, this makes sense from the code perspective. > > What your site is doing is requiring you to accept an alert, then it > does some kind of processing, then it refreshes some/all of the page. > > Your code is trying to click the element before the refresh has > happened, and because of the way you are rescuing it, it is giving you > misleading information. The element was located but couldn't be used, > then at the point it is trying to be used it is stale, and that method > isn't relocating when stale. > > Can you raise an issue on Github with this gist? Something like "Watir > should relocate stale elements when trying to click them" > > In the meantime, something like this should work: > > @b.alert.ok > @b.div(id: "spinnerOverlay").wait_while(&:present?) > @b.button(id: "NavContinue").click > > > On Tue, Nov 6, 2018 at 10:56 AM wrote: > > > > Hi Titus, > > > > Here is the gist url > > > > > https://gist.github.com/Rajagopalan-M/ba78aed6342c61d07968cfe195d3f4de > > > > -- > > -- > > Before posting, please read > https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group > . > > In short: search before you ask, be nice. > > > > watir-...@googlegroups.com > > http://groups.google.com/group/watir-general > > watir-genera...@googlegroups.com > > --- > > You received this message because you are subscribed to the Google > Groups "Watir General" group. > > To unsubscribe from this group and stop receiving emails from it, > send an email to watir-genera...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > -- > -- > Before posting, please read > https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. > > In short: search before you ask, be nice. > > watir-...@googlegroups.com > http://groups.google.com/group/watir-general > watir-genera...@googlegroups.com > --- > You received this message because you are subscribed to the Google > Groups "Watir General" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to watir-genera...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- >>> -- >>> Before posting, please read >>> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. >>> >>> In short: search before you ask, be nice. >>> >>> watir-...@googlegroups.com >>>
[wtr-general] Re: Is there an autogenerated method in page-object that tell if the element is present?
Yes, that would work. Personally, I find "falsey" hard to type. Technically it also includes "nil", though #present? shouldn't return that. I tend to go with: expect(on(MyAccountPage).reward_history?).to eq false The monkey patch is redefining the method. It's one of those good and bad things that Ruby lets you do. Justin On Thursday, January 31, 2019 at 6:18:51 PM UTC-5, NaviHan wrote: > > Thanks Justin for creating a feature request. > > What I have done is I have created a file name monkeypatch.rb and put the > code you have given in there. > Changed the script to use and it passed. > > expect(on(MyAccountPage).reward_history?).to be_falsey > > Could you please confirm if this is the right way to do this. > > By the way Im confused how the script know it has to give priority to > standard_methods in the monkypatch.rb rather in the actual PageObject > module? > > > On Friday, 1 February 2019 00:11:33 UTC+11, NaviHan wrote: >> >> I have an element defined as >> >> div(:reward_history, :class => 'reward-history-header') >> >> >> The page-object gem generated four methods for this element which are >> >> >> 'reward_history', 'reward_history_element', and 'reward_history?' >> >> >> >> The fourth method 'reward_history?' check if the element exists in the >> DOM? >> >> >> But what if the element exists in the DOM but is hidden, which is >> basically checking if the element is present? >> >> >> Is there an autogenerated method for this? >> >> I tried 'reward_history(:?)' but didn't work >> >> As of now I have to write a method separately which does this >> >> def is_reward_history_present? >> return reward_history_element.present? >> end >> >> >> >> -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[wtr-general] Re: Usage of block in hooks.rb
Hi Lakshya Here is the hooks.rb used in our project.. Eventhough the the browser is assigned to instance variable @browser we still get to see all the details you mentioned. So Im not quite getting the difference between the two Before hooks require 'rubygems' require 'page-object' require 'watir' require 'page-object/page_factory' require 'log4r' require 'cucumber' require 'selenium-webdriver' require 'fig_newton' require 'watir-screenshot-stitch' require 'mini_magick' args = ['--allow-running-insecure-content'] browser = Watir::Browser.new :chrome, options: {args: args} $code_retry = 30 Before do @browser = browser end Before do|scenario| ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil DataMagic.load_for_scenario(scenario) @browser.window.maximize @browser.driver.manage.timeouts.implicit_wait = 0 @browser.cookies.clear @browser.driver.manage.window.maximize PageObject.default_element_wait=(10) PageObject.javascript_framework = :jquery #Selenium::WebDriver.logger.level = :info end #before scenario # "after all" After do |scenario| @browser.execute_script("javascript:localStorage.clear();") @browser.cookies.clear if (scenario.passed?) puts 'Scenario Passed !' else puts 'Scenario Failed !' end end AfterStep('@screen') do filename = DateTime.now.strftime("%d%b%Y%H%M%S") @browser.screenshot.save ("C:/Users/lohit.kotian/Documents/Automation/screenshots-cucumber/#{filename}.png") #@browser.screenshot.save ("C:/Jenkins/workspace/screenshots-cucumber/#{filename}.png") end Around('@multipletimes') do |scenario, block| $counter = 0 $total_times_to_run = 6 while $counter < $total_times_to_run do block.call puts("Total times scripts were repeated = #$counter" ) $counter +=1 end end After do |scenario| take_screenshot(@browser, scenario) end at_exit do browser.close end # need to check this code for the full page screenshots as a part of the enhancement def take_screenshot(browser, scenario) time = Time.now.strftime("%Y-%m-%d_%H%M") opts = {:page_height_limit => 5000} if scenario.failed? scenario_name = scenario.name.gsub(/[^\w\-]/, ' ') screenshot_path = "#{scenario_name}" + "_failure_" + time @browser.screenshot.save_stitch("./screenshots/#{screenshot_path}.png", browser, opts) end end On Tuesday, 29 January 2019 16:47:10 UTC+11, NaviHan wrote: > > Hi all > > Im just looking for some good documentation which explains the usage of > blocks in hooks.rb > > For example "Before", "After" , "AfterStep" etc... > > Thanks in advance > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.