The actual resolution is (drum-roll, please):

rescue
   <some code>
   self.exit
end

Thanks to all who helped!

On Apr 27, 3:27 pm, «°¤§ømåtïçCðrp§ë¤°» <john.bai...@unisys.com>
wrote:
> You hit the nail on the head, thanks, Adam!
>
> I tried using 'break', but the ruby syntax didn't like seeing the
> 'break' before 'end'.
>
> Thanks!
>
> On Apr 27, 2:39 pm, AR <reed.a...@gmail.com> wrote:
>
>
>
> > Just to make sure I understand, let's lay out a basic rescue.
>
> > <-- code -->
>
> > begin
> >   assertion
> >   actions if assertion passes
> > rescue
> >   actions if assertion failed
> > end #rescue block
>
> > <-- unrelated actions/functions here -->
>
> > It sounds like you want the rescue to force the program to end safely
> > rather than crash with an error.  In that case:
>
> > begin
> >   assertion
> >   puts "passed"
> > rescue
> >   puts "failed"
> >   exit  #(I don't have my code in front of me but I believe it is
> > 'exit' or 'quit', which will terminate the ruby program)
> > end #rescue block
>
> > I've used this type of block to ensure that a data file was present
> > before the test ran.  If it was not present, it would tell the user
> > and exit the script immediately.
>
> > Am I warm?
>
> > Thanks,
> > Adam
>
> > On Apr 27, 1:47 pm, «°¤§ømåtïçCðrp§ë¤°» <john.bai...@unisys.com>
> > wrote:
>
> > > Alex,
>
> > > It's not that I don't want the code to run, at all, but only if it
> > > successfully binds/attaches to the browser.
> > > My issue is that it's rescueing the error, but not halting after the
> > > rescue; it continues to the next line of code.
>
> > > If I know it's going to fail, and I want the code to terminate, after
> > > the rescue, how can I implement it?
> > > If I put a 'break' in there, the ruby syntax throws an error/warning
> > > about it.
>
> > > As is evident, by the attached Command Line output, the code continues
> > > to run - after the rescue is invoked. How can I stop that!?
>
> > > Thanks!
> > > John
>
> > > On Apr 26, 3:20 am, Alex Collins <a.j.collins...@gmail.com> wrote:
>
> > > > John,
>
> > > > Asking the obvious, if you don't want the code to run, why not remove  
> > > > it or comment it out? I'm not entirely sure what you are after, so a  
> > > > general response which I hope may still be useful.
>
> > > > Firstly, the protected code block has the structure:
>
> > > >         begin
> > > >           expr..
> > > >         [rescue [error_type,..]
> > > >           expr..]..
> > > >         [else
> > > >           expr..]
> > > >         [ensure
> > > >           expr..]
> > > >         end
>
> > > > In this, the "end" statement ends the block. It does not stop the  
> > > > program running. In this case, the end statement after your puts  
> > > > 'please login..' line closes the begin block.
>
> > > > To stop the program / script running, call the 'exit' method.
>
> > > > Alternatively, if you want to build in behaviour around the lack of a  
> > > > browser, you could always use an if-block:
>
> > > > if browser
> > > >   # do stuff when you have a browser
> > > > else
> > > >   # do stuff when you have no browser (browser = nil)
> > > > end
>
> > > > Alex
>
> > > > On 26 Apr 2009, at 07:01, «°¤§ømåtïçCðrp§ë¤°» wrote:
>
> > > > > I'm running a script, which has a rescue clause, but I want it to
> > > > > (essentially) break, when the rescue clause is invoked.
>
> > > > > Instead, it runs to the next line:
>
> > > > > C:\Documents and Settings\Marissa\Desktop>ruby T3.rb
> > > > > What is the user's First Name?
> > > > > Test
> > > > > What is the user's Last Name?
> > > > > Test
> > > > > ALERT: You must have a running instance of SVC open!
> > > > > Please log into SVC and restart Sevin. Exiting: Code1.
> > > > > T3.rb:18: undefined method `frame' for nil:NilClass (NoMethodError)
>
> > > > > To state the obvious: The frame it's looking for is not going to be
> > > > > there, so I don't even want it to go there.
>
> > > > > [Code]
>
> > > > > require 'watir'
>
> > > > > puts "What is the user's First Name?"
> > > > > Fname = gets.chomp #Removes return (recognized as new line command)
> > > > > character '\n'
> > > > > puts "What is the user's Last Name?"
> > > > > Lname = gets.chomp #Removes return (recognized as new line command)
> > > > > character '\n'
>
> > > > > begin
> > > > > �...@browser = Watir::IE.attach(:url, 'https://
> > > > >www.servicecenterweb.unisys.com/sc2/index.do')
> > > > >    rescue Watir::Exception::NoMatchingWindowFoundException
> > > > >      puts "ALERT: You must have a running instance of SVC open!"
> > > > >     �...@browser1 = Watir::IE.new
> > > > >     �...@browser1.goto('https://www.servicecenterweb.unisys.com/sc2/
> > > > > index.do')
> > > > >      puts "Please log into SVC and restart Sevin. Exiting: Code1."
> > > > >    end
> > > > > �...@browser.frame(:id, 'detail').button(:id, 'X8').click
> > > > >  #Insert company name and user
> > > > > �...@browser.frame(:id, 'detail').text_field(:id, 'X7').set("BAXTER")
> > > > > �...@browser.frame(:id, 'detail').text_field(:id, 'X78').set(Fname)
> > > > > �...@browser.frame(:id, 'detail').text_field(:id, 'X80').set(Lname)
> > > > > [/Code]
>
> > > > > If I put a 'break' in the rescue clause, it doesn't seem to like it,
> > > > > and 'end' really doesn't "end", as you can see.
>
> > > > > So, is there a way I can ditch the script, if the rescue is invoked,
> > > > > or will I just have to deal with it going on to the next line?
>
> > > > > Thanks!- Hide quoted text -
>
> > > > - Show quoted text -- 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 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