Seems that now we are down to not 'seeing' the text field, we have
duplicate threads, so we might be best off to pursue that in the other
thread, where there's a series of questions for you

Secondly, general coding thing..  don't obscure the exit condition of
the while loop, it makes the code harder to read

There's little point to doing a check inside the loop and issuing
break at that point when you could just as well use

while xl.Cells(i,1).value != "End data"

and then anyone reading it knows when the loop will end right off,
instead of having to scan down inside it to find what will break you
out of the loop.

On Apr 14, 5:30 am, Chai Taolun <ctco...@gmail.com> wrote:
> Hi~ Chuck
>
> Thank you for your advice. That is good for me.
> I already add the ie.close in the while loop.
> And I change the code a little bit. Is this seems ok?
> I don't know ruby and network develop much, so I may made some mistakes.
> require 'watir'
> require 'win32ole'
> require 'thwait'
>
> inputfile = "C:\\codework\\watir\\Qian\\in.txt"
> logfile = "C:\\codework\\watir\\Qian\\logfile.txt"
> testcasefile = "C:\\codework\\watir\\Qian\\Book1.xls"
>
> #def getTestCases(testCaseFile)
>   testcase = Array.new # testCase - the array [i1, i2, answer]
>   testcases = Array.new # array of testCases
>   xl=WIN32OLE.new('Excel.Application')
>   xl.Workbooks.Open(testcasefile)
>
>   data = false
>   testcasenumber = 0
>   i = 1
>   while (true)
>
>           if (xl.Cells(i,1).value == "End data")
>             break
>           end
>           if (xl.Cells(i,1).value == "Start data")
>             data = true
>             i+=1
>           end
>
>           if (data)
>             ans = xl.Cells(i,3).value
>             ansstr = ans.to_s
>               if /(^.*)\.0$/ =~ ansstr
>                 ansstr = Regexp.last_match(1)
>               end
>             testcase = [xl.Cells(i,1).value,ansstr]
>             testcases[testcasenumber] = testcase
>             testcasenumber += 1
>           end
>     i += 1
>   end
>
>   xl.Workbooks.Close
>
> #end
>
> k =testcasenumber
>
> filehandle = File.open(logfile,"w")
> infile = File.new(inputfile, "r")
> filehandle << "Test result are:\n\n"
> folderlocation = "http://localhost:81/Homework/";
>
> infile.each do |i|
>   thislocation = [folderlocation, i]
>   print  thislocation
>   print '\n'
>   k =testcasenumber
>   while k !=0
>     ie = Watir::IE.new
>     ie.goto(thislocation.to_s)
>     tcase= testcases[k-1]
>     arg1= tcase[0]
>     ans = tcase[1]
>     puts tcase[0].to_s+"......"+tcase[1].to_s;
>     ie.text_field(:name, "fahrenheit").set(arg1.to_s)
>     ie.button(:type, "submit").click
>     if ie.contains_text(ans.to_s)
>       filehandle << ":::Passed\n\n"
>     else
>       filehandle << ":::failed\n\n"
>     end
>     #testCases = getTestCases(testCaseFile)
>     k-=1
>     ie.close;
>   end
> end
>
> filehandle.close
>
> However this code still does not work.
> It still says
> `assert_exists': Unable to locate element, using :name, "fahrenheit"
> (Watir::Exception::UnknownObjectException)
> I got so confused
>
> Thank you
> Allen
>  On Mon, Apr 13, 2009 at 2:15 PM, Chuck van der Linden 
> <sqa...@gmail.com>wrote:
>
>
>
>
>
>
>
> > I worry about a one thing however.
>
> > In each loop iteration I see you open a new browser instance, but I
> > never see you close a browser.. so expect you are going to open a lot
> > of browsers and potentially you could have quite a mess on your hands
> > (or run the system out of memory), if the test runs for a good number
> > of iterations..  You may want to consider adding a command to close
> > the browser at the end of the same loop where it is opened, or else
> > move creating (and later closing) the IE instance outside of your
> > loop.
>
> > 2) minor style thing, but I see most ruby coders express loops like
> > are doing without the curley braces, and just use the form
>
> >  variable.each do |i|
> >   code
> >   code
> >  end
>
> > the preference seems to be to use the curley brace notation only for
> > single line stuff such as
>
> > variable.each { |i| codeusing i }
>
> > Also for variable names, the most common thing I've seen is
>
> >  variable = all_lowercase
> >  constant = ALL_UPPERCASE
> >  classes = CamelCase
>
> > you're free to code anyway that works of course, but it might be
> > slightly less confusing to others (when you have code reviewed or ask
> > for assistance) to be slightly more 'mainstream'.   I've always
> > figured that the easier it was for other folks to read my code the
> > better when it came time to ask for help.  Also that means less
> > chances for non-answers where say someone thinks 'testCase' is a class
> > and responds accordingly.
>
> > On Apr 12, 1:15 pm, Chai Taolun <ctco...@gmail.com> wrote:
> > > Hi~
>
> > > Thank you alex!
> > > I got it. thank you so much.
>
> > > allen
> > > On Sun, Apr 12, 2009 at 9:00 AM, Alex Collins <a.j.collins...@gmail.com
> > >wrote:
>
> > > > I believe that the issue is that you are passing in an Array into goto,
> > > > when it expects a string:http://wtr.rubyforge.org/rdoc/-look at the
> > > > Watir::IE class' goto method.
>
> > > > You create an array on the following line:
> > > > thisLocation = folderLocation, i
>
> > > > Explicitly stated, you can read this as:
> > > > thisLocation = [folderLocation, i]
>
> > > > thisLocation is therefore an Array. To convert this to a string, simply
> > > > call the "to_s" method on the array. For example:
>
> > > > [1, 2].to_s => "12"
>
> > > > ["c:\\file\\", "foo.bar"].to_s => "c:\\file\\foo.bar"
>
> > > > You therefore need to amend your script so that you call:
> > > > ie.goto(thisLocation.to_s)
>
> > > > However, if you are looking to join file names to directory paths, I
> > > > suggest you look at Ruby's File and Dir classes. They have many useful
> > > > helpers, for example, File.join does exactly what we are doing above,
> > but in
> > > > a platform-safe manner.
>
> > > > Alex
>
> > > > On 12 Apr 2009, at 02:57, Chai Taolun wrote:
>
> > > > Hi~
> > > > Sorry, this is not like that, I want to visit some webpage using the
> > name I
> > > > store in the text file.
> > > > I need to find a way to do this.
> > > > Thank you
>
> > > > allen
>
> > > > On Sat, Apr 11, 2009 at 1:22 PM, kiran <gki...@gmail.com> wrote:
>
> > > >> Hi,
> > > >> I think problem with folder path.
> > > >> suppose if we want open a file located in D:\watir
> > > >> The statement for watir
> > > >> ie.goto("D:\\watir")
>
> > > >> it would help you.
>
> > > >> On Apr 11, 12:15 pm, Chai Taolun <ctco...@gmail.com> wrote:
> > > >> > Hi~
>
> > > >> > Ruby is new to me and I got this problem in this code. Could you
> > give me
> > > >> > some help? Thank you
>
> > > >> > infile.each{
> > > >> >   |i|
> > > >> >   thisLocation = folderLocation, i
> > > >> >   print thisLocation
> > > >> >   k =testCaseNumber
> > > >> >   while k !=0
> > > >> >     ie = Watir::IE.new
> > > >> >     ie.goto(thisLocation)
>
> > > >> > and here is the error
>
> > c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-class.rb:358:in
> > > >> > `method_missing': navigate (WIN32OLERuntimeError)
> > > >> >     OLE error code:0 in <Unknown>
> > > >> >       <No Description>
> > > >> >     HRESULT error code:0x80020005
> > > >> >       Type mismatch.    from
>
> > c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.2/lib/watir/ie-class.rb:358:in
> > > >> > `goto'
> > > >> >     from awat.rb:61
> > > >> >     from awat.rb:54:in `each'
> > > >> >     from awat.rb:54http://localhost:81/Homework/HswitchS.php>Exit
> > code:
> > > >> 1
>
> > > >> > Thank you so much and looking forward your help ^_^
>
> > > >> > Allen
> > > >> > --
> > > >> > There are some things in this world will never change and some
> > things do
> > > >> > change.
>
> > > > --
> > > > There are some things in this world will never change and some things
> > do
> > > > change.
>
> > > --
> > > There are some things in this world will never change and some things do
> > > change.- Hide quoted text -
>
> > > - Show quoted text -
>
> --
> There are some things in this world will never change and some things do
> change.- 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 watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to