[wtr-general] Re: How often to get element reference, best practice?

2018-09-12 Thread NaviHan
Hi Titus

Thats makes it very clear now :-)

Just to confirm, action methods as in set, click, select
And the reading attribute values like id, text, or any other custom 
attribute are not auto covered and we need to use wait_until(&:present?)

Is that correct?

Cheers
Navi

On Tuesday, 11 September 2018 14:52:33 UTC+10, NaviHan wrote:
>
> This is something that keeps me a bit sceptic when I write and read the 
> automation code in my project.
> This used PageObjects.
>
> I have seen extensive use of element referces, for example 
>
> button(:add_to_bag, :css => '#add-to-cart')
> add_to_bag.element.when_present.click
>
>
>
> instead of 
>
> add_to_bag 
>
> which directly clicks the element
>
> I have also seen extensive use of referencing elements using 
> .when_present, .wait_until_present etc
>
> Im confused where we should draw the line when deciding to reference the 
> element and actually using it(as in directly calling "add_o_bag" in the above 
> example to click the element.
>
> Any thoughts?
>
>
>

-- 
-- 
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: How often to get element reference, best practice?

2018-09-12 Thread Titus Fortner
Yeah, it is automatic only for action methods, which does not include text.
There's a case to be made to extend that behavior to text since it will
return an empty string if it isn't displayed, but for now you'll need to
keep the wait.



On Wed, Sep 12, 2018, 8:19 PM NaviHan  wrote:

> Hi Titus
>
> Thanks for the detailed explanation and the documentation link.
> Unfortunately my confusion doesnt get clarified.
>
> As you said for an element which eventually displays, for example a pop up
> that appears due to a user action, we can read the text by
>
> *scenario 1*
> "my_element.when_present.text" because when_present get info from element
> that eventually *displays*
>
> The above changed to my_element.text, post Watir6.0 as the wait was made
> automatic
>
> *scenario 2*
> "my_element.wait_until(&:present?).text" also waits for the element to be
> displayed like "my_element.when_present.text"
> So they are one and the same.
>
> Because they are one and the same and post Watir6.0 the when_present wait
> was made automatic we can achieve the above objective with "my_element.text"
>
> So there will never be a case where we have to use wait_until(&:present?).
>
> This is my theory.
> Is that correct?
>
> Cheers
> Navi
>
>
> On Tuesday, 11 September 2018 14:52:33 UTC+10, NaviHan wrote:
>>
>> This is something that keeps me a bit sceptic when I write and read the
>> automation code in my project.
>> This used PageObjects.
>>
>> I have seen extensive use of element referces, for example
>>
>> button(:add_to_bag, :css => '#add-to-cart')
>> add_to_bag.element.when_present.click
>>
>>
>>
>> instead of
>>
>> add_to_bag
>>
>> which directly clicks the element
>>
>> I have also seen extensive use of referencing elements using 
>> .when_present, .wait_until_present etc
>>
>> Im confused where we should draw the line when deciding to reference the 
>> element and actually using it(as in directly calling "add_o_bag" in the 
>> above example to click the element.
>>
>> Any thoughts?
>>
>>
>> --
> --
> 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.


[wtr-general] Re: wait_for_ajax method in PageObject gem, how to use in hooks?

2018-09-12 Thread Justin Ko
Hi Navi,

I don't think you'll be able to directly call Page-Object's #wait_for_ajax 
from an after hook. You'll have to do the wait directly.

I believe you said you were using jQuery. Where you are initializing the 
browser, add the following line to add the after_hook:

browser = Watir::Browser.new 
browser.after_hooks.add do |browser|
  browser.wait_until { browser.execute_script('return jQuery.active;') == 0 
}
end

Justin

On Tuesday, September 11, 2018 at 12:56:11 AM UTC-4, NaviHan wrote:
>
> We did discuss this previously. Im trying to find a way to use 
> wait_for_ajax for each and every element.
>
> Titus or Justin has earlier suggested to move this to the hooks.rb file.
>
> Could you guys tell me how to use it in hooks?
>
>

-- 
-- 
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: How often to get element reference, best practice?

2018-09-12 Thread NaviHan
Hi Titus

Thanks for the detailed explanation and the documentation link. 
Unfortunately my confusion doesnt get clarified.

As you said for an element which eventually displays, for example a pop up 
that appears due to a user action, we can read the text by

*scenario 1*
"my_element.when_present.text" because when_present get info from element 
that eventually *displays*

The above changed to my_element.text, post Watir6.0 as the wait was made 
automatic

*scenario 2*
"my_element.wait_until(&:present?).text" also waits for the element to be 
displayed like "my_element.when_present.text"
So they are one and the same.

Because they are one and the same and post Watir6.0 the when_present wait 
was made automatic we can achieve the above objective with "my_element.text"

So there will never be a case where we have to use wait_until(&:present?).

This is my theory.
Is that correct?

Cheers
Navi


On Tuesday, 11 September 2018 14:52:33 UTC+10, NaviHan wrote:
>
> This is something that keeps me a bit sceptic when I write and read the 
> automation code in my project.
> This used PageObjects.
>
> I have seen extensive use of element referces, for example 
>
> button(:add_to_bag, :css => '#add-to-cart')
> add_to_bag.element.when_present.click
>
>
>
> instead of 
>
> add_to_bag 
>
> which directly clicks the element
>
> I have also seen extensive use of referencing elements using 
> .when_present, .wait_until_present etc
>
> Im confused where we should draw the line when deciding to reference the 
> element and actually using it(as in directly calling "add_o_bag" in the above 
> example to click the element.
>
> Any thoughts?
>
>
>

-- 
-- 
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: Watir [DEPRECATION] ["stale_present"] Checking `#present? == false`

2018-09-12 Thread rajagopalanmadasami
Yes I saw that in your article, that's best idea. Thanks.

-- 
-- 
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: Watir [DEPRECATION] ["stale_present"] Checking `#present? == false`

2018-09-12 Thread rajagopalanmadasami
You are perfectly correct, yes wait_while(&:exists?) will do the same Job, I 
have not noticed when you explained me first time.thanks.

-- 
-- 
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: Trouble reading the text from Popup , Using Watir and Pageobject

2018-09-12 Thread rajagopalanmadasami
Just wanted to tell you, one more gem was released for page object, did you 
check that out? Its watirpump.

-- 
-- 
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: How often to get element reference, best practice?

2018-09-12 Thread Titus Fortner
Hey Navi, I'm sorry there is so much confusion around the waits. If there 
is something that would make this article 
(http://watir.com/guides/waiting/) more clear, please let me know so I can 
make it better. Maybe I spend too much time focusing on history and 
implementation details that don't matter to you?


Best practice before Watir 6:

Scenario one, click element that eventually displays:
my_element.when_present.click

Scenario two, get info from element that eventually displays:
my_element.when_present.get_attribute('class')

Secnario three, wait for one element then act on another:
my_element1.wait_until_present
my_element2.click

For the first scenario, 
since your test shouldn't attempt to click an element that isn't present, 
Watir 6 made the waiting automatic.

This will now do the exact same thing:
my_element.click

Scenario 2:
Watir waits for the element to exist, but not for it to be displayed. So if 
it needs to be displayed first (usually some kind of dynamic activity on 
the page):

element.wait_until(&:present?).attribute_value('class')

Scenario 3:

element_one.wait_until(&:present?)
element_two.click


We are encouraging everyone to move to the to_proc notation `&:` with the 
wait methods. This drastically simplifies the code we have to maintain 
relative to the benefit to our users. We do still have 
`#wait_until_present` and `#wait_while_present` methods to handle some 
special use cases, but these may go away as well.

Does this clarify things more?




On Tuesday, September 11, 2018 at 9:49:37 PM UTC-7, NaviHan wrote:
>
>
> Hi Titus
>
> You said "when_present" and 'wait_until(&:present?)" does the same thing, 
> which is Waits for element to be present, the former is deprecated and 
> latter is recommended.
>
> Why is that if bot does the same thing
>
> Im trying to understand if "wait_until(&:present?)" is in any ways 
> different from "when_present" eventhough its deprecated.
>
>
> Justin also mentioned on version 6.0 of Watir you made changes to 
> automatically wait for elements before taking actions which let us do away 
> ith "when_present". So I still do not understand why we should ever use 
> wait_until(&:present?) at all.
>
> Sorry if I sound stupid, becasue there is so much cinfusion around waits 
> :-(
>
> Cheers
> Navi
>
> On Tuesday, 11 September 2018 14:52:33 UTC+10, NaviHan wrote:
>>
>> This is something that keeps me a bit sceptic when I write and read the 
>> automation code in my project.
>> This used PageObjects.
>>
>> I have seen extensive use of element referces, for example 
>>
>> button(:add_to_bag, :css => '#add-to-cart')
>> add_to_bag.element.when_present.click
>>
>>
>>
>> instead of 
>>
>> add_to_bag 
>>
>> which directly clicks the element
>>
>> I have also seen extensive use of referencing elements using 
>> .when_present, .wait_until_present etc
>>
>> Im confused where we should draw the line when deciding to reference the 
>> element and actually using it(as in directly calling "add_o_bag" in the 
>> above example to click the element.
>>
>> Any thoughts?
>>
>>
>>

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