Re: [Wtr-general] Syntax for relative attributes
Christian Kreutzer wrote: On 12/22/06, Bret Pettichord [EMAIL PROTECTED] wrote: So we have consistently urged people to wrap their watir expressions in methods rather than assign them to global variables. This makes it easy to reuse them, and ensure that a correct rebinding occurs on each reuse. Also, as i have been using Watir more on large projects, i am finding that there are other reasons why this is a sound way to structure Watir libraries. im not sure if i understand this correctly. text = $ie.text -- so, this is bad because we cant be sure if the rebinding happens just in time when we need it. No. The advice applies to Watir objects, the things that are returned by expressions like $ie.button(:id, 'foo') -- in this a Watir::Button object. Your example ($ie.text) just returns a string, which is unproblematic. I guess you could say that $ie is a watir object, but that wasn't what i was talking about. Clear as mud, i know. Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
I think what bret said is $my_button = $ie.button(:id, 'foo') is a bad idea. It may be better to do something like... def my_button() return( $ie.button(:id, 'foo') ) end while my_string = $ie.text could be fine, though you could still do def my_string() return( $ie.text ) end ... i think The concept being you want to, depending on your situation, write a script that uses some sort of abstraction layer. This means your 'high level' scripts will not need to be changed much at all (I'm doing this, and it works wonders), while your abstraction layer will change with the site. - Posted via Jive Forums http://forums.openqa.org/thread.jspa?threadID=6038messageID=16960#16960 ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
On 12/22/06, Bret Pettichord [EMAIL PROTECTED] wrote: So we have consistently urged people to wrap their watir expressions in methods rather than assign them to global variables. This makes it easy to reuse them, and ensure that a correct rebinding occurs on each reuse. Also, as i have been using Watir more on large projects, i am finding that there are other reasons why this is a sound way to structure Watir libraries. im not sure if i understand this correctly. text = $ie.text -- so, this is bad because we cant be sure if the rebinding happens just in time when we need it. would the following approach be better?: class Page def initialize ie @ie = ie end def text @ie.text end end p = Page.new ie puts p.text the watir expressions are now wrapped in methods but i cant see how the object binding could be different from using global vars. I hope someone can enlighten me on this ;) Christian ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
the watir expressions are now wrapped in methods but i cant see how the object binding could be different from using global vars. I hope someone can enlighten me on this http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/117762add75f59e7/c7bb0338921b15ef?lnk=gstq=global+variablernum=1#c7bb0338921b15ef ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
John Lolis wrote: A second, slightly related question. Regardless of how you do it, i'm wondering whats going on behind the scenes. If you do headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Is headline now 'frozen'? For example, lets say there is a 'addtocart' after headline. What happens if after you create your headline variable the page changes (headline is now at the bottom of the page)? Will the after method re evaluate headlines position in the page? Or is headline now static so after would would be true even if it isn't? I'm not sure if that even made sense. Actually this is a good question. Let's call each of these Watir expressions. They can refer to different objects on different pages, or sometimes they refer to nothing. $ie.div(:text, 'Pragmatic Version Control') $ie.link(:class = 'addtocart', :after? = headline) When they are used, they end up referring to specific control on a specific page at a specific point in time. Let's call this an element reference (internally it is called @o and getOLEobject and ole_object, variously depending on version). This reference is actually a COM object that will become stale as soon as a new page is loaded. However it will remain valid if javascript-based changes are made to the DOM. So your question becomes: What is the relationship between Watir expressions and element references? And the answer depends on whether you are using Watir 1.4 or 1.5. Both versions of Watir use locate methods to tie the Watir objects returned by Watir expressions to the element references, and we might call this process binding. In Watir 1.4, this binding was made at call time. When the expression was executed, the Watir object would be bound. However, if there was a failure to bind (ObjectNotFound), an error would not be raised until you actually made a call to the object -- for example, calling its click method. The reason for this was to allow us to have an exists? method. This method would only return false if we had failed to bind -- not raise an error. In Watir 1.5, i moved the timing of the locate method (in most cases) so that binding itself would not happen until this time -- when we previously were just checking to see if the binding had been made or not. In other words, we had late binding in 1.4 and really-late binding in 1.5. In theory, really-late binding would allow you to create objects that would rebind themselves after a page load. However, i've never encouraged this, nor have i seen any evidence that people have actually been doing this. A big issue is that this automatic rebinding would happen in simple cases but not in complex cases and understanding the difference was really too much to expect from our users. I'm reluctant to even try and explain it, and frankly there are edge cases that i'm unsure of myself, and i also suspect there are bugs. So we have consistently urged people to wrap their watir expressions in methods rather than assign them to global variables. This makes it easy to reuse them, and ensure that a correct rebinding occurs on each reuse. Also, as i have been using Watir more on large projects, i am finding that there are other reasons why this is a sound way to structure Watir libraries. This made the automatic-rebinding we have in place simply a performance hog with no real benefit. I posted a patch the other day that removes it and will probably commit this to trunk soon. It has the potential to break tests, so first i want to post a release that rolls up the new features and bug fixes that will assuredly be popular. So the short answer to your question, is it depends. Is headline now 'frozen'? For example, lets say there is a 'addtocart' after headline. What happens if after you create your headline variable the page changes (headline is now at the bottom of the page)? Will the after method re evaluate headlines position in the page? Or is headline now static so after would would be true even if it isn't? So when you say the page changes, we need to know whether a new page is loaded (or even reloading the same page) or whether the change is made dynamically. Right now, it will rebind if we get a page load (but, like i said, i'm considering removing this behavior). If it is an AJAX/Javascript change, then we would need more details. In particular, a lot of times when we see AJAX/Javascript page elements moving, they are actually being made visible or invisible, which is a whole other thing, since Watir can see invisible elements. The important message is that you really should re-execute the headline Watir expression after a page change. That will ensure that your tests work correctly, not matter how your page works or what version of Watir you are using. Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org
Re: [Wtr-general] Syntax for relative attributes
link = ie.div(:text, 'Pragmatic Version Control').after.link(:class, addtocard') I think this is less intuitive and it would be somewhat harder to implement. That's why i came up with the other proposal, above. Thats actually the first way I thought of it too. A second, slightly related question. Regardless of how you do it, i'm wondering whats going on behind the scenes. If you do headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Is headline now 'frozen'? For example, lets say there is a 'addtocart' after headline. What happens if after you create your headline variable the page changes (headline is now at the bottom of the page)? Will the after method re evaluate headlines position in the page? Or is headline now static so after would would be true even if it isn't? I'm not sure if that even made sense. - Posted via Jive Forums http://forums.openqa.org/thread.jspa?threadID=5849messageID=16487#16487 ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
i can't see much difference between :after? and :is_after?. i would read both versions as link after headline Christian On 12/20/06, Bret Pettichord [EMAIL PROTECTED] wrote: Yi, Lawrence wrote: I would see that as link after headline. That was my original intention. Is this clearer? link = $ie.link(:class = 'addtocart', :is_after? = headline) Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
On 12/20/06, Bret Pettichord [EMAIL PROTECTED] wrote: link = $ie.link(:class = 'addtocart', :is_after? = headline) This would make sense to me (no question mark) link = $ie.link(:class = 'addtocart', :after = headline) By convention, methods that answer questions (i.e. Array#empty? returns * true* if the receiver is empty) end in question marks. ( http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/) This is not a method, but this convention really makes sense to me, so I expect anything that ends with question mark to return true or false. Why did you use question mark? -- Zeljko Filipin zeljkofilipin.com ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
Željko Filipin wrote: This would make sense to me (no question mark) link = $ie.link(:class = 'addtocart', :after = headline) By convention, methods that answer questions (i.e. Array#empty? returns *true* if the receiver is empty) end in question marks. (http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/ http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/) This is not a method, but this convention really makes sense to me, so I expect anything that ends with question mark to return true or false. Why did you use question mark? Actually it is a method, but not obviously so. A major structural change between Watir 1.4 and Watir 1.5 is that in 1.5, these 'conventions' actually are methods. In other words, there is a deep similarity between link = ($ie.links.collect {|l| l.class_name == 'addtocart'))[0] and link = $ie.link(:class_name = 'addtocart') (In the case of :class, we map it to the Element#class_name method because Object#class is already taken.) In other words, my proposal implicitly includes adding a method Element#after? that returns true or false based on the relation ship between self and the argument. That is why it has a question mark. But i can see that retaining the question mark in the attribute syntax may be confusing and will make it work without it too. Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Is this saying you want the link that comes after headline? Is there a before? :) *if* thats the case, my only problem with it is that it seems to not follow the standard syntax of Watir (as i understand it). how about ie.link(:class,'addtocard').after(ie.div(:text,'Pragmatic Version Control')) - Posted via Jive Forums http://forums.openqa.org/thread.jspa?threadID=5849messageID=16433#16433 ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
John Lolis wrote: headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Is this saying you want the link that comes after headline? Is there a before? :) Yes, there would also be a 'before' option, plus some others *if* thats the case, my only problem with it is that it seems to not follow the standard syntax of Watir (as i understand it). how about ie.link(:class,'addtocard').after(ie.div(:text,'Pragmatic Version Control')) This couldn't quite work. Well, it would work but what it would do is return true or false based on whether the link was after the div. However the following could be implemented, and in fact was a proposal that i had considered earlier: link = ie.div(:text, 'Pragmatic Version Control').after.link(:class, 'addtocard') I think this is less intuitive and it would be somewhat harder to implement. That's why i came up with the other proposal, above. Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
[Wtr-general] Syntax for relative attributes
I am in the process of adding a new feature to Watir and have a question. Consider this code: headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Would you assume that link was after headline, or headline after link? I can make it work either way. Which is more intuitive? Or is it confusing no matter what? Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
Bret Pettichord wrote: I am in the process of adding a new feature to Watir and have a question. Consider this code: headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Would you assume that link was after headline, or headline after link? I can make it work either way. Which is more intuitive? Or is it confusing no matter what? 'after' is reflexive when used as a question. Is link after headline? It reflects its target to before its subject. 'after' is transitive when used imperatively. Link! After link, headline! So Ruby's silly ? and ! markers make more sense than we thought. Whaddaya mean you can write anything and it doesn't check if you are really doing a query without side-effects inside a ? function?? I'm going back to a paranoid language with static typing and everything! Now I just have to figure out how to stop adding get_ and I'm there. Who wants to write a tiny book /Elements of Ruby Style/ ? -- Phlip http://www.greencheese.us/ZeekLand -- NOT a blog!!! ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
I would see that as link after headline. Wonder what other people think Cheers, Lawrence. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bret Pettichord Sent: Wednesday, 20 December 2006 11:31 To: wtr-general@rubyforge.org Subject: [Wtr-general] Syntax for relative attributes I am in the process of adding a new feature to Watir and have a question. Consider this code: headline = $ie.div(:text, 'Pragmatic Version Control') link = $ie.link(:class = 'addtocart', :after? = headline) Would you assume that link was after headline, or headline after link? I can make it work either way. Which is more intuitive? Or is it confusing no matter what? Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Syntax for relative attributes
Yi, Lawrence wrote: I would see that as link after headline. That was my original intention. Is this clearer? link = $ie.link(:class = 'addtocart', :is_after? = headline) Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general