Re: [Wtr-general] little framework
Looks good. In your setup I would wrap $ie with a global function (internet_explorer or some such). I would then use that global function through out your class files. This could save you a headache down the road :) ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
instead of explitily asserting the existance of all the elements, Id try and come up with an easier way, ( this probably wont work, but it might, and may give you some ideas ) def username;$ie.text_field(:name, 'user_name');end def password;$ie.text_field(:name, 'password');end def remember_me;$ie.checkbox(:name, 'remember_me');end def existance_check( *elems ) &elems.each do |el| raise "Didnt exist" unless eval(el.to_s.exists?) end end def test_it assert_nothing_raised( existance_check :username , :password) end - Original Message - From: aidy lewis <[EMAIL PROTECTED]> Date: Monday, April 2, 2007 10:48 am Subject: Re: [Wtr-general] little framework > #Hi, > > #This is what I have got, I don't think it is anything new: > > #each page has a class where objects of that class are mapped > class Login > def username;$ie.text_field(:name, 'user_name');end > def password;$ie.text_field(:name, 'password');end > def remember_me;$ie.checkbox(:name, 'remember_me');end > def sign_in;$ie.button(:value, 'Sign in');end > end > > > #objects that dont neatly fit into a class go into a project module > module Mission > def Mission.log_out;$ie.link(:text, /Log-out/);end > end > > #browser also has its own module > module Browser > def Browser.open;$ie = Watir::IE.new;end > def Browser.goto(url);$ie.goto(url);end > def Browser.bring_to_front;$ie.bring_to_front;end > def Browser.maximize;$ie.maximize;end > def Browser.close;$ie.close;end > end > > #we have suites of tests with a test set-up and teardown method > #the set-up is executed before each method, the teardown after > class MissionSuite < Test::Unit::TestCase >include Mission >include Browser > >def setup > Browser.open > Browser.goto('http://missiontesting.updatelog.com') > Browser.bring_to_front > Browser.maximize > #we use ruby test assertions for are own purposes > login = Login.new > assert(login.username.exists?) > assert(login.password.exists?) >end > >def teardown > Browser.close >end > >def test_1 > login = Login.new > login.username.set('aidy') > login.password.set('lewis') > login.remember_me.set > #need to use the watir xml logger or log to xml myself for > external purposes > >end > >def test_2 > login = Login.new > login.username.set('tony') > login.password.set('smith') > login.remember_me.clear > login.sign_in.click >end > > >end > > #don't know if anyone has any opinions > > #aidy > ___ > 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] little framework
#Hi, #This is what I have got, I don't think it is anything new: #each page has a class where objects of that class are mapped class Login def username;$ie.text_field(:name, 'user_name');end def password;$ie.text_field(:name, 'password');end def remember_me;$ie.checkbox(:name, 'remember_me');end def sign_in;$ie.button(:value, 'Sign in');end end #objects that dont neatly fit into a class go into a project module module Mission def Mission.log_out;$ie.link(:text, /Log-out/);end end #browser also has its own module module Browser def Browser.open;$ie = Watir::IE.new;end def Browser.goto(url);$ie.goto(url);end def Browser.bring_to_front;$ie.bring_to_front;end def Browser.maximize;$ie.maximize;end def Browser.close;$ie.close;end end #we have suites of tests with a test set-up and teardown method #the set-up is executed before each method, the teardown after class MissionSuite < Test::Unit::TestCase include Mission include Browser def setup Browser.open Browser.goto('http://missiontesting.updatelog.com') Browser.bring_to_front Browser.maximize #we use ruby test assertions for are own purposes login = Login.new assert(login.username.exists?) assert(login.password.exists?) end def teardown Browser.close end def test_1 login = Login.new login.username.set('aidy') login.password.set('lewis') login.remember_me.set #need to use the watir xml logger or log to xml myself for external purposes end def test_2 login = Login.new login.username.set('tony') login.password.set('smith') login.remember_me.clear login.sign_in.click end end #don't know if anyone has any opinions #aidy ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
here was one of the ideas I tried. In essence, what it does is create a method called the_search_box that returns the ie.text_field object. Im sure there are some better ways of doing it. Paul require 'watir' class WatirNaming def self.parse_ops( obj_name , opts ) if opts.has_key? :id how = :id elsif opts.has_key? :name how = :name elsif opts.has_key? :index how = :index else raise "No Idea how to find that object" end what = opts[ how ] mname = eval(":#{obj_name}") return how , what , mname end def self.text_field( obj_name , opts ) how, what , mname = self.parse_ops( obj_name , opts ) define_method( mname ) { @ie.text_field( how , what ) } end end class D < WatirNaming text_field "the_search_box" , :name => 'q' def initialize @ie = Watir::IE.attach(:title , /google/i ) the_search_box.set('abc') end end d=D.new - Original Message - From: "aidy lewis" <[EMAIL PROTECTED]> To: Sent: Wednesday, March 28, 2007 10:55 AM Subject: Re: [Wtr-general] little framework > Hi Paul, > > Could you just please explain how you are mapping something like this: > > text_field :user_name , :id=>'username' > > in the parent class? > > cheers > > aidy > ___ > 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] little framework
Hi Paul, Could you just please explain how you are mapping something like this: text_field :user_name , :id=>'username' in the parent class? cheers aidy ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
See below... - Original Message - From: "aidy lewis" <[EMAIL PROTECTED]> To: Sent: Tuesday, March 27, 2007 3:20 PM Subject: Re: [Wtr-general] little framework > Paul Rogers says > >> the ParentClass would have methods to validate that everything is there, >> the title > is correct etc. It also has the code to do the translation of >> the descrptive name ( > eg login_button) to the actual element ( >> button(:value , 'Login Now!') > > Very good idea. I have been struggling with the concept of making > automated acceptance tests OO. What could I do? Have a Login class > with a constructor containing ie.goto(url) - and extend that?? > PMR --> id probably have a goto method for the class, that goes to the correct page, but some pages probably arent directly accessable from a url ( the page displayed after submitting a form for example) . In this case, the login page is quite likely to be accessible. >> class MyLoginPage < SomeParentClass > > would you ever extend MyLoginPage or add additional methods to that > class as needs occurr? PMR --> Id add any methods I needed. Ive been wondering what to do about error messages on the login page. ( ie yo get a message that says "Pass word or username wrong" - is that a new class ( LoginPageWithErrorMessage < MyLoginPage ) , or part of the login class - I cant ddecide. > > Where do modules come into this framework? > PMR --> I think I would do some thing like Module UserScreens class LoginPage... class DoSomethingPage end Module AdminScreens .. end >> Bob Cotton from Rally has doe some similar type things, as has Elizabeth >> Hendrickson. Another guy I have worked with also came up with something >> similar, which makes me think this is sort of okay. > > yes, there are some people who you can more or less have complete > faith in; but not many. > > >> Ive also been using something like this for model based testing, which >> really is >> kind of neat. > > I know nothing of this. Maybe off-topic. Would you consider this agile? > Chris already answered this - google for Harry Robinson - hes the expert. > Would you mind me looking into these ideas, and if I tag your name on > - blogging them or adding them to the wiki or something? > PMR --> go ahead ! > aidy > ___ > 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] little framework
> > Ive also been using something like this for model based testing, which > > really is > > kind of neat. > > I know nothing of this. Maybe off-topic. Would you consider this agile? > > Would you mind me looking into these ideas, and if I tag your name on > - blogging them or adding them to the wiki or something? Google for "Harry Robinson". He is the founder/originator/guru of Model Based Testing, and he's a really nice guy, too. He used to work for Microsoft, now he works for Google, and he contributes to the googletesting blog fairly often: http://googletesting.blogspot.com/ He is also a big fan of Watir, and uses it to test Google Maps (at least). ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
Paul Rogers says > the ParentClass would have methods to validate that everything is there, the > title > is correct etc. It also has the code to do the translation of the > descrptive name ( > eg login_button) to the actual element ( button(:value , > 'Login Now!') Very good idea. I have been struggling with the concept of making automated acceptance tests OO. What could I do? Have a Login class with a constructor containing ie.goto(url) - and extend that?? > class MyLoginPage < SomeParentClass would you ever extend MyLoginPage or add additional methods to that class as needs occurr? Where do modules come into this framework? > Bob Cotton from Rally has doe some similar type things, as has Elizabeth > Hendrickson. Another guy I have worked with also came up with something > similar, which makes me think this is sort of okay. yes, there are some people who you can more or less have complete faith in; but not many. > Ive also been using something like this for model based testing, which really > is > kind of neat. I know nothing of this. Maybe off-topic. Would you consider this agile? Would you mind me looking into these ideas, and if I tag your name on - blogging them or adding them to the wiki or something? aidy ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
yep. My original motivation was to improve the speed of code development and also make it clearer what was going on. I did this and then realised I had almost had an mbt library. With some extra work I got it to work just fine. MBT on web apps have some problems, as the 'state' is not just what pahe you are on, but also what state the ( for exampe ) user is in. EG on a web banking app, the user may be on the 'pay my visa bill' page, but if there is no balance on the visa, the 'Pay Now' link may be disabled. Paul - Original Message - From: Chris McMahon <[EMAIL PROTECTED]> Date: Tuesday, March 27, 2007 12:07 pm Subject: Re: [Wtr-general] little framework > > Ive also been using something like this for model based testing, > which really is kind of neat. > > I was going to say, you could make a state machine for > MBT/robot-army-testing out of this fairly easily, eh? > -C > ___ > 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] little framework
> Ive also been using something like this for model based testing, which really > is kind of neat. I was going to say, you could make a state machine for MBT/robot-army-testing out of this fairly easily, eh? -C ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
the idea is that each page in the app that Im testing has a corresponding class n my test code. the class would look something like this: class MyLoginPage < SomeParentClass text_field :user_name , :id=>'username' text_field :pass_word, :id =>'password' button :login_button , :value => 'Login Now' title "Welcome To MyApp" url /login.jsp/ def has_loaded raise "Not loaded" unless user_name.exists? end def do( un , pw ) user_name.set( un ) pass_word.set( pw ) login_button.click NextPage.has_loaded end end the ParentClass would have methods to validate that everything is there, the title is correct etc. It also has the code to do the translation of the descrptive name ( eg login_button) to the actual element ( button(:value , 'Login Now!') I also have some code that generates this class from the page, so in irb you would do something like this ie.goto( 'http://server/login.jsp') ie.gen => saves the class to a file using the title which then saves the class above. Bob Cotton from Rally has doe some similar type things, as has Elizabeth Hendrickson. Another guy I have worked with also came up with something similar, which makes me think this is sort of okay. Ive also been using something like this for model based testing, which really is kind of neat. Paul - Original Message - From: aidy lewis <[EMAIL PROTECTED]> Date: Tuesday, March 27, 2007 11:10 am Subject: Re: [Wtr-general] little framework > paul > could you give us a little taster of your efforts? > aidy > > > On 27/03/07, Paul Rogers <[EMAIL PROTECTED]> wrote: > > > > Ive been working on some things that ( at least to my mind) > simplify how the > > code represents an html page. It also has several other > advantages. I'll > > probably publish it in a seperate library ( or via the contrib > dir ) > > > > as for your code, the firsat think i would do is get rid of the > global ie. > > even replacing it with a method is better > > > > $ie = Watir::IE.new > > > > def my_browser > > $ie > > end > > > > my_browser.goto('http://someurl') > > > > > > at least this way its a bit easier to switch to firefox, or do > something> different with the browser. > > > > > > Paul > > > > > > - Original Message - > > From: aidy lewis <[EMAIL PROTECTED]> > > Date: Tuesday, March 27, 2007 9:56 am > > Subject: [Wtr-general] little framework > > > > > Hi, > > > > > > Could anyone give me some feedback on this? > > > > > > Each HTML objects exists in a module > > > > > > > > > > > > > > > module Field > > > > > >MAP_FIELD = Hash.new {|h,k| k}.update( > > > 'username' => 'login', # gui name => HTML name > > > 'password' => 'password' > > >) > > > > > > def Field.set(name,args) > > >$ie.text_field(:name, MAP_FIELD[name]).set(args) > > > end > > > > > > def Field.assert(name,args) > > >puts $ie.text_field(:name, > MAP_FIELD[name]).verify_contains(args)> > end > > > end > > > > > > > > > > > > At the top of each module is a hash map that acts as an object > map for > > > each object.The gui name is mapped to the object name > > > > > > > > > > > > MAP_BUTTON = Hash.new {|h| k}.update( > > > 'login' => 'Login' > > > ) > > > > > > > > > > > > IE methods go here > > > > > > > > > > > > module Explorer > > > def Explorer.start(url) > > >$ie = IE.new > > >@url=url > > >$ie.goto(@url) > > > end > > > > > > def Explorer.close > > >$ie.close > > > end > > > end > > > > > > > > > > > > Each test will be in a class > > > > > > > > > > > > class TestClass > > > > > > def test_1 > > > > > >Explorer.start 'http://aidy_server.com/' > > >Field.set 'username', 'aidy' > > >Field.assert 'username', 'aidy' > > >Field.set 'password', 'password123' > > >A_Button.press 'login' > > >Explorer.close > > > > > > end > > > > > > end > > > > > > TestClass.new.test_1 > > > > > > > > > Not so sure about logging, but will probably write to XML > > > > > > Any opinions? > > > > > > aidy > > > ___ > > > 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 > > > ___ > 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] little framework
paul could you give us a little taster of your efforts? aidy On 27/03/07, Paul Rogers <[EMAIL PROTECTED]> wrote: > > Ive been working on some things that ( at least to my mind) simplify how the > code represents an html page. It also has several other advantages. I'll > probably publish it in a seperate library ( or via the contrib dir ) > > as for your code, the firsat think i would do is get rid of the global ie. > even replacing it with a method is better > > $ie = Watir::IE.new > > def my_browser > $ie > end > > my_browser.goto('http://someurl') > > > at least this way its a bit easier to switch to firefox, or do something > different with the browser. > > > Paul > > > - Original Message ----- > From: aidy lewis <[EMAIL PROTECTED]> > Date: Tuesday, March 27, 2007 9:56 am > Subject: [Wtr-general] little framework > > > Hi, > > > > Could anyone give me some feedback on this? > > > > Each HTML objects exists in a module > > > > > > > > > > module Field > > > >MAP_FIELD = Hash.new {|h,k| k}.update( > > 'username' => 'login', # gui name => HTML name > > 'password' => 'password' > >) > > > > def Field.set(name,args) > >$ie.text_field(:name, MAP_FIELD[name]).set(args) > > end > > > > def Field.assert(name,args) > >puts $ie.text_field(:name, MAP_FIELD[name]).verify_contains(args) > > end > > end > > > > > > > > At the top of each module is a hash map that acts as an object map for > > each object.The gui name is mapped to the object name > > > > > > > > MAP_BUTTON = Hash.new {|h| k}.update( > > 'login' => 'Login' > > ) > > > > > > > > IE methods go here > > > > > > > > module Explorer > > def Explorer.start(url) > >$ie = IE.new > >@url=url > >$ie.goto(@url) > > end > > > > def Explorer.close > >$ie.close > > end > > end > > > > > > > > Each test will be in a class > > > > > > > > class TestClass > > > > def test_1 > > > >Explorer.start 'http://aidy_server.com/' > >Field.set 'username', 'aidy' > >Field.assert 'username', 'aidy' > >Field.set 'password', 'password123' > >A_Button.press 'login' > >Explorer.close > > > > end > > > > end > > > > TestClass.new.test_1 > > > > > > Not so sure about logging, but will probably write to XML > > > > Any opinions? > > > > aidy > > ___ > > 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 > ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] little framework
Ive been working on some things that ( at least to my mind) simplify how the code represents an html page. It also has several other advantages. I'll probably publish it in a seperate library ( or via the contrib dir ) as for your code, the firsat think i would do is get rid of the global ie. even replacing it with a method is better $ie = Watir::IE.new def my_browser $ie end my_browser.goto('http://someurl') at least this way its a bit easier to switch to firefox, or do something different with the browser. Paul - Original Message - From: aidy lewis <[EMAIL PROTECTED]> Date: Tuesday, March 27, 2007 9:56 am Subject: [Wtr-general] little framework > Hi, > > Could anyone give me some feedback on this? > > Each HTML objects exists in a module > > > > > module Field > >MAP_FIELD = Hash.new {|h,k| k}.update( > 'username' => 'login', # gui name => HTML name > 'password' => 'password' >) > > def Field.set(name,args) >$ie.text_field(:name, MAP_FIELD[name]).set(args) > end > > def Field.assert(name,args) >puts $ie.text_field(:name, MAP_FIELD[name]).verify_contains(args) > end > end > > > > At the top of each module is a hash map that acts as an object map for > each object.The gui name is mapped to the object name > > > > MAP_BUTTON = Hash.new {|h| k}.update( > 'login' => 'Login' > ) > > > > IE methods go here > > > > module Explorer > def Explorer.start(url) >$ie = IE.new >@url=url >$ie.goto(@url) > end > > def Explorer.close >$ie.close > end > end > > > > Each test will be in a class > > > > class TestClass > > def test_1 > >Explorer.start 'http://aidy_server.com/' >Field.set 'username', 'aidy' >Field.assert 'username', 'aidy' >Field.set 'password', 'password123' >A_Button.press 'login' >Explorer.close > > end > > end > > TestClass.new.test_1 > > > Not so sure about logging, but will probably write to XML > > Any opinions? > > aidy > ___ > 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
[Wtr-general] little framework
Hi, Could anyone give me some feedback on this? Each HTML objects exists in a module module Field MAP_FIELD = Hash.new {|h,k| k}.update( 'username' => 'login', # gui name => HTML name 'password' => 'password' ) def Field.set(name,args) $ie.text_field(:name, MAP_FIELD[name]).set(args) end def Field.assert(name,args) puts $ie.text_field(:name, MAP_FIELD[name]).verify_contains(args) end end At the top of each module is a hash map that acts as an object map for each object.The gui name is mapped to the object name MAP_BUTTON = Hash.new {|h| k}.update( 'login' => 'Login' ) IE methods go here module Explorer def Explorer.start(url) $ie = IE.new @url=url $ie.goto(@url) end def Explorer.close $ie.close end end Each test will be in a class class TestClass def test_1 Explorer.start 'http://aidy_server.com/' Field.set 'username', 'aidy' Field.assert 'username', 'aidy' Field.set 'password', 'password123' A_Button.press 'login' Explorer.close end end TestClass.new.test_1 Not so sure about logging, but will probably write to XML Any opinions? aidy ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general