Forum: Ruby How to print FULL stacktrace of exception w/ line #?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E6e1c5287fd1db02313c4628bc3fccde?d=identicon&s=25 Andrew Chen (babyeyes)
on 2007-09-19 04:28
The ruby interpreter prints out a full trace of the exception.

However, all the expection I got is an one line message.  I need to know
where the exception happened in my code.  I don't mind it is verbose.

begin
 ....
 Math.sqrt (-1)
rescue => e
 puts e.inspect
end

e only prints out a message.

Am I missing anything real simple?

Thanks
~Andrew Chen
4d60ea85b83de9f19821ecdfa8689219?d=identicon&s=25 Konrad Meyer (konrad)
on 2007-09-19 05:05
(Received via mailing list)
Quoth Andrew Chen:
> end
>
> e only prints out a message.
>
> Am I missing anything real simple?
>
> Thanks
> ~Andrew Chen

Don't rescue it, full stack trace! :P
E6e1c5287fd1db02313c4628bc3fccde?d=identicon&s=25 Andrew Chen (babyeyes)
on 2007-09-19 05:11
Konrad Meyer wrote:
>
> Don't rescue it, full stack trace! :P

In the situation, I want to rescue, and run some other logic, since I
don't want the whole class to die.
86e33dee4a89a8879a26487051c216a8?d=identicon&s=25 Michael Fellinger (Guest)
on 2007-09-19 05:39
(Received via mailing list)
On 9/19/07, Andrew Chen <meihome@gmail.com> wrote:
> The ruby interpreter prints out a full trace of the exception.
>
> However, all the expection I got is an one line message.  I need to know
> where the exception happened in my code.  I don't mind it is verbose.

begin
  ....
  Math.sqrt (-1)
rescue => e
  puts e.inspect
  puts e.backtrace
ensure
  andrew.brain << open("ri"){|ri| ri.read('Exception')}
end
934180817a3765d132193a5428f99051?d=identicon&s=25 Sylvain Joyeux (Guest)
on 2007-09-19 13:39
(Received via mailing list)
You can check utilrb's #full_message at
http://www.laas.fr/~sjoyeux/darcs/utilrb/lib/utilr...

(utilrb is also available as a gem on rubyforge :))
934180817a3765d132193a5428f99051?d=identicon&s=25 Sylvain Joyeux (Guest)
on 2007-09-19 13:41
(Received via mailing list)
> Don't rescue it, full stack trace! :P
... or not
Ruby removes in-betweeen lines if a backtrace is 'too long'. The limit
is
not configurable, so it you have long backtraces (and if you need what
is
in the middle) you're fucked.
6357218c16ad3f341f22e120a135a0ad?d=identicon&s=25 Mitch Mon (mitchm)
on 2007-09-25 20:57
I miss Java.

I run into this kind of short sighted decision far too often with Ruby.
Ugh.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2007-09-26 10:00
(Received via mailing list)
Sylvain Joyeux wrote:
>> Don't rescue it, full stack trace! :P
> ... or not
> Ruby removes in-betweeen lines if a backtrace is 'too long'. The limit is
> not configurable, so it you have long backtraces (and if you need what is
> in the middle) you're fucked.
>
You can get that information when you rescue the exception -
Exception#backtrace is an array of caller information.
934180817a3765d132193a5428f99051?d=identicon&s=25 Sylvain Joyeux (Guest)
on 2007-09-26 10:18
(Received via mailing list)
> You can get that information when you rescue the exception -
> Exception#backtrace is an array of caller information.
Yes, so I had to rescue all exceptions in all threads I spawn to have a
proper backtrace (even more so since with abort_on_exception the
exception
is not shown /at all/).

Sometimes it drived me crazy ...

Sylvain Joyeux
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2007-09-26 17:40
Sylvain Joyeux wrote:
>> You can get that information when you rescue the exception -
>> Exception#backtrace is an array of caller information.
> Yes, so I had to rescue all exceptions in all threads I spawn to have a
> proper backtrace (even more so since with abort_on_exception the
> exception
> is not shown /at all/).
>
> Sometimes it drived me crazy ...
>
> Sylvain Joyeux

You might be able to rewrite the Thread.new method and have it catch and
display exceptions (and raise them).
GL!
-Roger
E6e1c5287fd1db02313c4628bc3fccde?d=identicon&s=25 Andrew Chen (babyeyes)
on 2007-09-26 17:46
e.backtrace works fine for me.  In my case, I don't need traces in the
middle.

Thanks for all the help!
1142476e4b21386eb75a8303df5e4ae8?d=identicon&s=25 Kru K. (kru_k)
on 2010-10-14 16:46
Michael Fellinger wrote in post #555437:
> On 9/19/07, Andrew Chen <meihome@gmail.com> wrote:
>> The ruby interpreter prints out a full trace of the exception.
>>
>> However, all the expection I got is an one line message.  I need to know
>> where the exception happened in my code.  I don't mind it is verbose.
>
> begin
>   ....
>   Math.sqrt (-1)
> rescue => e
>   puts e.inspect
>   puts e.backtrace
> ensure
>   andrew.brain << open("ri"){|ri| ri.read('Exception')}
> end

hahah :) nice one
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-12-06 08:23
Friends i want to write backtrace inside teardown method but i am
unable to get the syntax. Here is the script that i have

def teardown
if @check==1
$driver.close
puts "passed if condition"
else
puts "passed else condtion"
  $driver.save_screenshot('IM.png')
  sleep 3
      #------ i want to put backtrace here---
  $driver.switch_to.default_content
  sleep 1
  puts "Switched back from Iframe"

  $driver.find_element(:name, "headerForm:logoutLink").click
  puts "User successfully logged out"
  sleep 2

  $driver.close
  puts "test case passed"

      assert_equal [], @verification_errors
      $driver.save_screenshot('IM.png')
    puts "test case failed"
end
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2013-12-06 08:53
(Received via mailing list)
On 12/05/2013 11:23 PM, saurav panda wrote:
>    sleep 3
>    puts "test case passed"
>
>        assert_equal [], @verification_errors
>        $driver.save_screenshot('IM.png')
>      puts "test case failed"
> end
>

"caller" will return the stack trace as an array. For example:

     puts caller

will print out the stack trace with file names, line numbers, and method
names.

If you need to rescue an exception, you at least need a "rescue"
clause[1].

For example:

def teardown
# ...
rescue => e
   puts e.backtrace
end

-Justin

[1]https://github.com/ruby/ruby/blob/trunk/doc/syntax...
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-12-06 09:06
Justin Collins wrote in post #1129827:
> On 12/05/2013 11:23 PM, saurav panda wrote:
>>    sleep 3
>>    puts "test case passed"
>>
>>        assert_equal [], @verification_errors
>>        $driver.save_screenshot('IM.png')
>>      puts "test case failed"
>> end
>>
>
> "caller" will return the stack trace as an array. For example:
>
>      puts caller
>
> will print out the stack trace with file names, line numbers, and method
> names.
>
> If you need to rescue an exception, you at least need a "rescue"
> clause[1].
>
> For example:
>
> def teardown
> # ...
> rescue => e
>    puts e.backtrace
> end
>
> -Justin
>
> [1]https://github.com/ruby/ruby/blob/trunk/doc/syntax...


justin
 i have used this
def teardown
# ...
rescue => e
   puts e.backtrace
end


It is showing exception as un defined method backtrace

can we use rescue inside teardown and that too without "begin"

only puts caller is enough to get the failed element, or anything extra
needed
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2013-12-06 09:17
(Received via mailing list)
On 12/06/2013 12:06 AM, saurav panda wrote:
>>
>> For example:
>
> It is showing exception as un defined method backtrace
>

Please check your code or post your exact code and error message.

$ irb
2.0.0p247 :001 > def teardown
2.0.0p247 :002?>   raise
2.0.0p247 :003?>   rescue => e
2.0.0p247 :004?>   puts e.backtrace
2.0.0p247 :005?>   end
  => nil
2.0.0p247 :006 > teardown
(irb):2:in `teardown'
(irb):6:in `irb_binding'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/workspace.rb:86:in
`eval'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/workspace.rb:86:in
`evaluate'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/context.rb:380:in
`evaluate'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:492:in
`block (2 levels) in eval_input'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:624:in
`signal_status'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:489:in
`block in eval_input'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:247:in
`block (2 levels) in each_top_level_statement'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in
`loop'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in
`block in each_top_level_statement'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in
`catch'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in
`each_top_level_statement'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:488:in
`eval_input'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:397:in
`block in start'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in
`catch'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in
`start'
/home/justin/.rvm/rubies/ruby-2.0.0-p247/bin/irb:12:in `<main>'
  => nil

-Justin
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-12-06 09:43
Justin,
This is my entire code but u will not have access to use the application
link as it is an internal application.

require "rubygems"
require "selenium-webdriver"
gem "test-unit"
require "test/unit"

class Search_Export < Test::Unit::TestCase

def setup
$driver = Selenium::WebDriver.for :ie
$base_url = "https://qa-pec.razorsight.com/sso2"
$accept_next_alert = true
$driver.manage.timeouts.implicit_wait = 10
$verification_errors = []

#-----------------User Login-----------------
puts "User Log in"
$driver.get($base_url + "/login.jsf")
$driver.find_element(:id, "loginForm:username").clear
$driver.find_element(:id, "loginForm:username").send_keys
"sysadmin@firstcomm.com"
$driver.find_element(:id, "loginForm:password").clear
$driver.find_element(:id, "loginForm:password").send_keys "Saurav12345"
$driver.find_element(:id, "loginForm:loginBtn").click

puts "User has successfully logged in"
end

def test_Search_Export
assert_equal "Razorsight - Profit Enhancement Center", $driver.title
puts "Assertion for IMLink passed"

puts "Wait for 5sec for page to load"
sleep 5

$driver.switch_to.frame $driver.find_element(:id, "baseFrame")
puts "Switched to Iframe"

puts "Wait for 5sec for page load to complete"
sleep 5
puts "User Logged in"

#------------------------User Logged in------------------------
#-------------------Searching an Invoice-----------------------
@loop = 1
while @loop <= 2 do
$driver.find_element(:id, "j_id16:searchControlTab_lbl").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntnp").clear

 #-- this is error element ->j_id761:invoiceSearchForm:acntnp ---


$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").send_keys
"80027309527"
#$driver.find_element(:css,
"td.rich-sb-cell-padding.richfaces_suggestionSelectValue").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:srchBtn1").click
$driver.find_element(:id,
"j_id761:invoiceSearchForm:invoiceSearchDataTable:1:eachleminvumnvhvv4B8xt").click
puts "Searching done based on Entered Account Number"

sleep 1
#$driver.save_screenshot('IM.png')
$driver.find_element(:id, "j_id16:inventoryTab_lbl").click
sleep 1
$driver.find_element(:id,
"j_id966:provisionInventorySearch:srchBtn").click
sleep 1
puts "Inventory searched"

$driver.find_element(:id, "j_id16:searchControlTab_lbl").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntnp").clear
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").send_keys
"80027309527"
#$driver.find_element(:css,
"td.rich-sb-cell-padding.richfaces_suggestionSelectValue").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:srchBtn1").click
$driver.find_element(:id,
"j_id761:invoiceSearchForm:invoiceSearchDataTable:1:eachleminvumnvhvv4B8xt").click
puts "Searching done based on Entered Account Number"

$driver.find_element(:id, "j_id16:rzrMaintenanceTab_lbl").click
sleep 1
puts "Supplier list is searched"
@loop = @loop+1
end
#-----------Logging out----------

$driver.switch_to.default_content
sleep 1
puts "Switched back from Iframe"
@check=1
$driver.find_element(:name, "headerForm:logoutLink").click
puts "User successfully logged out"
end
#-----------Teardown Method... Here i want to catch the failed element
def teardown
if @check==1
$driver.close
puts "passed if condition"
else
puts "passed else condtion"
  $driver.save_screenshot('IM.png')
  sleep 3


  $driver.switch_to.default_content
  sleep 1
  puts "Switched back from Iframe"

  $driver.find_element(:name, "headerForm:logoutLink").click
  puts "User successfully logged out"
  sleep 2

  $driver.close
  puts "test case passed"

      assert_equal [], @verification_errors
      $driver.save_screenshot('IM.png')
    puts "test case failed"
end
end

end
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2013-12-06 09:49
(Received via mailing list)
On 12/06/2013 12:43 AM, saurav panda wrote:
> Justin,
> This is my entire code but u will not have access to use the application
> link as it is an internal application.

You left out the important part, which is how you are adding rescue and
what the error is when you try to do so.

-Justin
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-12-06 09:57
Justin Collins wrote in post #1129842:
> On 12/06/2013 12:43 AM, saurav panda wrote:
>> Justin,
>> This is my entire code but u will not have access to use the application
>> link as it is an internal application.
>
> You left out the important part, which is how you are adding rescue and
> what the error is when you try to do so.
>
> -Justin




C:\Users\saurav.panda\Desktop>ruby search__exportEH.rb
Loaded suite search__exportEH
Started
Started InternetExplorerDriver server (64-bit)
2.33.0.0
Listening on port 5555
User Log in
User has successfully logged in
Assertion for IMLink passed
Wait for 5sec for page to load
Switched to Iframe
Wait for 5sec for page load to complete
User Logged in
Searching done based on Entered Account Number
Inventory searched
E
===============================================================================
Error: test_Search_Export(Search_Export)
  Selenium::WebDriver::Error::NoSuchElementError: Unable to find element
with id == j_id761:invoiceSearchForm:acntnp
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:51:in
`assert_ok'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:15:in
`initialize'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`new'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`create_response'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:66:in
`request'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in
`call'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in
`raw_execute'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in
`execute'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:575:in
`find_element_by'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/search_context.rb:42:in
`find_element'
search__exportEH.rb:62:in `test_Search_Export'
     59: puts "Inventory searched"
     60:
     61: $driver.find_element(:id, "j_id16:searchControlTab_lbl").click
  => 62: $driver.find_element(:id,
"j_id761:invoiceSearchForm:acntnp").clear
     63: $driver.find_element(:id,
"j_id761:invoiceSearchForm:acntInp").send_keys "80027309527"
     64: #$driver.find_element(:css,
"td.rich-sb-cell-padding.richfaces_suggestionSelectValue").click
     65: $driver.find_element(:id,
"j_id761:invoiceSearchForm:srchBtn1").click
===============================================================================
passed else condtion
Switched back from Iframe
User successfully logged out
test case passed
F
===============================================================================
Failure:
test_Search_Export(Search_Export)
search__exportEH.rb:110:in `teardown'
<[]> expected but was
<nil>

diff:
? []
? nil
===============================================================================


Finished in 78.243 seconds.

1 tests, 2 assertions, 1 failures, 1 errors, 0 pendings, 0 omissions, 0
notifications
0% passed

0.01 tests/s, 0.03 assertions/s

C:\Users\saurav.panda\Desktop>
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2013-12-06 10:17
(Received via mailing list)
On 12/06/2013 12:57 AM, saurav panda wrote:
>
>
>
>
> C:\Users\saurav.panda\Desktop>ruby search__exportEH.rb
> Loaded suite search__exportEH
<snip>

Allow me to summarize this conversation:

1. You asked how to get a stack trace
2. I provided two methods, one using "caller" and the other getting the
stack trace from an exception
3. You said you tried to use my code but got an error
4. I asked for how you tried my code and what the error looked like
5. You gave me your code WITHOUT any modifications or the error
mentioned in step 3. However, you did ask a different question, how to
get a "failed element" in the teardown method
6. I didn't see your different question, all I saw was that you didn't
have "caller", "rescue", or "backtrace" anywhere in the code. So I
requested the code that included one of these.
7. You gave me the output of running the webdriver code
8. Since we seem to be working at different problems, I wrote this list.


Going back to 6, I see what you want has to do with getting information
from webdriver about a failure. You shouldn't do this in the teardown
method, though, that's for resetting application state.

However, the information you need is right in the messages output from
webdriver. So at this point I don't know what you want and we are back
to the beginning.

At this point, I am going to bed. I hate to do this, but I'm going to
have to direct you to http://www.catb.org/~esr/faqs/smart-questions.html
and in particular
http://www.catb.org/~esr/faqs/smart-questions.html#goal

-Justin
16d74ef2ca3348d45b87cdbc2377acba?d=identicon&s=25 saurav panda (sauravpanda)
on 2013-12-06 10:23
sorry i copied from previous script. this is what i did when u said
backtrace

require "rubygems"
require "selenium-webdriver"
gem "test-unit"
require "test/unit"

class Search_Export < Test::Unit::TestCase

def setup
$driver = Selenium::WebDriver.for :ie
$base_url = "https://qa-pec.razorsight.com/sso2"
$accept_next_alert = true
$driver.manage.timeouts.implicit_wait = 10
$verification_errors = []

#-----------------User Login-----------------
puts "User Log in"
$driver.get($base_url + "/login.jsf")
$driver.find_element(:id, "loginForm:username").clear
$driver.find_element(:id, "loginForm:username").send_keys
"sysadmin@firstcomm.com"
$driver.find_element(:id, "loginForm:password").clear
$driver.find_element(:id, "loginForm:password").send_keys
"Razorsight123"
$driver.find_element(:id, "loginForm:loginBtn").click

puts "User has successfully logged in"
end

def test_Search_Export
assert_equal "Razorsight - Profit Enhancement Center", $driver.title
puts "Assertion for IMLink passed"

puts "Wait for 5sec for page to load"
sleep 5

$driver.switch_to.frame $driver.find_element(:id, "baseFrame")
puts "Switched to Iframe"

puts "Wait for 5sec for page load to complete"
sleep 5
puts "User Logged in"

#------------------------User Logged in------------------------
#-------------------Searching an Invoice-----------------------
@loop = 1
while @loop <= 2 do
$driver.find_element(:id, "j_id16:searchControlTab_lbl").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").clear
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").send_keys
"80027309527"
#$driver.find_element(:css,
"td.rich-sb-cell-padding.richfaces_suggestionSelectValue").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:srchBtn").click
$driver.find_element(:id,
"j_id761:invoiceSearchForm:invoiceSearchDataTable:1:eachleminvumnvhvv4B8xt").click
puts "Searching done based on Entered Account Number"

sleep 1
#$driver.save_screenshot('IM.png')
$driver.find_element(:id, "j_id16:inventoryTab_lbl").click
sleep 1
$driver.find_element(:id,
"j_id966:provisionInventorySearch:srchBtn").click
sleep 1
puts "Inventory searched"

$driver.find_element(:id, "j_id16:searchControlTab_lbl").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").clear
$driver.find_element(:id, "j_id761:invoiceSearchForm:acntInp").send_keys
"80027309527"
#$driver.find_element(:css,
"td.rich-sb-cell-padding.richfaces_suggestionSelectValue").click
$driver.find_element(:id, "j_id761:invoiceSearchForm:srchBtn1").click
$driver.find_element(:id,
"j_id761:invoiceSearchForm:invoiceSearchDataTable:1:eachleminvumnvhvv4B8xt").click
puts "Searching done based on Entered Account Number"

$driver.find_element(:id, "j_id16:rzrMaintenanceTab_lbl").click
sleep 1
puts "Supplier list is searched"
@loop = @loop+1
end
#-----------Logging out----------

$driver.switch_to.default_content
sleep 1
puts "Switched back from Iframe"
@check=1
$driver.find_element(:name, "headerForm:logoutLink").click
puts "User successfully logged out"
end

def teardown
if @check==1
$driver.close
puts "passed if condition"
else
puts "passed else condtion"
  $driver.save_screenshot('IM.png')
  sleep 3

        begin
        raise
  rescue => e
     puts e.backtrace
  end


  $driver.switch_to.default_content
  sleep 1
  puts "Switched back from Iframe"

  $driver.find_element(:name, "headerForm:logoutLink").click
  puts "User successfully logged out"
  sleep 2

  $driver.close
  puts "test case passed"

      #assert_equal [], @verification_errors
      $driver.save_screenshot('IM.png')
    puts "test case failed"
end
end

end
This topic is locked and can not be replied to.