In general, what is going on remotely is that the page is taking
slightly longer to load relative to what you have locally, so the
Selenium command is trying to execute before the site is ready for it

Does this help to explain the difference between #wait_until and #wait_while?

browser.wait_until { true } # => returns immediately
browser.wait_until { false } # => will time out
browser.wait_while { true } # => will time out
browser.wait_while { false } # => returns immediately

> 2. On local this passes but on Jenkins box the text is being read as empty

Text will return as empty if the element exists, but it not yet visible.
Ideally waiting for text to not be "" should be automatic, but
implementing that with the current code we have is not trivial. :(

So in for now you need to explicitly wait for it to become present first:

cta_description_element.wait_until(&:present?).text.gsub(/[^$,.A-Za-z0-9]/," ")

Based on our conversation here, I just added code that will go into
the next version of Watir that will allow you to do this (which might
be easier to understand?):

cta_description_element.wait_while(text: "").text.gsub(/[^$,.A-Za-z0-9]/," ")





On Wed, Aug 8, 2018 at 4:54 AM NaviHan <hishinessr...@gmail.com> wrote:
>
> ***Please ignore previous message. It was accidently sent before typing 
> completely"
>
> Hi Titus and Rajagopalan and Justin
>
> The hook is written by another automation engineer, so Im yet to understand 
> that fully.
> Considering Im new to automation Im going through the learning curve and you 
> guys are of immense help.
> Tomorrow I will be debugging the script in Jenkins box as to why reading the 
> text from the popup fails just to remind this topic was started for that and 
> in the midst we nailed the javascript issue. The confusion with wait_until 
> and wait_while still bothers me.
>
> Let me make it a bit more clearer to you.
>
> 1. The pop up appears and Im trying to assert two texts in that popup.
> 2. On local this passes but on Jenkins box the text is being read as empty
>
> So Im thinking in the line, wait while the pop up disappears during that time 
> read the texts in the pop up. I have this idea in mind but dont know how to 
> implement that.
> These are the methods..
>
> def rewards_popup_description
>   #return cta_description_element.when_present.text.gsub(/[^$,.A-Za-z0-9]/," 
> ")
>   return cta_description_element.when_present(timeout = 
> 10).text.gsub(/[^$,.A-Za-z0-9]/," ")
>
> end
>
>
> def rewards_popup_expiration
>   return cta_expiry_element.when_present(timeout = 
> 10).text.gsub(/[^$,.A-Za-z0-9]/," ")
> end
>
>
> Instead of this can I do something like, note :- in BOLD is PSEUDO CODE
>
> cta_description_element.wait_while do
>   cta_description_element.visible?   AND READ THE TEXT
> end
>
>
> cheers
>
> On Friday, 3 August 2018 15:12:45 UTC+10, NaviHan wrote:
>>
>> I have a functionality where I click an a link from an email a voucher gets 
>> added to the shopping cart and a pop up appears with a message. Im trying to 
>> assert the text in the popup
>> I have defined the element as
>>
>> div(:cta_description, :css => '.homepage-clicktoactiavte-description')
>>
>> Tried to use a mix of Watir and Pageobejct to read the text. The below code 
>> works 5 out of 10 times.
>>
>> @rewards_popup_txt = Watir::Wait.until{cta_description_element}.text
>> @rewards_popup_txt = @rewards_popup_txt.gsub(/[^$,.A-Za-z0-9]/," ")
>> return @rewards_popup_txt
>>
>>
>> Tried using, which doesnt even set the @reward_popup_txt and shows error
>>
>>
>> if (Watir::Wait.while {cta_description_element.visible?})
>>   @rewards_popup_txt = cta_description_element.text
>> end
>> @rewards_popup_txt = @rewards_popup_txt.gsub(/[^$,.A-Za-z0-9]/," ")
>> return @rewards_popup_txt
>>
>> Error
>> NoMethodError: undefined method `gsub' for nil:NilClass
>> ./features/support/pages/Frontend/Cotton_On/Loyalty_Page.rb:22:in 
>> `rewards_popup_description'
>>
>> Any stable way to do the job?
>
> --
> --
> 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.

-- 
-- 
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.

Reply via email to