If else condition in ruby not working

K

King Maker

i write simple code for button if button pressed than result is passed
other wise failed.

but every time condition goes to the Failed.
i try may things but every time i face this problem.



begin
if(ie.button:)value,"Continue").click)
@result = 'PASSED'
@log = "Clicked Continue button"
log.info "Clicked Continue button\n"
else
@result = 'FAILED'
@log = "Clicked Continue button not pressed"
log.info "Clicked Continue button not pressed\n"
end
Readfrom_file(@file1,"Continue button",@log,@result)
rescue
end
 
K

King Maker

It's Working but..........
if i give the

ie.button( :value, '' ).click

without button name that time they click on button and search next page
continue button and press many time.
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

i write simple code for button if button pressed than result is passed
other wise failed.

but every time condition goes to the Failed.
i try may things but every time i face this problem.



begin
if(ie.button:)value,"Continue").click)
@result = 'PASSED'
@log = "Clicked Continue button"
log.info "Clicked Continue button\n"
else
@result = 'FAILED'
@log = "Clicked Continue button not pressed"
log.info "Clicked Continue button not pressed\n"
end
Readfrom_file(@file1,"Continue button",@log,@result)
rescue
end

Hi, King,

You need to give more context. I assume you are using watir and logger, I
don't know anything else, but regardless, I shouldn't have to guess.

Also, I assume by "goes to the Failed" you mean the condition is false, as
opposed to raises an error, for example.

Anyway Try making sure the browser is on the page you think it is on.
Try looking at the html and making sure that there is only one button with a
value of "Continue".
Try inspecting that button before you click it. Make sure it is there, make
sure it is the button you want to click.
Maybe use the debugger to get an interactive irb session into your code
right at that moment, so you can play with that object, make sure it looks
how you think it should look. (There is a nice Railscast gives an example of
how to use ruby-debug
http://railscasts.com/episodes/54-debugging-with-ruby-debug)

Also, I don't know what Readfrom_file is, but you should check that it is
named correctly, it's context implies a function, but functions almost never
begin with capital letters, and when they do, it's not for whatever you're
trying to do with it.
 
K

King Maker

Method:
def Readfrom_file(filename,fieldata,log,result)
@fielddata = fieldata
@log = log
@result = result
@filename = filename

@filename.puts "<TR><TD>#{@fielddata}<TD>"
@filename.puts "<TD>#{@log}</TD>"
if(@result == 'PASSED')
@filename.puts "<TD ALIGN='center'><FONT
COLOR='#00FF00'>#{@result}</FONT></TD></TR>"
else
@filename.puts "<TD ALIGN='center'><FONT
COLOR='RED'>#{@result}</FONT></TD></TR>"
end
end
def closeFile(filename)
@filename.close()
end

main file:

require 'watir'
include Watir
require 'logger'
require 'D:\Scripts\report.rb'
require 'D:\Scripts\Create_HTML.rb'
@file1 = HTML_HEADER()
opts = {}
File.open("c:/test/Flow1.txt") do |f|
f.each_line do |line|
opts[$1] = $2 if line =~ /^(.*)=(.*)$/
end
end
#Create the Timestamp on file
fileName=Time.now.strftime('%H-%M-%S-%d-%m-%Y')
OrignalFilename ="logger"
fileName1="C:\\test\\"+fileName+"_"+OrignalFilename+".txt"
@Customername =opts["customername"]
@Iteration = opts["iteration"]
log = Logger.new(fileName1)
begin
if(
ie=Watir::IE.start("http://"+@Customername+".vendormate.net/"+@Iteration+"/login.do"))
if(ie.contains_text("Login"))
log.info "login page open successfully"
else
log.info "login page not found"
break
end
end
rescue Exception => e
end
ie.link:)text, "New User Registration >>").click
log.info "Click on New User Registration link"
#Code for Finding file and Directory Path.
path="c:/test/"
file = "Test.txt"
begin
if File.directory?(path) && File.exists?(path+""+file)
log.info "File or Directory Found"
else
log.info "File or Directory Not Found\n"
end
rescue Exception => e
end
@FirstName = opts["firstName"]
@LastName = opts["lastName"]
@LegalName = opts["legalName"]
@VendorRepWorkPhone = opts["vendorRepWorkPhone"]
@Email = opts["email"]
@ConFirmEmail = opts["confirmEmail"]

#Compair the username and password and set into the textbox
begin
ie.text_field:)name,"firstName").set(@FirstName)
if(ie.text_field:)name,"firstName").value == @FirstName)
@result = 'PASSED'
@log ="First Name is correct"
log.info "First Name is correct"
else
@result = 'FAILED'
@log = "First Name not Match"
log.info "First Name not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"firstName").name,@log,@result)
rescue Exception => e
end

begin
ie.text_field:)name,"lastName").set(@LastName)
if(ie.text_field:)name,"lastName").value == @LastName)
@result = 'PASSED'
@log = "last Name is correct"
log.info "last Name is correct"
else
@result = 'FAILED'
@log = "last Name not Match"
log.info "last Name not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"lastName").name,@log,@result)
rescue Exception => e
end

begin
ie.text_field:)name,"legalName").set(@LegalName)
if(ie.text_field:)name,"legalName").value == @LegalName)
@result = 'PASSED'
@log = "legal Name is correct"
log.info "legal Name is correct"
else
@result = 'FAILED'
@log = "legal Name not Match"
log.info "legal Name not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"legalName").name,@log,@result)
rescue Exception => e
end

begin
ie.text_field:)name,"vendorRepWorkPhone").set(@VendorRepWorkPhone)
if(ie.text_field:)name,"vendorRepWorkPhone").value ==
@VendorRepWorkPhone)
@result = 'PASSED'
@log = "vendor Rep Work Phone is correct"
log.info "vendor Rep Work Phone is correct"
else
@result = 'FAILED'
@log = "vendor Rep Work Phone not Match"
log.info "vendor Rep Work Phone not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"vendorRepWorkPhone").name,@log,@result)
rescue Exception => e
end

begin
ie.text_field:)name,"email").set(@Email )
if(ie.text_field:)name,"email").value == @Email)
@result = 'PASSED'
@log = "Email is correct"
log.info "Email is correct"
else
@result = 'FAILED'
@log = "Email not Match"
log.info "Email not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"email").name,@log,@result)
rescue Exception => e
end

begin
ie.text_field:)name,"confirmEmail").set(@ConFirmEmail )
if(ie.text_field:)name,"confirmEmail").value == @ConFirmEmail )
@result = 'PASSED'
@log = "confirm Email is correct"
log.info "confirm Email is correct"
else
@result = 'FAILED'
@log = "confirm Email not Match"
log.info "confirm Email not Match"
end
Readfrom_file(@file1,ie.text_field:)name,"confirmEmail").name,@log,@result)
rescue Exception => e
end



page layout:
firstname:
lastname:
LegalName:
phone number:
email id:
conform email id:


continue button.button value is continue and name is _eventId_submit.


(next page opened)

reg number:
conform reg number:

continue button.





C:\>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

C:\>gem -v
0.9.4

browser IE 7.0.5730.13
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top