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
“[email protected]”
$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