Forum: Ruby question on watir

Posted by Raj pal (arc)
on 2012-11-12 05:45
I am automating Idit application using Ruby, at one screen I can't feed
the input to one of the text box using the code
$browser.select_field(:id,"").set() what could be the reason.?

Raj
Posted by Joel Pearson (virtuoso)
on 2012-11-12 09:53
I think it's usually select_list, and you haven't entered an id to look 
for. You also haven't given a value to set to.
Posted by Raj pal (arc)
on 2012-11-12 10:30
hi thanks for reply.
I just place the syntax, My original line is this
"$browser.text_field(:id,'IDITForm@pmlPercentage').set(23)"

it gives the error

"Unable to locate element, using {:tag_name=>["text", "password",
"textarea"], :id=>"IDITForm@pmlPercentage"}"

But I can manually enter the value into this text box. while I am
writing this line "puts
$browser.text_field(:id,'IDITForm@pmlPercentage').exists?" it prints
false. But that element is present there.

If so, what would be the solution?

Raj
Posted by Joel Pearson (virtuoso)
on 2012-11-12 20:40
There are a few reasons it might not work.

Try navigating to the page using a Watir browser running through 
Interactive Ruby so you can do some live experimentation.

Try using longer paths, like specifying any parent elements (frames in 
particular):
thisfield = 
$browser.frame(:index,0).text_field(:id,'IDITForm@pmlPercentage')

Ensure that the page is fully loaded before looking for the field, In 
order to do this, I use Watir-Webdriver rather than just Watir alone, so 
I tend to use when_present:
$browser.text_field(:id,'IDITForm@pmlPercentage').when_present.set(23)

Otherwise, try locating all (or some of) the text fields and iterating 
through them to make sure you have the details exactly right (name, id, 
value, etc.):
$browser.text_fields.each {|el| puts el.id }
Posted by Raj pal (arc)
on 2012-11-14 11:24
Hi,

Really so much thank you for your reply, Actually I have already solved 
the problem, I solved the problem by executing via IRB mode in dos mode, 
But confusion still reamins because I was not able to identified what 
that problem was. But after i went through the IRB mode,scripts is also 
working fine, i haven't done any changes in scripts. . And some of your 
codings(give below) are useful for me for further work. Thank you so 
much for you reply.

"$browser.text_field(:id,'IDITForm@pmlPercentage').when_present.set(23)"
"$browser.text_fields.each {|el| puts el.id }"

Thanks,
Raj
Posted by Joel Pearson (virtuoso)
on 2012-11-14 14:14
No problem, I struggled to find documentation when starting out with 
Watir, but it's getting better all the time.

These are handy resources:

http://watirwebdriver.com/

http://www.rubydoc.info/github/jarib/watir-webdriver/
Posted by Raj pal (arc)
on 2012-11-15 06:09
Hi Joel Pearson

Thank you so much.

RAJ
Posted by Raj pal (arc)
on 2012-11-15 11:13
Hi Joel Pearson

I am using eclipse for automation,when i am executing the program using
debug mode,Once i executed some lines, is it possible to bring the
control back to some lines before, and continue execution from there or
debugging from there?What i meant to ask was, can i bring back the
control after execution happens,and then continue the execution from
there on(from new place)?

Raj
Posted by Raj pal (arc)
on 2012-11-15 11:27
Hi Joel Pearson

please look at this error,

[15:51:13] [ERROR] : Error attaching: excelOpen: false , fileOpen:
false, file:
C:\work1\IDITTestAutomationProject\TestData\TestData_MyCopy.xls error:
Open
    OLE error code:800A03EC in Microsoft Office Excel
      'TestData_MyCopy.xls' cannot be accessed. The file may be
corrupted, located on a server that is not responding, or read-only.
    HRESULT error code:0x80020009
      Exception occurred.
Open
    OLE error code:800A03EC in Microsoft Office Excel
      'TestData_MyCopy.xls' cannot be accessed. The file may be
corrupted, located on a server that is not responding, or read-only.
    HRESULT error code:0x80020009
      Exception occurred.


I encounter this error so often, I haven't opened any Excel file during
execution, But still i am encountering this error, what is the reason ?
But if I close the eclipse and open again then this won't be coming.How 
to solve this error without closing the eclipse?

Raj
Posted by Joel Pearson (virtuoso)
on 2012-11-15 13:25
Raj pal wrote in post #1084536:
> Hi Joel Pearson
>
> please look at this error,
>
> [15:51:13] [ERROR] : Error attaching: excelOpen: false , fileOpen:
> false, file:
> C:\work1\IDITTestAutomationProject\TestData\TestData_MyCopy.xls error:
> Open
>     OLE error code:800A03EC in Microsoft Office Excel
>       'TestData_MyCopy.xls' cannot be accessed. The file may be
> corrupted, located on a server that is not responding, or read-only.
>     HRESULT error code:0x80020009
>       Exception occurred.
> Open
>     OLE error code:800A03EC in Microsoft Office Excel
>       'TestData_MyCopy.xls' cannot be accessed. The file may be
> corrupted, located on a server that is not responding, or read-only.
>     HRESULT error code:0x80020009
>       Exception occurred.
>
>
> I encounter this error so often, I haven't opened any Excel file during
> execution, But still i am encountering this error, what is the reason ?
> But if I close the eclipse and open again then this won't be coming.How
> to solve this error without closing the eclipse?
>
> Raj

You may have crashed out without closing the process which is accessing 
the file. In that case, you might have an invisible process locking the 
file which is being terminated when you close Eclipse.
Have a look at this for example:

____________________________________________
begin
excel = WIN32OLE::new("excel.application")
#Do some stuff where excel might crash
rescue
excel.Quit()unless excel.nil?
end
____________________________________________

Within that code, if you experience an error inside the begin/end block, 
excel will close and therefore stop locking whichever file it's 
accessing. You should probably do the same type of exception-based 
garbage collection with any object which might lock files.
Posted by Raj pal (arc)
on 2012-11-15 15:45
Hi,

I got it, Thank you.

Raj
Posted by steve dodkin (Guest)
on 2012-11-16 01:19
(Received via mailing list)
unsubscribe
Posted by Raj pal (arc)
on 2012-11-16 06:18
i don't understand, what do you mean by "unsubscribe"?

Raj
Posted by Arlen Cuss (Guest)
on 2012-11-16 06:28
(Received via mailing list)
Hi Raj,

People seem to have gotten the idea that they unsubscribe by sending the 
word "unsubscribe" to the list itself.

Unfortunately, this is mistaken; it'll no sooner unsubscribe them than 
would shouting unsubscribe at the computer screen.

If they really want to unsubscribe, they can either use the form here:

http://www.ruby-lang.org/en/community/mailing-lists/

Or they can mail the word "unsubscribe" to the list *controller* 
address, which for ruby-talk is:

ruby-talk-ctl@ruby-lang.org

Cheers,

Arlen
Posted by Raj pal (arc)
on 2012-11-16 06:52
Hi Arlen

Thank you , I was confused when i saw the word unsubscribe,because i
thought somebody was asking me to unsubscribe. Now it's clear .

Raj
Posted by Raj pal (arc)
on 2012-11-20 07:15
hi Joel Pearson

I have a question, For an example consider that I have to execute 10 
test case, but at the first attempt it is found that internet has been 
down, in such situation, it is not terminating the execution, but it 
tries to run the remaining test cases, any idea to stop this as soon as 
it realizes internet connection has been down.? It should not execute 
the remaining test cases as soon as it is found internet connection has 
been down.

Raj
Posted by Joel Pearson (virtuoso)
on 2012-11-20 12:39
Firstly, please start any new question as a new thread so others can 
find answers more easily in future.

Anyways, you want to look into this kind of thing:
http://www.tutorialspoint.com/ruby/ruby_exceptions.htm

If you're receiving a Timeout exception from Watir but your program 
keeps running then you're probably handling the exception. What you need 
to do is terminate when you hit that kind of exception. If you're 
calling a method and the exception is handled inside that method, you'll 
need to return a value which will be recognised by the parent and used 
in a decision as to whether to continue or terminate execution.

For example (caveat lector, untested code):
________________________________________________

def mymethod
b = Watir::Browser.new
b.goto 'www.purple.com'
b.close
return true
rescue Timeout::Error
puts "Page load timed out"
return false
rescue => e
puts e
return false
ensure
b.close rescue nil
end

10.times do |iteration|
unless mymethod
puts "Error occurred, terminating process"
exit
else
puts "Succeeded: #{iteration}"
end
end
Posted by Raj pal (arc)
on 2012-11-20 16:08
Yeah I will start a new thread if i have question in future, Thank you 
so much.

Raj
Posted by Raj pal (arc)
on 2013-01-21 10:23
hi,

I couldn't create a new thread, If press submit button, it came back to 
the preview window .So I am posting here.

I have installed Ruby 1.8.7 and while i was trying to install "gem
install watir" it gives the error "ERROR:  Error installing
watir:win32-process requires Ruby version > 1.9.0."But it was not the
case when i installed the Ruby last time? Is there any way to install
win32-process in version 1.8.7?Or is there any way can i able to install
"gem install watir" without any error?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-21 10:39
You'd need to install a version compatible with 1.8.7:
"gem install watir -v (version number here)"
But a far better approach is to upgrade to Ruby 1.9.3.
Posted by Raj pal (arc)
on 2013-01-21 10:57
"gem install watir -v (version number here)"

I used this "gem install watir -v 3.0.0" (the reason I have used is,I 
have watir 3.0.0 for Ruby 1.8.7 in my computer already)Now i am 
installing into another system. But anyway i couldn't succeed with 
installation using the above syntax.

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-21 13:34
Without a more descriptive response than "i couldn't succeed" ,it's 
impossible to suggest anything relevant to combat your problem.
Other than "USE RUBY 1.9.3!", of course.
Posted by Raj pal (arc)
on 2013-01-21 13:38
I used 'gem install watir -v 3.0.0' ,But i failed to install this. Error 
occurred suggesting me to install watir 1.9.0.

Raj
Posted by Raj pal (arc)
on 2013-01-22 18:58
hi,

we usually run ruby program by giving the command

>ruby prog.rb

But here our source code is needed. But Is there any way we could 
convert this file into .exe and then run the program directly by double 
clicking that file or directly typing name of the file in the command 
prompt?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-22 21:28
If you want to just double click the file and run it then you can 
associate ".rb" files with the Ruby interpreter.

If you want an executable, look up http://rubyforge.org/projects/ocra/
Posted by Raj pal (arc)
on 2013-01-23 14:30
Ok thank you.
Posted by Raj pal (arc)
on 2013-01-23 15:20
Hi,

I am running 500 test cases. I am facing some problem here,that is, if 
server has been down for sometime,we couldn't access the web page,So 
watir fails to access the web page, and it stops it's running. and then 
again i need to start the process manually as soon as server has been 
up,Is there any way we can avoid this manual interference,what i meant 
to say is,Can we make our program for continual checking until server 
has been up and then it has to start the program automatically?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-23 19:43
Rather than tell you how to fix your specific problem, I'll give you a 
link on how to handle Exceptions; so you can broaden your knowledge and 
apply it appropriately.
http://www.skorks.com/2009/09/ruby-exceptions-and-...
Posted by Raj pal (arc)
on 2013-01-24 08:05
Ok Thank you.
Posted by Raj pal (arc)
on 2013-01-28 08:34
hi,

They have explained how can we handle the exception. Now, my question 
is, I am working in a big project, there are many screens, we have 
written unique script for each and every screen. So the server may fails 
to respond at any time or at any script while execution. So how can i 
write the exception common for all screen? My ultimate goal is, i need 
to inform the user that server has been down at this test case. how 
would i do this?



Raj.
Posted by Joel Pearson (virtuoso)
on 2013-01-28 11:21
It depends what you mean by "screens". If you're referring to the 
different pages your script is accessing and the scripts are all running 
on the same machine, you can join your tests into a single environment 
so that the error handler can encapsulate all of them. Look into using a 
Class or Module.

If you mean you're running individual scripts on different machines, 
then you have the option of placing a log file in a shared location 
which any failing routine can append to, so that you can trace errors 
after the tests have been run, or check the file before running the 
tests to see whether this iteration has already failed and can be 
skipped.
Posted by Raj pal (arc)
on 2013-01-28 15:37
hi Joel Pearson

Thank you, I am running in a single machine, For each screen I have 
defined corresponding function,when one particular screen has to be 
automated, corresponding function will be invoked. Basically, from one 
function all other function are getting called. And I haven't thought 
class usage anyway. I will try put it in class as packed one. Thank you 
for you suggestions.

Raj
Posted by Raj pal (arc)
on 2013-01-28 15:59
Hi ,

could you please write the small code about how to write the exception 
handling inside the class common to all function.?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-28 16:48
You basically have 2 options...

You can handle the exception only at parent level and not bother with
local error trapping:
______________________
begin

  def method1
    #Content
  end

  def method2
    #Content
  end

  method1
  method2

rescue
  #Handle exception
end
______________________

Or you could handle each exception at a local level and then hand it up
to the next handler:
______________________
begin

  def method1
    #Content
  rescue
    #Do something here
    raise #Pass the error up to the next level
  end

  def method2
    #Content
  rescue
    #Do something here
    raise #Pass the error up to the next level
  end

  method1
  method2

rescue
  #Handle exception
end
______________________

You don't strictly need a class, a parent method would do but building a
class system allows you to avoid rewriting the same code repeatedly by
dealing with variables as arguments and leaving the surrounding
structure as part of your methods. For more info on this, look up DRY
(Don't Repeat Yourself).

FYI, this is what it would look like as a class

______________________

class MyTestClass

  method1
    #Do stuff
  end

  method2
    #Do stuff
  end

rescue
  #Do stuff here
end
______________________
Posted by Raj pal (arc)
on 2013-01-28 16:55
Hi Thank you so much, what do you mean by "don't repeat yourself"? I 
think class form would be much more easy. Any way I will try it out.

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-28 19:23
Regarding DRY,
I know that when running Watir tests from different scripts you'll be 
rewriting a lot of the same code, like starting and closing the browser, 
for example. By using a single running environment (or requiring tools), 
you can set up the repetitive tasks into methods, meaning you need only 
write the code once.
Unless of course you're ahead of the game and you're only writing the 
unique steps into each of your scripts while requiring the common 
methods from elsewhere, in which case you can ignore me :)
Posted by Raj pal (arc)
on 2013-01-29 05:46
OK Thank you.
Posted by Raj pal (arc)
on 2013-01-29 07:03
hi,

please consider this code below

these three function has been written in separate page.
def fun2
end


def fun3
end


def fun4
end
________________________________
def fun1(argument)
        begin
          if(argument == this)
               fun2
          end
        end
        begin
          if(argument == some)
                fun3
          end
        end
        begin
         if(argument == something)
          fun4
         end
        end
rescue
#some statement
end
____________________________________
class fun
    for loop
       fun1(argument)
    end
end

I hope you can understand above simple structure of my program.when the 
first time "fun1" called,assume inside the fun1, fun3 is getting called, 
and now if server has been down, execution should not continue, but it 
has to be terminated. But regardless of server state, program continues 
to execute.could you give me suggestion where to put this exception to 
avoid this execution?

Another problem is, if server has not been down, and there is some error 
in function, it has to terminate the funtion, but next execution has to 
continue. So how could I handle this situation?

Raj
Posted by Raj pal (arc)
on 2013-01-29 10:01
class MyTestClass

  method1
    #Do stuff
  end

  method2
    #Do stuff
  end

rescue
  #Do stuff here
end

you gave this example for writing exception inside the class, but it is 
not working for me, consider the program below,

class Raj
  def hello
    puts 'hello'
    1/0
        end
        def hi
    puts 'hi'
  end

rescue Exception => e
    puts 'the exception has been raised'
end

a=Raj.new
a.hello
a.hi


Here exception error of division by 0 is not caught by exception, why it 
is so?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-29 10:23
You're rescuing the exceptions inside fun1, but your loop inside class 
fun will continue because you're not passing the exception any higher.

Catch specific types of exceptions. 
http://wtr.rubyforge.org/rdoc/1.6.5/classes/Watir/...
This one should cover server outages: Watir::Exception::TimeOutException

You're kind of missing the point with the class, it's intended to 
encapsulate your methods.

Also this:

_____________________

def fun1(argument)
        begin
          if(argument == this)
               fun2
          end
        end
        begin
          if(argument == some)
                fun3
          end
        end
        begin
         if(argument == something)
          fun4
         end
        end
rescue
#some statement
end
_____________________

is equivalent to this:

_____________________

def fun1(argument)

  if argument == this
    fun2
  elsif argument == some
    fun3
  elsif argument == something
    fun4
  end

rescue
  #some statement
end
_____________________
Posted by Joel Pearson (virtuoso)
on 2013-01-29 10:35
It's probably best to put the errorhandler in the script which is using 
the class. Apparently it doesn't like rescuing inside a class like that. 
This approach works:

irb(main):001:0> class Raj
irb(main):002:1>   def hello
irb(main):003:2>     puts 'hello'
irb(main):004:2>     1/0
irb(main):005:2>         end
irb(main):006:1>         def hi
irb(main):007:2>     puts 'hi'
irb(main):008:2>   end
irb(main):009:1>
irb(main):010:1* rescue Exception => e
irb(main):011:1>     puts 'the exception has been raised'
irb(main):012:1> end
=> nil
irb(main):013:0> begin
irb(main):014:1*   Raj.new.hello
irb(main):015:1> rescue
irb(main):016:1>   puts 'the exception has been raised'
irb(main):017:1> end
hello
the exception has been raised
=> nil
Posted by Raj pal (arc)
on 2013-01-29 13:18
irb(main):013:0> begin
irb(main):014:1*   Raj.new.hello
irb(main):015:1> rescue
irb(main):016:1>   puts 'the exception has been raised'
irb(main):017:1> end

Yes I understood now.

I have another here,

please have a look at this code
------------------------------------------
class Raj
  def hi
  raja
  gopal
  hello
  end
def raja
  puts 'raja'
end
def gopal
        begin
  puts 'gopal'
  1/0
  rescue Exception =>e
  puts e
        end
end
def hello
  puts 'hello'
end
end


begin
Raj.new.hi
rescue Exception => e
puts e
end
-------------------------------------------

here, the exception has been caught at the gopal function,So the 
exception which I have written for entire class hasn't been invoked. So 
next hello also was called. But hello should not be invoked in my case, 
meanwhile I couldn't take exception handling which is within gopal 
function because it has some other need. what can I do to solve this 
problem?
Posted by Joel Pearson (virtuoso)
on 2013-01-29 13:23
If you want the Exception to be passed up to the next level...
Instead of this:

  1/0
 rescue Exception =>e
  puts e

do this:

  1/0
 rescue Exception =>e
  puts e
  raise

A local rescue would be used if you wanted to do something specific to 
that method, otherwise just don't rescue it there, it'll be picked up by 
the error handler you're using at the top level.
Posted by Raj pal (arc)
on 2013-01-29 13:33
Ok thank you ,it's very helpful.

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-29 13:34
Raj pal wrote in post #1094182:
> meanwhile I couldn't take exception handling which is within gopal
> function because it has some other need. what can I do to solve this
> problem?

To rescue something specific, rescue is like a case statement:

begin
  1/0
rescue ZeroDivisionError => err
  puts 'Rescued expected error'
  p err
rescue => err
  puts 'Rescued unexpected error'
  p err
  raise
end
Posted by Raj pal (arc)
on 2013-01-29 16:24
Yep, thank you very much, I exactly understood.

Raj
Posted by Raj pal (arc)
on 2013-01-30 07:52
hi,

I have some confusion with define method

class Raja<Watir::testcase

define_method(testName[i]) do
  puts 'raja'
end

end
how this define_method is automatically executed when we run the script?
(the above program will not execute),I haven't called this function by
creating object, but when i run this script this method gets
automatically executed. could you please explain me how it is working?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-30 10:28
I've never tried this before, but after a little digging I got this to 
work:

irb(main):001:0> class Raja
irb(main):002:1>   def initialize
irb(main):003:2>     create_method(:raja) {puts 'raja'}
irb(main):004:2>   end
irb(main):005:1>  def create_method(name, &block)
irb(main):006:2>     self.class.send(:define_method, name, &block)
irb(main):007:2>   end
irb(main):008:1> end
=> nil
irb(main):009:0> Raja.new.raja
raja

I used the "create_method" example from the Module documentation, and 
then used initialize to trigger it when the class is created via "new". 
Of course you could iterate through a hash or array to populate your 
class with multiple methods.
Posted by Raj pal (arc)
on 2013-01-30 10:39
I am not sure whether you have answered my question. Actually my 
question was the define_method was getting called when I execute the 
file, But there was no object creation is in my file like you did( 
Raja.new.raja). "define_method" is getting called when I execute the 
file, So my question was who calls this define method. Actually it was 
declared inside Module.rb.

like

def define_method(*args)
end

RAJ
Posted by Wayne Brisette (Guest)
on 2013-01-30 11:31
(Received via mailing list)
I seem to be missing something. If I don't have any .js files in my 
input
directory, shouldn't this fail and fall into rescue?


begin
  jsfile = Dir.glob("*.js")          # Get the javascript file that 
contains the
real hiearachy.
  jsfile.each do |f|
   js_contents = File.open(f, "rb") {|io| io.read }
   process_js(js_contents)
   end
rescue
   puts "The x7_top.js file must be in the input directory."
   exit
end

- Wayne
Posted by Joel Pearson (virtuoso)
on 2013-01-30 11:47
Raj pal wrote in post #1094296:
> I am not sure whether you have answered my question. Actually my
> question was the define_method was getting called when I execute the
> file, But there was no object creation is in my file like you did(
> Raja.new.raja). "define_method" is getting called when I execute the
> file, So my question was who calls this define method. Actually it was
> declared inside Module.rb.
>
> like
>
> def define_method(*args)
> end
>
> RAJ

Because you haven't contained it within a method, it'll execute when you 
run the file.
Posted by Raj pal (arc)
on 2013-01-30 12:02
hi,
I think you have misunderstood,

For an example consider the code below
---------------------------------------------
class Raja < Watir::TestCase

  def test_2_Event
      puts 'raja'
  end

  def test_3_Followup
      puts 'gopal'
  end

  def test_4_hi
      puts 'hi'
  end

  def testhello
    puts 'hiiii'
  end


end
---------------------------------------------

Now for the above class you no need to create the object, instead if you
execute the file which contains this class, it will be executed
successfully. So Watir::TestCase contains some thing which invoke this
function name starts with "test". Now what if we have 1000 files which
starts with test, So we have a method "define_method" which generate the
function dynamically. This takes the name as an argument.for an example
define_method(test_3_Followup). Now my question how these function are
getting invoked without any calling to these functions?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-30 12:15
It looks like anything starting with "test" gets executed automatically
in alphabetical order. It's a convenience thing so you don't have to
manually make the list of all your methods to be run, you just name them
in order: "test_01_DoThis", "test_02_ThenDoThis".

This looks useful:
http://jimhmatthews.wordpress.com/2007/10/28/how-t...
Posted by Raj pal (arc)
on 2013-01-30 12:19
Yes this is what I meant, but now the problem is, how do I write the 
exception handling for such a class?

If I were to call the function ,then i would write the exception 
handling like,

begin
Raja.new.hi
rescue Exception => e
end
But now, there is no method calling. If so, how would I write the 
exception handling?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-01-30 12:25
What do you want the handler to do? Skip to the next test, quit the 
program, begin the next test loop?
I don't have TestCase installed, so I can't experiment with this, but 
experimentation is often the way forward. Try placing handlers in 
different places and see what they pick up.
Posted by Peter Hickman (Guest)
on 2013-01-30 12:31
(Received via mailing list)
There is nothing wrong with iterating over an empty list. This will not
produce and error, you will need to check the list manually
Posted by Raj pal (arc)
on 2013-01-30 12:38
when the control in a particular method and server has been failed, 
entire program has to terminate, it should not call the next method. 
Handling with exception is the problem here, because it allows me to run 
the next test case.

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-30 12:41
I'm pretty sure the whole point of using testcase is so that you can 
report back the number of failures and successes rather than terminate 
at the first failure. If you really want to terminate on failure you 
could just do this without using testcase.
Posted by Raj pal (arc)
on 2013-01-30 12:44
Yes, you are right , I need to report to the user that how many failures 
and how many successes, But however I need to tell to the user that It 
was failed since server was failed to responded.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-01-30 13:17
I think you'll need to do something specific around each page navigation 
which rescues the Timeout error specifically and then calls "exit" after 
outputting the appropriate failure message.
I'm not sure you're supposed to be able to rescue outside of individual 
testcases. perhaps you could run your methods through something which 
appends a handler?

modified_method = "#{current_method.reverse.sub(/\bdne\b/, '').reverse}
rescue Watir::Exception::TimeOutException
  puts 'Server failed to respond'
  exit
end
"
Posted by Raj pal (arc)
on 2013-01-31 07:22
OK thank you.
Posted by Raj pal (arc)
on 2013-01-31 08:38
hi,

tests = method_names.delete_if { |method_name| method_name !~ /^test/ }
while I am trying to execute this line, it says that

" undefined method `delete_if' for "test_1":String (NoMethodError)"

What should I do to work with this delete_if method?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-01-31 09:50
delete_if is an array method, it looks like you're trying to run it 
against a string.
Posted by Raj pal (arc)
on 2013-02-02 10:00
Yes I got it. Thank you.
Posted by Raj pal (arc)
on 2013-02-04 11:59
hi consider your program

def mymethod
b = Watir::Browser.new
b.goto 'www.purple.com'
b.close
return true
rescue Timeout::Error
puts "Page load timed out"
return false
rescue => e
puts e
return false
ensure
b.close rescue nil
end

10.times do |iteration|
unless mymethod
puts "Error occurred, terminating process"
exit
else
puts "Succeeded: #{iteration}"
end
end

This program opens the browser by executing the statement
b.open "www.purple.com" and then it immediately closes the browser 
regardless of loading status of the browser. That means it executes the 
statement www.purple.com  and once browser open operation has been 
triggered, it just executes next statement b.close. But it should not be 
the case right? Because it has to wait until browser gets opened and 
then it has to go to the next statement, So it could calculate the time 
taken by the browser to open and if it exceeds the time limit ,then it 
can direct the execution control inside

"rescue Timeout::Error
puts "Page load timed out"
return false"

So Is it a wrong program for Timeout, Or did i misunderstand?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-02-04 12:23
This was done with watir-webdriver, not selenium-webdriver, so it
handles the page load waiting and timeout raising by itself.

The reason I used purple.com is because it's the fastest-loading page on
the internet, so it will look very quick.

If you want to account for the browser's opening time as well, then you 
could do something like this:

Timeout.timeout(10) do
  b = Watir::Browser.new
  b.goto('www.purple.com')
  b.close
end
Posted by Raj pal (arc)
on 2013-02-04 12:40
Timeout.timeout(10) do
  b = Watir::Browser.new
  b.goto('www.purple.com')
  b.close
end


I tried this code it is not giving any output, means it is not loading 
loading anything. Do i need to make a call? could you please write the 
full code?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-02-04 14:00
You need to require 'timeout'
Posted by Raj pal (arc)
on 2013-02-04 15:28
ok ok.

Raj
Posted by Raj pal (arc)
on 2013-03-12 14:33
hi Joel Pearson,

$browser.text_fields.each {|el| puts el.id }

hi, you have given me to print the id of the text box, but what if i 
want to print the id's of all field?(including combo,checkbox)?

What should I do?
Posted by Joel Pearson (virtuoso)
on 2013-03-12 15:05
You could try "elements" but that'll be quite slow on most pages since 
there are often a lot you can't see. You're better off specifying the 
type you want, e.g. select_lists, checkboxes

Try reading the documentation to see the different element types:
http://www.rubydoc.info/github/jarib/watir-webdriv...
Posted by Raj pal (arc)
on 2013-03-12 15:46
OK, Thank you.
Posted by Raj pal (arc)
on 2013-03-13 08:59
hi Joel Pearson,

I have one text box, another one is combo box, combo box value will be
populated according to the value of text box. But last focus control is
being operated here, when we come out of text box, then only combo box
is populated, So when i write the code to click the combo box, it fails
to load, So what is your suggestion in such a case?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 09:40
Here's something I did to deal with a dynamically updating text field.
The user clicks outside the field (or tabs away from it) after 
populating it and it populates other fields automatically. This code 
waits for that to happen.
You should be able to do something similar in your code for your 
particular case.

@driver.text_field(:id => 'currentcustomer').set @data[:Account]
until @driver.text_field(:id => 'customer_account_num').value != ''
  @driver.text_field(:id => 'currentcustomer').send_keys :tab
  sleep 0.5
end
Posted by Raj pal (arc)
on 2013-03-13 10:03
Oh,that's great. I solved my problem indeed.

Thanks,
RAJ
Posted by Raj pal (arc)
on 2013-03-13 11:26
hi Joel Pearson

can i check whether it is text box or combo box or check box using id?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 11:48
I think your best best is to use my_element.html and extract the valid 
information from there.
Posted by Raj pal (arc)
on 2013-03-13 12:28
Then how can I verify whether it is combo or text box?

for an example,

$browser.elements.each do |i|

puts i

end

Now how can i verify i is a text box or combo box, Because i need to
write a condition according to that.

Or is there any way can we print like

textbox,
combobox,
checkbox,

?
I mean I want to print the object of that screen,is it possible?

Raj
Posted by Joel Pearson (virtuoso)
on 2013-03-13 12:55
[:text_fields, :select_lists, :checkboxes].each do |type|
  $browser.send(type).each do |i|
    puts i, type.to_s[0..-2]
  end
end
Posted by Joel Pearson (virtuoso)
on 2013-03-13 12:57
Joel Pearson wrote in post #1101394:
> [:text_fields, :select_lists, :checkboxes].each do |type|
>   $browser.send(type).each do |i|
>     puts i, type.to_s[0..-2]
>   end
> end

bollocks, that puts "checkboxe" instead of "checkbox".
Ah well, you get the idea.
Posted by Raj pal (arc)
on 2013-03-13 12:59
Thank you very much this would help me,

and I have another question,

consider the below hash,

a={1=>2,3=>4,5=>6}

when I try to print the key values, it is not printing in the order

a.each do |key,value|
puts key
end

it's printing 5 3 1

Is there any way could I able to print in order.?

RAJ
Posted by Raj pal (arc)
on 2013-03-13 13:06
hi,

[:text_fields, :select_lists, :checkboxes].each do |type|
  $browser.send(type).each do |i|
    puts i, type.to_s[0..-2]
  end
end

This code stuns me. Beautifully written.Please consider my last question 
about Hash.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 13:08
Raj pal wrote in post #1101398:
> hi,
>
> [:text_fields, :select_lists, :checkboxes].each do |type|
>   $browser.send(type).each do |i|
>     puts i, type.to_s[0..-2]
>   end
> end
>
> This code stuns me. Beautifully written.Please consider my last question
> about Hash.
>
> RAJ

Hah, doesn't feel like it to me! Thanks anyway :)
Posted by Lee Daekeun (Guest)
on 2013-03-13 13:09
(Received via mailing list)
As far as I know, there is no "order" in hash. If the order matters, you
should use list instead of hash.
2013. 3. 13.  9:00 "Raj pal" <lists@ruby-forum.com> ۼ:
Posted by Joel Pearson (virtuoso)
on 2013-03-13 13:10
Try this:

a.sort_by &:first

actually sorting by the keys is the default:

a.sort
Posted by Raj pal (arc)
on 2013-03-13 13:17
a.sort_by &:first


Here a is what? Is it hash?

RAJ
I don't understand how would I write the full code?

a=a.sort_by &:first

Is it like that?

RAJ
Posted by Raj pal (arc)
on 2013-03-13 13:20
Ok ok I understood here, But I don't want the sorted order, But I want 
the exact same order for an example,

a={'a'=>'raj','z'='gopal','b'='hello'}

If I want to store or print the keys in an array it has to be in the 
same order

Is it possible?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 13:22
If you know the input order then use your inputs to retreive the values 
in the same order later:

a={'a'=>'raj','z'='gopal','b'='hello'}
order = a.keys

#Change the values and mess up the order...

#Output in the same order
order.each { |k| puts k, a[k] }
Posted by Raj pal (arc)
on 2013-03-13 13:41
HI,

Still it is printing in the same order it doesn't provide the result in 
right order.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 13:47
Are you trapping the order before you mess with the hash?
If the order is important, why are you using a hash?
Can a sorting algorithm duplicate the order?
Posted by Raj pal (arc)
on 2013-03-13 14:04
I am using excel sheet to store the values, while I am reading those 
values I am storing inside the hash, first row act as a key, remaining 
column act as a values, Now I need the order of those column to match 
with the fields, But i don't have.

If i had the Order then I would not have to write like
-----
begin
 $browser.text_field(:id,'').set(contact['Name']
rescue =>e
  puts e
end

begin
 $browser.text_field(:id,'').set(contact['age']
rescue =>e
  puts e
end

begin
 $browser.text_field(:id,'').set(contact['Gender']
rescue =>e
  puts e
end
-----

consider the above three code, I can take id dynamically and I can pass 
into text_field(:id,'  ') here and at the same time if i can get the 
Name,age,Gender in the order then I can pass that too so I can put into 
the loop, I no need to write the static code for thousands of field. But 
unfortunately it's not working.

Thanks for your help.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 14:16
Well, that's a lot of logic to cover with a quick Q&A.
Have you considered interfacing with the excel sheet directly rather 
than using a hash?
Posted by Raj pal (arc)
on 2013-03-13 14:18
Yes,

begin
 $browser.text_field(:id,'').set(contact['Gender']
rescue =>e
  puts e
end

In the above line I am interacting with excel to retrieve this value 
contact['Gender']

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 14:28
In that case you may as well use excel's columns and rows to iterate, 
and update it live with the results. No more worrying about disorganised 
hashes that way.
Posted by Raj pal (arc)
on 2013-03-13 14:33
How can you iterate excel column and row,

If i retrieve the first row, headings will be the keys and values would 
be values, If i retrieve the second rows then same headings will be the 
keys and second row values would be the values. And my long project 
incorporate this view.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 14:36
How you iterate depends on what you're using to access excel. There's 
always the option of reading the whole lot into an array, modifying it 
in memory during your browser interaction, and then rewriting all at 
once
Posted by Raj pal (arc)
on 2013-03-13 14:40
Yes that we have already done, from that I was reading my HASH. OK i 
will look into it if that is possible by array,so that order would not 
change.

RAJ
Posted by Raj pal (arc)
on 2013-03-13 14:55
Thank you for your help today, you have taught a lot today to me.

Thanks,
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-13 16:21
If you really want a hash you could incorporate the cell addresses:
For example:

hash = { 'Name' => { B1: 'James', B2: 'Tiberius', B3: 'Kirk' },
         'Age' => { C2: 1, C3: 2, C4: 3  },
         'Gender' => { D2: 'Man', D3: 'Cat', D4: 'God' }
}

> hash['Name'][:B3]
=> "Kirk"
Posted by unknown (Guest)
on 2013-03-13 17:03
(Received via mailing list)
Am 13.03.2013 12:59, schrieb Raj pal:
> a.each do |key,value|
> puts key
> end
>
> it's printing 5 3 1

then you are using a very old Ruby version.

>
> Is there any way could I able to print in order.?

1. In case you need insertion order:

    - upgrade to 1.9.3 or 2.0.0
      (nowadays hashes keep the insertion order)

    - use an array

2. In case you need sorting order: sort before printing

1.8.7 :005 > a.sort.each do |key,value|
1.8.7 :006 >   puts key
1.8.7 :007?> end
1
3
5
Posted by Raj pal (arc)
on 2013-03-14 05:23
hi, thank you, I am using the version of 1.8.3 version, But if i use the 
1.9.3,I am facing the problem gem installation, So i never go there.

RAJ
Posted by unknown (Guest)
on 2013-03-14 07:44
(Received via mailing list)
Am 14.03.2013 05:23, schrieb Raj pal:
> hi, thank you, I am using the version of 1.8.3 version, But if i use the

Any support for 1.8.7 (like security fixes) will end this year.

> 1.9.3,I am facing the problem gem installation, So i never go there.

?
Posted by Raj pal (arc)
on 2013-03-14 07:59
I have already in a project for automation,now all functions are working 
in 1.8.7 ,So if i immediately changes to 1.9.7,I will be in need of 
changing everything right?

RAJ
Posted by Raj pal (arc)
on 2013-03-14 08:44
hi, I am comparing objects like

if a.class.to_s == 'hash'
   puts 'hash'
end

Is there any way can i compare objects directly?

Like if a.class==OBJECT
       puts 'hash'
end
Posted by tamouse mailing lists (Guest)
on 2013-03-14 09:28
(Received via mailing list)
On Mar 14, 2013 2:45 AM, "Raj pal" <lists@ruby-forum.com> wrote:
>        puts 'hash'
> end
>
> --
> Posted via http://www.ruby-forum.com/.
>

Not quite getting what you want, but would === or is_a? work?
Posted by Joel Pearson (virtuoso)
on 2013-03-14 10:06
object.is_a?( Hash ) is the one I usually use.

By the way, this caught me out for a while. When using a case statement 
to check classes, the syntax is a bit different from if statements:

case object
when Hash
end
Posted by Raj pal (arc)
on 2013-03-14 11:04
yes it is working for me, this is what I want.And what is the difference 
did you see while you were using for case statement.?

Thank you.
RAJ
Posted by Raj pal (arc)
on 2013-03-14 13:15
hi I have a question about pop up, we can handle the pop up if it is the 
part of the window. But Now I am automating another screen,here pop up 
arises as new window, how can i handle this pop up? Is there any idea?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-14 13:38
This was already addressed in another thread:
http://www.ruby-forum.com/topic/4407617#new
Posted by Raj pal (arc)
on 2013-03-14 13:47
Ok Thank you very much.

RAJ
Posted by Raj pal (arc)
on 2013-03-18 10:44
hi Joel Pearson,

a="hi how are you

what are you doing"

b="hi how are you

what are you doing"

one=a
one=one.delete(' ')
one=one.delete("\n")
puts one
two=b
two=two.delete(' ')
two=two.delete("\n")
puts two

The above code is working perfectly, but while i take "hi how are you
what are you doing" from SCREEN to a variable one,this delete("\n") is
not working, can you guess where the problem is?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-18 12:13
Inspect the result you get from "SCREEN". You may have different 
characters in there.

By the way, if you really feel the urge to remove all whitespace, try 
this:

a = a.gsub(/\s/,'')
Posted by Raj pal (arc)
on 2013-03-18 12:22
Yes thank you, I realized that that character was 13 not 10.10 is for 
enter key.That's what it hasn't been removed. Thanks anyway for this a = 
a.gsub(/\s/,'')code.

RAJ
Posted by Raj pal (arc)
on 2013-03-18 13:03
"Any support for 1.8.7 (like security fixes) will end this year."

what do you meant by this line? I don't understand what you meant by 
support for 1.8.7 will end?
Posted by Joel Pearson (virtuoso)
on 2013-03-18 13:14
It means that 1.8.7 won't receive any more updates, so you need to 
upgrade to a newer Ruby version ASAP.
I'd reccommend testing for compatiblity on a test network (or test 
computer for smaller-scale operations) before rolling out an update.
Posted by Raj pal (arc)
on 2013-03-18 13:20
Ok thank you.

RAJ
Posted by Raj pal (arc)
on 2013-03-18 14:29
hi  Joel Pearson,


You told me to refer the another discussion for popup, I used your code
here,

$browser.windows.each {|w| w.close rescue nil}
$browser.close rescue nil

But it is not closing the window as you told there.

My problem is, when i am pressing the next button one pop up is getting
opening in a new window.I used above code of yours, but it's not
working.what should I do to handle that pop up? In the earlier case, pop
up was attached with browser window, so I used the developer tool to
find the id and i succeeded but I now I couldn't use the developer tool
also.

And also I need to read the message on the pop up, Is it possible ? you 
only have given the way to close the pop up.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-18 15:00
It helps to get some feedback using IRB:

puts $browser.windows.count

$browser.windows.each {|w| puts w.title }

#The last window should be your popup:
$browser.windows.last.use do
  $browser. (code to read the message here)
end
Posted by Raj pal (arc)
on 2013-03-18 15:18
hi I have used the below code,

 puts $browser.windows.count
 $browser.windows.each do |w|
      puts w.title
      w.close
    end


but it is not closing the pop up. but it's printing the title and count
also.I think w.close is not working. what can i do to solve this
problem?And also the pop consist of Ok button, can i press that OK
button?

I didn't understand this message

 $browser. (code to read the message here)

what you meant here? how would I write the code to read the pop message?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-18 15:41
When you say "popup" do you mean a Javascript Alert?

If so, in the latest versions of watir-webdriver I believe that's as 
easy as:
puts $browser.alert.text
$browser.alert.close
Posted by Raj pal (arc)
on 2013-03-19 06:01
hi,  i used this code to handle this pop up.

def modalDialog(flg)
  begin
    #Watir::wait($browser.modal_dialog().enabled)
    if(flg ==1)
      puts "modalDialog called"
      errLog=$browser.modal_dialog().td(:class,"PopupMsgTitleMenu").text
      $browser.modal_dialog().table(:id,"OK").click

    else
      $browser.modal_dialog().table(:id,"OK").click
      errLog =""
    end

    return errLog
  rescue Exception => e
    $logger.error " modalDialog - #{e.message}"
  end
end


Thank you
Posted by Raj pal (arc)
on 2013-03-20 11:16
hi,

how can i make my program to wait until it chooses an element from the 
combo box? It's choosing an element from the combo box.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-20 11:40
Do you mean selecting an option within the element's list, or do you 
mean selecting the element itself?
It should wait anyway while selecting something. What is it doing 
instead?
Posted by Raj pal (arc)
on 2013-03-20 13:42
yeah yeah it is waiting, I did some mistake here. Just I realized.
Posted by Raj pal (arc)
on 2013-03-20 15:20
hi,

My browser is loading very slowly, due to that I am having this error,

C:/Ruby187/lib/ruby/gems/1.8/gems/watir-classic-3.2.0/lib/watir-classic/ie-class.rb:606:in
`attach_browser_window': Unable to locate a window with url of
http://localhost/login.do
(Watir::Exception::NoMatchingWindowFoundException)

how could I rectify this?

RAJ
Posted by Raj pal (arc)
on 2013-03-20 15:42
hi

I have another question, Server is overloaded when I automated this web 
page application, if i look into the server, many thread hasn't been 
closed and remains idle,consequently,server gets overloaded very soon, 
Can i make sure that whether all thread are closed once I run the 
program. And I haven't created any Thread program,but it still there is 
a message in server says many thread remains idle. How can i make sure 
threads are closed.?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-20 17:25
Sorry, these are both outside my area of expertise. Maybe some other 
kind soul will be able to help :)
Posted by Raj pal (arc)
on 2013-03-21 05:31
Thank you.
Posted by Raj pal (arc)
on 2013-03-22 08:18
hi,

 puts $browser.windows.count
 $browser.windows.each do |w|
      puts w.title
      w.close
    end

The above code of yours prints the title but it's not closing the
window. You asked me to check whether it is a Javascript window,I
checked that,it is not JavaScript alert,I have used your code of below

puts $browser.alert.text
$browser.alert.close

It's not working since it's not JavaScript window. I told you I started
to use the Model dialog box, But somehow it's having some problem
thereby I couldn't continue with that. So can you give me the solution
why it's not closing the window, and also you have written the code of
below

$browser.windows.last.use do
  $browser. (code to read the message here)
end

Do i need to use like

$browser.windows.last.use do
  $browser.window.text
end

to print the string in the pop up?And the pop up consist of OK and
cancel button, now i need to have a way to press the both the buttons
according to my requirement. Can you give me any solution to resolve
this problem?

And also I can't use the developer tool to view the elements in the pop 
up window, is there any way, can i know the id of the elements in the 
pop up window?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 09:50
Works for me:
__________________________________________
irb(main):001:0> require 'watir-webdriver'
=> true
irb(main):002:0> b = Watir::Browser.new
=> #<Watir::Browser:0x..fb514d2a0 url="about:blank" title="">
irb(main):003:0> b.goto 'google.com'
=> "http://www.google.co.uk/"
#Here I manually opened a new window from that session.
irb(main):004:0> b.windows.count
=> 2
irb(main):005:0> b.windows.each do |w|
irb(main):006:1* puts w.title
irb(main):007:1> end
Google
Gmail: Email from Google
=> [#<Watir::Window:0x..fb49b4dbe located=true>, 
#<Watir::Window:0x..fd178cb4a located=true>]
irb(main):008:0> b.windows.each do |w|
irb(main):009:1* w.close
irb(main):010:1> end
=> [#<Watir::Window:0x..fb49b4dbe located=true>, 
#<Watir::Window:0x..fd178cb4a l
ocated=true>]
#All Windows closed!
__________________________________________

Perhaps there's some Javascript code preventing the window from closing 
until you've made a selection. In which case you'll need to interact 
with the window before closing it. The same principle applies, you just 
transfer control to the popup until you're done with it.

When you use this:

$browser.windows.last.use do

The variable "$browser" will refer to the last window (or whichever one 
you choose in that line) until it reaches "end". It should just be a 
matter of interacting with the selected window in the same way as you 
normally would.
Posted by Raj pal (arc)
on 2013-03-22 11:04
Ok,

how can I use choose the last window

for an instance you have given this code

"$browser.windows.last.use do"

Now how can i use this code to close the window?

I used like $browser.windows.last.close. But it is not working.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 11:11
Does it work with just a blank new window?

irb(main):106:0> require 'watir-webdriver'
=> true
irb(main):107:0> b = Watir::Browser.new
=> #<Watir::Browser:0x..fcee16076 url="about:blank" title="">
irb(main):108:0> b.windows.last.close
=> #<Watir::Window:0x..fad045588 located=true>

The above worked perfectly for me.

If that doesn't work for you, what gem version & browser version are you 
working with?
Posted by Raj pal (arc)
on 2013-03-22 12:49
hi,

I tried in the way you tried (i.e)through irb, I met up with pop 
problem, and then I open many browser and then I tried to close using 
this comment
b.windows.last.close,all other windows are closed expect the one which
consist of pop up. What could be the reason?

And I executed your above code, when I use watir-webdriver it opens the
Firebox and when i use watir it opens the internet explorer, and it's
closing also. But it is not closing when the window is having a pop up.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 13:16
Raj pal wrote in post #1102781:
> all other windows are closed expect the one which
> consist of pop up.
>
> it is not closing when the window is having a pop up.

Then it's something to do with the way the popup is created. I'd guess 
that the popup doesn't have watir attached to it.

If you don't have watir's control of the popup, then you have a few 
options.

For IE you can use the COM object, or just use Watir to re-attach to it.

For Firefox you can either target the window, using the various ways of 
dealing with a window regardless of what it contains; or you could use 
the process library to kill the underlying process once you've finished 
with the browser, thereby terminating all windows.
These approaches would also work with IE, but they should be second 
choice to using its COM object.
Posted by Raj pal (arc)
on 2013-03-22 13:24
I am using IE so i will try to reattach and also Can I read the message
from the pop up?if so, what code do I need to return?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 13:55
The way you read the message depends on exactly what the popup contains. 
Once you attach to it it's just the same as a normal window, so treat it 
as such.
Posted by Raj pal (arc)
on 2013-03-22 13:57
But how can I attach the pop ? why i am asking is, when I attach the 
window  I use this code

b= Watir::IE.attach(:url,"www.google.com")

But in the case of pop up I am not aware of url, If so, how would I 
attach the pop up?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 16:09
In the version of Watir I have, you can just keep iterating via index. 
Something like this:

100.times { |t|
  puts ( Watir::Browser.attach( :index, t ) ).title rescue break
}
Posted by Raj pal (arc)
on 2013-03-22 16:59
hi, I am using that model dialog box again where again I am having this
attaching problem, I have written your code of below, It's perfectly
working, thank you very much, But I couldn't able to understand how this
code is working, each and every time you are passing value through 1 to
100. But what is exactly happening when it encounters
Watir::Browser.attach(:index, 1) or Watir::Browser.attach( :index, 2 ) )
? could you explain me?

100.times { |t|
  puts ( Watir::Browser.attach( :index, t ) ).title rescue break
}

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-22 17:11
This is how it works if you have 2 IE windows open:

______________________
do...

Watir::Browser.attach( :index, 0 ) #Grab the first window

puts .title #Output the window title

loop #Onward to index 1!

Watir::Browser.attach( :index, 1 ) #Grab the second window

puts .title #Output the window title

loop #Sally forth to index 2!

Watir::Browser.attach( :index, 2 ) #Oh no, there's no 3rd window!

rescue #Catch the error caused by not finding a window

break #Exit the loop

end
______________________

And that's how it works.
It's not an ideal solution as you will get a delay before timing out on 
grabbing the non-existent upper indexed window, but given that you don't 
know how many windows are open, that's the best I could come up with on 
short notice.
Posted by Raj pal (arc)
on 2013-03-22 17:14
That's excellent I understood.
Posted by Raj pal (arc)
on 2013-03-25 07:41
hi Joel Pearson,

100.times { |t|
  puts ( Watir::Browser.attach( :index, t ) ).title rescue break
}

This code fails to execute because you haven't return the browser 
instance, But now I modified your code like given below

100.times do |t|
  $browser=Watir::Browser.attach( :index, t )  rescue break
end

This code works. Why your code is not working? did you meant to say 
include something with your code thereby it will work?Did I miss 
anything in your code?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-25 12:12
Works for me:

irb(main):001:0> require 'watir'
=> true
irb(main):002:0> 100.times { |t|
<atir::Browser.attach( :index, t ) ).title rescue break
irb(main):004:1> }
Google
Gmail: Email from Google
=> nil
irb(main):005:0>

All you're doing with your code there is constantly reassigning the 
variable $browser but not doing anything with it. The code you posted 
doesn't "work" in the same sense as the example I gave.
The reason that I don't use assignation is because I'm only doing 1 
thing inside the loop, I don't need to use a variable for that.
If you're experiencing issues then could be down to Ruby or Watir 
versions, IE add-ons, typos in the code, or all sorts of different 
possibilities.
Posted by Raj pal (arc)
on 2013-03-25 15:14
Ok, Since I am using Ruby 1.8.7, this problem might have occured.

Thank you.

RAJ
Posted by tamouse mailing lists (Guest)
on 2013-03-25 19:49
(Received via mailing list)
On Mon, Mar 25, 2013 at 6:12 AM, Joel Pearson <lists@ruby-forum.com> 
wrote:
> assignation

So where my head is at.....
 :)

(I know it means assignment as well.)
Posted by Raj pal (arc)
on 2013-03-26 05:56
No,No Just I told you.

RAJ
Posted by Raj pal (arc)
on 2013-03-26 07:56
hi,

Look at the below code,

<table class='panel'>
<tr>
    <td title="hi">
    <td title="hello">
</table>

Now from the above table I need to print the title using ruby code? How
can i write the code? Because If we want to take something from the
column then we can write the code like
$browser.table().td(:title,'hi').text

But I want the title to be printed,Is it possible?

And currently i am using this code to print the value of inner text,

iActual = 
tempHTML.xpath(".//div[@id='Dashboard']//div[@id='DashboardDetails']//table[@class='Panel']//tbody//tr[3]//td[4]//label").inner_text

So i able to print the title from td , i will not be in need the above 
code.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-26 09:30
This will flash every cell with a title in the first table it finds (for 
some reason passing a single dot makes it include ones with no title). 
Just deconstruct it and rebuild to do what you want with it.

b.tables.first.tds(:title, /../).each &:flash
Posted by Raj pal (arc)
on 2013-03-26 15:23
OK, Thank you.

consider this code,

$browser.text_field(:id,'Date').set('raja')
puts 'raja'
popupMsg=modalDialog('Ok')

hi look at the above code, I am setting the wrong string 'raja' in the 
date field, so it gives the pop up, Now i have written the pop up 
handler below "modelDialog", Now the problem is, as soon as pop comes 
next line is not executed, in this case puts 'raja' is not executed, 
that means control is not coming to the next line, so it is not reaching 
the function call of modalDialog('Ok'), How can i transfer the control 
to the next line while pop is visible?
Posted by Raj pal (arc)
on 2013-03-26 15:37
hi I have another question, what is the difference between click and 
click_no_wait?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-26 15:38
If you mean that there's an alert appearing immediately after you set 
the text field, you'd need to do something like this:

$browser.text_field(:id,'Date').set('raja')
$browser.alert.close
puts 'raja'
Posted by Raj pal (arc)
on 2013-03-27 10:44
Thank you.

hi,

b.tables.first.tds(:title, /../).each &:flash

Can you re-define this above line for textfields? for an example i want 
to reflect the title in username and password for Gmail.Is it possible?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-27 11:36
In the case of gmail, this would do it.
b.text_fields.each { |t| t.parent.labels.first.flash }
Posted by Raj pal (arc)
on 2013-03-27 12:37
b.text_fields.each { |t| puts t.parent.labels.first.text }(I made it as 
text to print the value)

This above code perfectly working for Gmail, But for some screens, it 
says that
" undefined method `text' for nil:NilClass", what is the problem here?

RAJ
Posted by Raj pal (arc)
on 2013-03-27 12:57
hi,
$browser.link(:id,'click').when_present.click

Here we are giving when_present to make sure that link is available in 
the browser. Now, sometimes when the combobox delays to populate the 
values, in such cases my program clicks the combo box and checks the 
element and it found nothing, but if it had pressed after few seconds 
elements would have been found. Is there any function like when_present 
available for combo to check when elements gets populated or not?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-27 13:09
Regarding waiting:
http://watirwebdriver.com/waiting/

Watir::Wait.until { ( Code to check Combobox has your value... ) }

Regarding NilClass, the code I gave is assuming that the text field is 
inside a label, like in the gmail page. If this is not the case, you 
will get nil for the parent's label. You need to adapt the code to the 
structure of your page.
Posted by Raj pal (arc)
on 2013-03-27 13:20
Hi,

It's working fine, I have given like

Watir::Wait.until{$b.select_list(:id,'hi').select('hello')}

Now it's working fine.

Thank you.

RAJ
Posted by Raj pal (arc)
on 2013-03-27 14:31
Regarding NilClass, the code I gave is assuming that the text field is
inside a label, like in the gmail page. If this is not the case, you
will get nil for the parent's label. You need to adapt the code to the
structure of your page.

ok

RAJ
Posted by Raj pal (arc)
on 2013-03-28 08:02
hi,

I redefined your code according to my necessity,

[:text_fields, :select_lists, :checkboxes].each do |type|
  $browser.send(type).each do |i|
    if type.to_s[0..-2].eql?('text_field')
      puts "$browser.text_field(:id,'#{i.id}').set('rajagopalan')"
    elsif type.to_s[0..-2].eql?('select_list')
      puts "$browser.select_list(:id,'#{i.id}').select('RAJ')"
    elsif type.to_s[0..-3].eql?('checkbox')
      puts "$browser.checkbox(:id,'#{i.id}').set"
    end
  end
end

Now, it actually takes all the text box first and then it goes to the 
select_list and then it goes to the checkbox. But I want to be an order 
the way they are situated in screen, Is it possible to get like that?

RAJ
Posted by Raj pal (arc)
on 2013-03-28 08:27
For textbox we are using text_field, what is the corresponding one for 
textarea?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-28 09:48
> I want to be an order
> the way they are situated in screen, Is it possible to get like that?
>
> RAJ

There are some ideas on sorting IDs here, you should be able to collect 
the objects using the loop and then sort them using one of these sorting 
methods.
http://stackoverflow.com/questions/830155/nokogiri...

textbox and textarea are both covered by text_field. If you specifically 
want a textarea, use textarea.
Posted by Raj pal (arc)
on 2013-03-28 09:56
No no i am not asking about the sorted one, But the order the objects 
are placed in the webpage,

For an example,

textbox(id : a) combobox(id :z) textbox(id : b)

now it has to print the id
a
z
b.

But what it actually doing is,it print the textbox id first,and then it 
print the combobox id like
a
b
z

But I want the first order
azb.

Can you bring this?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-28 10:07
As I said,

Collect the objects in the initial loop.

Sort the collection of objects based on their position in the page using 
one of the methods given in the link, or create your own approach using 
the ideas on that page.

Then iterate through your sorted collection, happy in the knowledge that 
they are now in page order.
Posted by Raj pal (arc)
on 2013-03-28 11:32
OK
THANKS
Posted by Raj pal (arc)
on 2013-03-29 12:04
Hi, Have you ever used the test-factory? If so, can you tell me how it 
helps to our testing?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-03-29 17:57
Never used it. It looks interesting though, I'll have a look.

At a glance I'd say that if you learn how to use it you'll save yourself 
some time writing test scripts.
Posted by unknown (Guest)
on 2013-03-29 23:37
(Received via mailing list)
Am 29.03.2013 12:04, schrieb Raj pal:
> Hi, Have you ever used the test-factory? If so, can you tell me how it
> helps to our testing?
>
> RAJ
>

Please start a different thread for questions that are not related.
Posted by Raj pal (arc)
on 2013-03-30 16:30
Never used it. It looks interesting though, I'll have a look.

At a glance I'd say that if you learn how to use it you'll save yourself
some time writing test scripts.

Ok Thank you, and I will start a new thread.

RAJ
Posted by Raj pal (arc)
on 2013-04-03 14:30
hi,

Ruby has any Date validation function? Or do you have any function for 
date validation?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-03 16:16
I don't know exactly what you mean by date validation, but Ruby has 
this:

require 'date'
Date.today
Date.new( 2013, 4, 3 )

etcetera...
Posted by Raj pal (arc)
on 2013-04-04 11:27
hi,

what I meant was, in the date field, I should not enter "raja", if i 
enter it has to print on the console ,it's not valid date.

RAJ
Posted by Raj pal (arc)
on 2013-04-04 11:31
hi,

the gmail,

If i have to automate the gmail account, then I will write the code like

begin
$browser.text_field(:id,'Gmail').set('raja')
rescue =>e
puts e.message
puts e.backtrace
end

begin
$browser.text_field(:id,'password').set('raja')
rescue =>e
puts e.message
puts e.backtrace
end

Likewise, if i have to automate 1000field, then it would 4000 lines of 
code, Is there any way could I able to put into the loop. My problem is, 
i couldn't able to synchronize the id and value.Do you have any solution 
for this?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 11:47
It depends whether you mean a Date object or a string in date format. If 
you want to validate I tend to use Regexp for that sort of thing.

Here's a Regexp example which covers a variety of date-string formats:

http://www.rubular.com/r/SXfDou7sQs

use like this:

if my_date !~ /\d{1,2}[\-\/]\d{1,2}[\-\/]\d{4}/
  fail TypeError, 'Invalid date: ' + my_date
end


For a Date object it's just:

my_date.is_a?( Date )
Posted by Raj pal (arc)
on 2013-04-04 11:52
Ok thank you.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 11:58
Raj pal wrote in post #1104349:
> if i have to automate 1000field, then it would 4000 lines of
> code, Is there any way could I able to put into the loop. My problem is,
> i couldn't able to synchronize the id and value.Do you have any solution
> for this?

Something like this should work.

my_hash = {
  User1: 'Pass1',
  User2: 'Pass2'
}

my_hash.each do |username, password|
  $browser.text_field(:id,'Email').set(username.to_s)
  $browser.text_field(:id,'Passwd').set(password)
  #Other stuff here...
end
Posted by Raj pal (arc)
on 2013-04-04 12:28
OK thank you.

RAJ
Posted by Raj pal (arc)
on 2013-04-04 12:34
hi Is there any way can I focus on to the text box through the program, 
More closely put,I have to bring cursor pointer to the specific textbox.
Posted by Joel Pearson (virtuoso)
on 2013-04-04 12:47
Can you explain what you're trying to achieve by this? It's sometimes 
convenient for Watir not to steal focus, and I don't think this is how 
it operates; so is this your end-goal, or a stepping stone towards 
something else?
Posted by Raj pal (arc)
on 2013-04-04 13:08
i have written a code to dynamically generate the id,but i don't have to 
make that sychronise into the column in the spread sheet. so I decided 
to enter the value manually. So if I know the corresponding textbox, 
then i will enter the value manually and then full code will be 
generated,

look at this example,
b.text_field(:id,'generated dynamically').set(entered manually)

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 13:20
how about:

b.text_field(:id,from spreadsheet).set(from spreadsheet)

or

b.text_field(:id,from hash).set(from hash)

or

b.text_field(:id,from array).set(from array)
Posted by Raj pal (arc)
on 2013-04-04 13:22
this is interesting,

b.text_field(:id,from spreadsheet).set(from spreadsheet)

But how do you know "from spreadsheet"part from spreadsheet? because id 
is the screen dependent,isn't it so?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 13:25
On gmail's login page, the id is always the same.

If you're using a site which doesn't keep the same ID, you'll need to 
find something else which is immutable (even a parent, child, or 
adjacent element) and use that as the identifier.
Posted by Raj pal (arc)
on 2013-04-04 14:18
But my problem is little differs. Here ids are fixed, but I can't create 
a sheet which is coherent to the field in the text box, so I couldn't 
put it in a loop,

for an example 10 textboxes are there but I may match first textbox has 
to be filled with the detail of first column in the spread sheet, but I 
can't achieve this, because Order varies.
Posted by Joel Pearson (virtuoso)
on 2013-04-04 14:32
How do you, doing it manually, identify where each value goes?
Posted by Raj pal (arc)
on 2013-04-04 15:05
Look at this code

[:text_fields, :select_lists, :checkboxes].each do |type|
  $browser.send(type).each do |i|
    if type.to_s[0..-2].eql?('text_field')
      puts 'enter your name'
      p=gets.chomp
      puts "begin"
      puts "$browser.text_field(:id,'#{i.id}').set(#{p})"
      puts "rescue =>e"
      puts "end"
    end
  end
end

I hope now you can understand what I am doing here.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 15:14
Well, this:
if type.to_s[0..-2].eql?('text_field')

negates this:
[:text_fields, :select_lists, :checkboxes].each do |type|

This whole section appears to accomplish nothing other than outputting 
text:
      puts "begin"
      puts "$browser.text_field(:id,'#{i.id}').set(#{p})"
      puts "rescue =>e"
      puts "end"

And you didn't answer my question. How do you know where a given value 
goes when you look at the page?

What is your ultimate goal? You seem to be taking a rather convoluted 
path there.
Posted by Raj pal (arc)
on 2013-04-04 15:39
My aim is to produce that four lines code for all fields.

How do you know where a given value
goes when you look at the page?
I don't know that's what I am stopping as soon as my code approch field 
and waiting for input from me, and I will see what text box is this and 
i will enter that value through key board and that value will be 
gathered into a variable "p" and then that will be assigned into the 
code.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-04 16:08
Raj pal wrote in post #1104394:
> My aim is to produce that four lines code for all fields.

That sounds like a very repetitive way of going about this. In general, 
code should not be repeated.

If the only thing that changes is the ID, then you should focus your 
efforts on finding something which doesn't change, or establishing a 
pattern of behaviour so you can write a method which handles this rather 
than writing out an individual line of code for each case.
Posted by Raj pal (arc)
on 2013-04-04 16:26
OK
Posted by Raj pal (arc)
on 2013-04-05 08:44
sheet.each do |record|
if (record['DataSet'] == dataSet)
    return record
end
end

hi,
    I am trying to find the data with hash, can you re-write the 
statement without any loop using any of the predefined method in ruby?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 10:00
I don't know what your sheet looks like, what data you need to return, 
or what gem you're using to access the sheet.
In general a hash could contain all the relevant data without having to 
pick and choose, possibly in a nested hash.

Since I don't know what your data looks like I'll give you a generic 
example.

h = {}

sheet.each do |row|

  #Create a new nested hash with the key from the first column
  h[ row[0].value ] ||= {}

  #Reference it so we don't have to keep writing that line
  ref = h[ row[0].value ]

  #Fill in other details
  ref[ 'password' ] = row[1].value
  ref[ 'data1' ] = row[2].value
  ref[ 'data2' ] = row[3].value

end
Posted by Raj pal (arc)
on 2013-04-05 10:10
i think you did not understand my question here.

For an example,

sheet

name   age  class
raj    21   first
gopal  22   second

now,

 Now sheet is the array but the element in the array is hash.

sheet.each do |element|
   if element['name']='gopal'
        return element
   end
end

so my aim is to get the record which consist of the name gopal. Now I am 
using loop for this as i have written, my question is, can able to 
access that element without loop?do you know any predefined function for 
that?

Another question, we can use the key to find the element in the hash, 
but do we find the key using value? one of the way is,

raja.each do |key,value|
if value=='hi'
return key
end
end
Is there any other way ? Is there any predefined function?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 10:31
There are many ways to do this. You should go through some tutorials on
using Arrays and Hashes.

In an Array containing Hashes:
sheet.select { |row| row['name']=='gopal' }.first

In a Hash:
raja.index 'hi'
Posted by Raj pal (arc)
on 2013-04-05 11:40
Yes thank you, this is what I expected.

Another question,

I am using ADODBconnector for exatracting the data from spread sheet, 
here I am getting an error.

14:56:56] [ERROR] : Open
    OLE error code:80004005 in Microsoft JET Database Engine
      The connection for viewing your linked Microsoft Excel worksheet 
was lost.
    HRESULT error code:0x80020009

it shows the error in the below line.

 def query(sql)
    recordset = WIN32OLE.new('ADODB.Recordset')
---------->    recordset.Open(sql, connection)#this line it indicates.
    @data = recordset.GetRows.transpose
    @fields = []
    recordset.Fields.each do |field|
      @fields << field.Name
    end
  end

Do you have any idea ?
Posted by Joel Pearson (virtuoso)
on 2013-04-05 11:45
I didn't know the Jet engine was still in use, thought that had died 
out.

I'd guess that your connection or sql string has an error in. This is 
really more of a StackOverflow type of question.

One other possibility is that you might still have a connection active 
from a previous attempt. Have you tried turning it off and on again?
Posted by Raj pal (arc)
on 2013-04-05 12:13
hi,

I have opened the connection like below

$dbConnector = ADODBConnector.new(dataFile)
      $dbConnector.openConnection()

How do I ensure that connection is active?

I working in multilple project and I maintain all project in same 
eclipse it's working in other project, but not here.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 12:20
Again, this is veering away from Ruby into other territory.
If you have another working project then check the differences. Often 
it's a missed character in your connection string.

If you want to see the options available with the object ADODBConnector, 
then try this:
$dbConnector.ole_methods
Posted by Raj pal (arc)
on 2013-04-05 12:25
Ok thank  you.

RAJ
Posted by Raj pal (arc)
on 2013-04-05 12:57
hi,

In the below line

sheet.select { |row| row['name']=='gopal' }.first

what is the use of 'first'?

RAJ
Posted by Raj pal (arc)
on 2013-04-05 13:09
hi I used your code,

my_hash = {
  User1=> 'Pass1',
  User2=> 'Pass2'
}

my_hash.each do |username, password|
  $browser.text_field(:id,'Email').set(username.to_s)
  $browser.text_field(:id,'Passwd').set(password)
  #Other stuff here...
end

First of all it throws the error in User1:pass1 and then I changed into 
User1=>'Pass1' Now it's throw an error
C:/work1/LnTIDITAutomation/Main/hi.rb:48: uninitialized constant User1 
(NameError)

and then I changed this into
my_hash = {
   User1=> 'Pass1'
   User2=> 'Pass2'
}

Now it is applying. But I want to know whether it's working in higher 
version of ruby, because you might have applied the code

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 13:12
Select returns an array, so "first" just picks the top one out for you. 
Your code returns a single result as well so I thought this to be the 
most suitable option.
Posted by Raj pal (arc)
on 2013-04-05 13:12
Ok I understand.
RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 13:17
Raj pal wrote in post #1104520:
> hi I used your code,
>
> my_hash = {
>   User1=> 'Pass1',
>   User2=> 'Pass2'
> }
>

That's not my code, this is:

my_hash = {
  User1: 'Pass1',
  User2: 'Pass2'
}

This is equivalent to:

my_hash = {
  :User1 => 'Pass1',
  :User2 => 'Pass2'
}

The reason I used #to_s on the username later was because it is a 
symbol, and I used the shortcut notation when creating the hash. The 
values themselves are of course placeholders. You can use whatever 
content is most suitable.

User1 is a constant (a type of variable), and an uninitialised one in 
your case. This is the reason for the error.

Are you sure you're not out of your depth? After all, you're trying to 
do advanced interactions without being able to work out what lines like 
"uninitialized constant User1" mean.
Perhaps you should do some basic tutorials before working on projects 
this complex.
Posted by Raj pal (arc)
on 2013-04-05 13:30
I am working in a project, and also I am styding while something new is
needed, I knew of the problem, why i asked was,I don't have a higher
version, that's reason i suspect this may be syntax in the higher
version.

RAJ
Posted by Raj pal (arc)
on 2013-04-05 13:31
I have another question,

h = { "a" => 100, "b" => 200, "c" => 300 }
a=h.select {|k,v| k > "a"}

In the ruby documention they say that it returns hash but it actually
returns the array,what is the reason for this?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 13:50
Enumerable#select is what is being used. This returns an array (a 
collection).
Posted by Raj pal (arc)
on 2013-04-05 13:54
select {|key, value| block} → a_hash click to toggle source
select → an_enumerator
Returns a new hash consisting of entries for which the block returns 
true.

If no block is given, an enumerator is returned instead.

h = { "a" => 100, "b" => 200, "c" => 300 }
h.select {|k,v| k > "a"}  #=> {"b" => 200, "c" => 300}
h.select {|k,v| v < 200}  #=> {"a" => 100}

This is from Ruby Documentation, See this is returning the Hash,not 
array,isn't it?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 14:02
In 1.8.7:
select {|key, value| block} => array

In 1.9.3 (which I'm currently using), select does indeed return a Hash.
Posted by Raj pal (arc)
on 2013-04-05 14:06
Ok got it.
Posted by Raj pal (arc)
on 2013-04-05 14:08
hi,

If i jump into 1.9.3 ,do i need to face lot of change in my existing 
project. My existing project is about automating screen which you might 
have known since i have raised lot of question regarding to that.

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-05 14:31
You can run side-by-side installs. I think I've heard RVM mentioned in 
relation to that.

If I ever get time I'm going to migrate onto Ruby 2.0, so you might want 
to look into doing that directly rather than going via 1.9.3 first.

As far as I know Ruby versions are mostly backward compatible regarding 
code, apart from the odd hiccup like the behaviour of Hash#select / 
Enumerable#select. Operating with multiple versions for a while seems 
the best way to manage the upgrade and give time to smooth out any 
inconsistency.
Posted by Raj pal (arc)
on 2013-04-05 15:42
Yes that seems to be a good idea if i have more than one version. And 
tell me about Ruby 2.0 if you are to migrate to that.

RAJ
Posted by Raj pal (arc)
on 2013-04-06 11:19
hi, Is there any way can I able to highlight the selectbox?Or can i 
click the select box so that it would appear with drop down list.

RAJ
Posted by Raj pal (arc)
on 2013-04-06 11:48
Can you tell me how to choose the first element from select_list?

RAJ
Posted by Raj pal (arc)
on 2013-04-08 07:22
hi,

Include this question with the above one, when watir places the value in 
the text box, it moves the screen towards upwords, can I stop this 
screen movement?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-10 21:01
I think clicking a select box would probably cause the list to appear. 
Try it and see.

If you look at the underlying HTML you'll often find that a select_list 
has values hidden inside the list which are available as an alternative 
selection method (select_value).

I think if you want to select an option by its place in the list 
(dangerous and prone to errors if the list changes) then you can use 
".options.map(&:text)" to get an array which contains all the options, 
then pick whichever one you want from that list.
Posted by Joel Pearson (virtuoso)
on 2013-04-10 21:04
Raj pal wrote in post #1104861:
> Include this question with the above one, when watir places the value in
> the text box, it moves the screen towards upwords, can I stop this
> screen movement?

I haven't observed this behaviour, however I should think if it does 
this then the solution would be to interact with another element which 
makes the screen scroll back down, or interact with the element directly 
using a bit of JavaScript.
If you give me the link (or the HTML), and the relevant code, then I can 
experiment and see what I can come up with.
Posted by Raj pal (arc)
on 2013-04-12 07:46
Ok thank you, And that url is available in internal server,it's not 
available outside.

RAJ
Posted by Raj pal (arc)
on 2013-04-12 07:48
hi,
I have a question,

$browser.elements.each do |t|
puts t
end

Is there anything wrong in the above code, it's giving the error,

" `each_element': undefined method `each' for nil:NilClass 
(NoMethodError)"

Can't apply each method for elements?

RAJ
Posted by unknown (Guest)
on 2013-04-12 07:55
(Received via mailing list)
Am 12.04.2013 07:48, schrieb Raj pal:
> (NoMethodError)"
>
> Can't apply each method for elements?
>
> RAJ

Try

     p $browser.elements
or  puts $browser.elements.inspect

and you will see what the problem is.
Posted by Raj pal (arc)
on 2013-04-12 08:27
when i try to print the elements as you have explained, it throws the 
same error,

`each_element': undefined method `each' for nil:NilClass (NoMethodError)

I am trying for Gmail username and password, So can you try to with 
Gmail and tell me whether it's working for you or not?

RAJ
Posted by Raj pal (arc)
on 2013-04-12 13:01
hi,

do we have anything equivalent to static keyword in C? My motto is value
has to be preserved even after the function return, Global variable is
one of the way to do this, But I guess something equivalent to static
keyword would be a better solution.

RAJ
Posted by unknown (Guest)
on 2013-04-12 15:46
(Received via mailing list)
Am 12.04.2013 08:27, schrieb Raj pal:
> when i try to print the elements as you have explained, it throws the
> same error,
>
> `each_element': undefined method `each' for nil:NilClass (NoMethodError)

That's strange because in my example `each` has not been called
at all...

Anyway: What the error message is trying to convey to you is
that you are trying to call `each` for an object that is nil:

$ irb
1.9.3p392 :001 > a = nil
  => nil
1.9.3p392 :002 > a.each {|element| puts element }
NoMethodError: undefined method `each' for nil:NilClass

So, `$browser.elements` seems to be nil for some reason.
Posted by unknown (Guest)
on 2013-04-12 15:47
(Received via mailing list)
Am 12.04.2013 13:01, schrieb Raj pal:
> hi,
>
> do we have anything equivalent to static keyword in C?
>
> RAJ

Please start a new thread for unrelated questions.
Posted by Raj pal (arc)
on 2013-04-16 13:26
$ irb
1.9.3p392 :001 > a = nil
  => nil
1.9.3p392 :002 > a.each {|element| puts element }
NoMethodError: undefined method `each' for nil:NilClass

So, `$browser.elements` seems to be nil for some reason.

OK
Posted by Raj pal (arc)
on 2013-04-17 11:51
can you tell me what is the difference between
a=[2,3,3,5]
a=Hash[*b]# It's converting into hash
a=Hash[b]#it's converting if a consist of any array

What is the job of "*" here?

And also I would like to know what is the difference does it make for

def hi(*h)
end
def hi(h)
end

RAJ
Posted by Julian Leviston (Guest)
on 2013-04-17 13:08
(Received via mailing list)
* here converts an array to a list of arguments.

so,

in:

args_ary = [1,2]
hash = Hash[*args_ary]

it's the same as

hash = Hash[1,2]

where as
args_ary = [1,2]
hash = Hash[args_ary]

is the same as

hash=Hash[[1,2]]

... which will give you a bunch of warnings and just set hash to an 
empty Hash.

J
Posted by Joel Pearson (virtuoso)
on 2013-04-17 13:48
The word you're looking for is "splat". I found this link quite useful 
when I discovered them: 
http://endofline.wordpress.com/2011/01/21/the-stra...
Posted by Raj pal (arc)
on 2013-04-18 08:26
hi Julian Leviston

Thank you .I understood what you meant.

hi Joel Pearson

Yes this is what I expected.thank you.
Posted by Raj pal (arc)
on 2013-04-24 07:33
hi,

Class.class==Class

Every class we create is an object of a class Class, but how can Class 
itself object of it's own? Can we create such a class?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-24 10:15
Class is part of Ruby's core. Any class you make will be an instance of 
Class. As far as I know you could modify class Class but not overwrite 
it, although I'd consider that rather dangerous since virtually 
everything inherits from Class.

This might help you understand it:
http://stackoverflow.com/questions/1219691/why-obj...
Posted by Raj pal (arc)
on 2013-04-24 10:59
Yep this is ok, this i understood. My main focus is, how can Class be 
instance of it's own? Class.class=Class.
Can we able to create a class like that? Instance is only possible after 
declaration of class, But here Class is an instance of Class as well. 
How it's possible?

RAJ
Posted by Joel Pearson (virtuoso)
on 2013-04-24 11:19
Because the implementation is written in C, not Ruby. Ruby works through 
an interpreter, and the circular reference there is part of the 
framework that the language works through. I don't think it's something 
you can replicate from within Ruby, only by writing your own 
interpreter. Why would you need to, anyway?
Posted by Raj pal (arc)
on 2013-04-24 11:29
Not for my work, Just to know how that is possible. Because i haven't 
seen such an implemention so far.
Posted by Raj pal (arc)
on 2013-04-24 12:59
I understood what you meant.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.