My suggestion is that you take a look at one of the watir-centric frameworks that are being developed and learn from them and/or just use one of them. They're available on github:
Watirloo: http://github.com/marekj/watirloo/tree/master Taza: http://github.com/scudco/taza/tree/master WatirCraft: http://github.com/bret/watircraft/tree/master Each of these frameworks encapsulates dealing with pages, movement between pages, some abstraction, etc. which seems to be what you're trying to do. Charley Baker blog: http://charleybakersblog.blogspot.com/ Lead Developer, Watir, http://wtr.rubyforge.org QA Architect, Gap Inc Direct On Mon, Mar 2, 2009 at 11:30 AM, <[email protected]> wrote: > > Having had the weekend to ponder this, it occurs to me, am I guilty of > slipping into pre-oop thinking? by trying to create what amount to > 'functions' instead of teaching objects how to act on themselves? > > Should I be doing something like subclassing the watir browser class > and adding my methods to that?? perhaps have it take the URL of the > login page, the username, and password as parameters, and then just > send it a message tot he browser object something along the lines of > > brow.login_ess_user(login_url, user, pass) > > On Feb 27, 5:00 pm, [email protected] wrote: > > I'm having a similar issue, I'm pretty sure it's scope related, but I > > can't wrap my head around what I need to do to fix it. My longterm > > intent is to move a bunch of frequently called methods, such as > > logging in a user, off into a seperate file (or module?) but my first > > attempt at this is failing. The problem seems to center around my > > trying to pass the browser instance to the method, which I should > > think would be possible, but I'm getting the error below: > > > > test_login_user(Ess_Employee_Tests): > > NoMethodError: undefined method `goto' for nil:NilClass > > > > Here's a somewhat abridged version of the code (removing most of the > > validation, all of which is working) > > > > #-=-=-=-=-=-=-= > > require 'watir' > > require 'watir/testcase' > > require 'example_logger1' > > require 'CLReport.class' > > > > Watir::Browser.default = 'ie' > > > > # GlobalConstants > > $employee_userid = 'hallb' > > $employee_password = 'test' > > $employee_name = 'Bob T. Hall' > > $ess_site = 'http://odo-qas1/SelfService' > > $ess_loginpage = $ess_site + '/SelfServiceLogin.aspx' > > > > #Create a Report file > > $results = CLReport.new() > > $testReport = $results.createReport('c:\\QAReports\\ess-smoketest') > > #Create a Logfile > > logfileprefix = 'ess_Employee_log' > > $logger = LoggerFactory.start_xml_logger(logfileprefix) > > > > # method for logging a user into the site <<==== this is the method > > I can't get to work... > > # > > def ess_login(b, userid, password) > > b.goto $ess_loginpage > > b.text_field(:id, 'UserId').set userid > > b.text_field(:id, 'Password').set password > > b.button(:id, 'Login').click > > end > > > > class ESS_Employee_Tests < Watir::TestCase > > > > #initialization stuff > > def start > > #Open a browser > > @b = Watir::Browser.new > > @b.set_logger($logger) > > end > > > > def test_login_page #tests content of user login page > > #call start method > > start > > > > $logger.log('Beginning of testcase set for ESS Employee actions') > > $logger.log('Beginning of test_login_page)') > > $logger.log('Step: call and validate login page') > > @b.goto $ess_loginpage > > $logger.log('action: browser goto ' + $ess_loginpage) > > #Check page contents as expected > > $logger.log('checking contents of login page') > > > > # is the word login on the page? > > if @b.text.include?('Login') > > $results.addtoReport($testReport, 'Page text contains phrase: > > Login', 'PASSED', 'phrase: Login found') > > $logger.log('found text "login" on page') > > else > > $results.addtoReport($testReport, 'Page text contains phrase: > > Login', 'FAILED', 'phrase: Login not found on page') > > end > > > > # <snip> for brevity I've removed a bunch more like the one above, > > that test content of the page, all of which is working > > > > end #end of test_Login_Page > > > > def test_login_user > > $logger.log('Calling ess_login from test_login user') > > ess_login(@b, $employee_id, $employee_password) > > > > # <snip> more validation and assertions follow for the page seen > > once the user is logged in > > > > end # end of test_login_user > > end #end of class Ess_Employee_Tests > > > > class ZZZ_Cleanup_And_Publish_Report < Watir::TestCase > > def test_finished > > $logger.log('about to close test report') > > $results.finishReport($testReport) > > $logger.log('after test report closed') > > $logger.end_log #needed for xml log only? > > end #end of test_finished > > end #end of class ZZZ_Cleanup_And_Publish_Report > > > > Notes: > > * all the globals is ugly.. need to find a better way, either via > > seperate ruby file, or reading from some spreadsheet or config file to > > allow test to be more data driven down the road. > > * I expect to add a whole additional class for the Manager action > > tests (approving employee requests etc), which is why the ess_login > > method isn't just inside the test case class. > > * still fumbling around looking for best way to report the results > > but the CLReport is spiffy enough to do for now > > * Also not sure (with way I'm doing my validations, and not using > > 'assert') that there's value to using Watir/testcase > > * tons of best practice, what works well in real life large projects > > etc questions, but for the moment I just need to get some scripts > > working to make the boss happy.. will see perfection soon, but not > > this instant. > > > > On Feb 25, 9:02 am, Tiffany Fodor <[email protected]> wrote: > > > > > > > > > I think your problem is with the scope of the variable @my_workbook > > > because it's a member of a class now. I recommend finding a good Ruby > > > resource that describes the various variable types - I'm sure any > > > resource you find would do a better job than I could. > > > > > Good luck! > > > > > -Tiffany > > > > > On Feb 25, 1:16 am, [email protected] wrote: > > > > > > Hi, > > > > > > Tried this out: > > > > > > I have one class called Utilities.rb with the following content: > > > > > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" > > > > require "watir" > > > > require 'win32ole' > > > > > > class Utilities > > > > > > def connect(path_file) > > > > excel = WIN32OLE::new('excel.application') > > > > @my_workbook = excel.Workbooks.open(path_file) > > > > end > > > > > > def disconnect(workbook) > > > > workbook.Close > > > > excel.Quit > > > > end > > > > end > > > > > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" > > > > > > This is "Main" with this content: > > > > > > > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" > > > > require 'watir' > > > > require'Utilities' > > > > > > util = Utilities.new() > > > > util.connect("C:\\Programfiler\\Ruby\\FPSdata.xls") > > > > > > #read and write to @my_workbook > > > > #worksheet = ut...@my_workbook.worksheet(1) > > > > > > util.disconnect(@my_workbook) > > > > > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" > > > > > > As you might have guessed, I want to separate my Excel connect/ > > > > disconnect into a separate class and call this class' methods in my > > > > main class. > > > > > > I get the following error message: > > > > > > Undefines methos Close for nil:NilClass (NoMethodError) > > > > > > Cheers > > > > > > On 24 Feb, 23:39, Tiffany Fodor <[email protected]> wrote: > > > > > > > Try this: > > > > > > > def connect(path_file) > > > > > excel = WIN32OLE::new('excel.application') > > > > > @my_workbook = excel.Workbooks.open(path_file) > > > > > end > > > > > > > def disconnect(path_file, workbook) > > > > > workbook.SaveAs(path_file) > > > > > workbook.close > > > > > end > > > > > > > Then you can call your methods like this: > > > > > > > connect("C:\\Spreadsheets\\MySpreadsheet.xls") > > > > > > > #read and write to @my_workbook > > > > > > > disconnect("C:\\Spreadsheets\\MyNewSpreadsheet.xls", @my_workbook) > > > > > > > If you're hoping to have more than one spreadsheet open at a time, > > > > > you'll run into trouble. In that case, it may be easier to just > open > > > > > each spreadsheet and close it without using the methods since each > > > > > method is only a couple lines of code anyway. > > > > > > > I hope this helps! > > > > > > > -Tiffany > > > > > > > On Feb 24, 12:03 pm, [email protected] wrote: > > > > > > > > Hi, > > > > > > So I can write> > def connect(workbook) > > > > > > > > worksheet = workbook.WorkSheets(1) > > > > > > > > #Manipulate the workbook cells as in i.e. get the cell > values here > > > > > > > > end > > > > > > > > And have another method ´disconnect´ > > > > > > > > as this: > > > > > > > > > > def disconnect(workbook) > > > > > > > > workbook.close() > > > > > > > > end > > > > > > > > This will refer to the same object? > > > > > > > > Cheers > > > > > > > > On Feb 24, 3:59 pm, Tiffany Fodor <[email protected]> wrote: > > > > > > > > > Sorry, I should have also included that you can pass 'workbook' > to > > > > > > > methods and write to the file within those methods. > > > > > > > > > On Feb 24, 1:02 am, [email protected] wrote: > > > > > > > > > > This might be a ruby question, bit is it possible to have an > WIN32OLE > > > > > > > > object asparameterto a method? > > > > > > > > > > excel = WIN32OLE::new("excel.Application") > > > > > > > > workbook = excel.Workbooks.Open("C:\\Programfiler\\Ruby\ > > > > > > > > \FPSdata.xls") > > > > > > > > > > def connect(workbook) > > > > > > > > worksheet = workbook.WorkSheets(1) > > > > > > > > puts "You are now connected to Excel" > > > > > > > > end– Skjul sitert tekst – > > > > > > > – Vis sitert tekst –- Hide quoted text - > > > > > - Show quoted text -- Hide quoted text - > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Watir General" group. To post to this group, send email to [email protected] Before posting, please read the following guidelines: http://wiki.openqa.org/display/WTR/Support To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/watir-general -~----------~----~----~----~------~----~------~--~---
