Web Application Testing in Ruby: What is stub?
It's a document released along with the product which explains about the product. It also contains about the bugs that are in deferred status.
This will help you for Automation Software Testing with Watir Tool(Ruby)
Labels
Showing posts with label ruby scripting. Show all posts
Showing posts with label ruby scripting. Show all posts
Monday, February 21, 2011
What is internationalization Testing?
Web Application Testing in Ruby: What is stub?
Software Internationalization is process of developing software products independent from cultural norms, language or other specific attributes of a market
Software Internationalization is process of developing software products independent from cultural norms, language or other specific attributes of a market
What is stub?
Web Application Testing in Ruby: What is bidirectional traceability?
Stub is a dummy program or component, the code is not ready for testing, it's used for testing...that means, in a project if there are 4 modules and last is remaining and there is no time then we will use dummy program to complete that fourth module and we will run whole 4 modules also. The dummy program is also known as stub
Stub is a dummy program or component, the code is not ready for testing, it's used for testing...that means, in a project if there are 4 modules and last is remaining and there is no time then we will use dummy program to complete that fourth module and we will run whole 4 modules also. The dummy program is also known as stub
What is bidirectional traceability?
Web Application Testing in Ruby: What is agile testing?
What is bidirectional traceability?
Bidirectional traceability needs to be implemented both forward and backward (i.e., from requirements to end products and from end product back to requirements).
When the requirements are managed well, traceability can be established from the source requirement to its lower level requirements and from the lower level requirements back to their source. Such bidirectional traceability helps determine that all source requirements have been completely addressed and that all lower level requirements can be traced to a valid source.
What is bidirectional traceability?
Bidirectional traceability needs to be implemented both forward and backward (i.e., from requirements to end products and from end product back to requirements).
When the requirements are managed well, traceability can be established from the source requirement to its lower level requirements and from the lower level requirements back to their source. Such bidirectional traceability helps determine that all source requirements have been completely addressed and that all lower level requirements can be traced to a valid source.
What is agile testing?
Web Application Testing in Ruby: What is Recovery testing?
What is agile testing?
What is agile testing?
Agile testing is used whenever customer requirements are changing dynamically
If we have no SRS, BRS but we have test cases does you execute the test cases blindly or do you follow any other process.
Test case would have detail steps of what the application is supposed to do.
1) Functionality of application.
2) In addition you can refer to Backend, is mean look into the Database. To gain more knowledge of the application.
What is agile testing?
What is agile testing?
Agile testing is used whenever customer requirements are changing dynamically
If we have no SRS, BRS but we have test cases does you execute the test cases blindly or do you follow any other process.
Test case would have detail steps of what the application is supposed to do.
1) Functionality of application.
2) In addition you can refer to Backend, is mean look into the Database. To gain more knowledge of the application.
What is Recovery testing?
Web Application Testing in Ruby: What is Recovery testing?
Recovery Testing is the testing which is used to find how
well the application will get recover from crashes.
Recovery Testing is the testing which is used to find how
well the application will get recover from crashes.
What is Recovery testing?
Evaluates the contigency features are built in the
application for handling interruptions and to return to
specific check points. This test also assures that disaster
recovery if possible.
application for handling interruptions and to return to
specific check points. This test also assures that disaster
recovery if possible.
Wednesday, February 9, 2011
How to wait in Watir?
Watir does not wait for new page to load, except:
when you "attach" to an existing
window
use the "click" method
"set" or "clear" radio buttons or checkboxes
when you select an item in a select list
when you clear a text field
when you "goto" a new page
when you "submit" a form
when you "back", "forward" or "refresh" the browser
when you "fire_event" on any element
ie = Watir::IE.attach(:title, 'My Window')
# no need to wait, ie.wait called implicitly
ie.link(:id, 'mylink').click
# no need to wait, ie.wait called implicitly
assert(ie.link(:id, 'mynewlink).exists?)
"Watir is deterministic. Watir does not wait X seconds. It waits until the page is loaded. Period."
when you "attach" to an existing
window
use the "click" method
"set" or "clear" radio buttons or checkboxes
when you select an item in a select list
when you clear a text field
when you "goto" a new page
when you "submit" a form
when you "back", "forward" or "refresh" the browser
when you "fire_event" on any element
ie = Watir::IE.attach(:title, 'My Window')
# no need to wait, ie.wait called implicitly
ie.link(:id, 'mylink').click
# no need to wait, ie.wait called implicitly
assert(ie.link(:id, 'mynewlink).exists?)
"Watir is deterministic. Watir does not wait X seconds. It waits until the page is loaded. Period."
How do I use Ruby for shell scripting?
Dir['*.rb'] #basic globs
Dir['**/*.rb'] #** == any depth of directory, including current dir.
#=> array of relative names
File.expand_path('~/file.txt') #=> "/User/mat/file.txt"
File.dirname('dir/file.txt') #=> 'dir'
File.basename('dir/file.txt') #=> 'file.txt'
File.join('a', 'bunch', 'of', 'strings') #=> 'a/bunch/of/strings'
__FILE__ #=> the name of the current file
Also useful from the stdlib is FileUtils
require 'fileutils' #I know, no underscore is not ruby-like
include FileUtils
# Gives you access (without prepending by 'FileUtils.') to
cd(dir, options)
cd(dir, options) {|dir| .... }
pwd()
mkdir(dir, options)
mkdir(list, options)
mkdir_p(dir, options)
mkdir_p(list, options)
rmdir(dir, options)
rmdir(list, options)
ln(old, new, options)
ln(list, destdir, options)
ln_s(old, new, options)
ln_s(list, destdir, options)
ln_sf(src, dest, options)
cp(src, dest, options)
cp(list, dir, options)
cp_r(src, dest, options)
cp_r(list, dir, options)
mv(src, dest, options)
mv(list, dir, options)
rm(list, options)
rm_r(list, options)
rm_rf(list, options)
install(src, dest, mode =, options)
chmod(mode, list, options)
chmod_R(mode, list, options)
chown(user, group, list, options)
chown_R(user, group, list, options)
touch(list, options)
Dir['**/*.rb'] #** == any depth of directory, including current dir.
#=> array of relative names
File.expand_path('~/file.txt') #=> "/User/mat/file.txt"
File.dirname('dir/file.txt') #=> 'dir'
File.basename('dir/file.txt') #=> 'file.txt'
File.join('a', 'bunch', 'of', 'strings') #=> 'a/bunch/of/strings'
__FILE__ #=> the name of the current file
Also useful from the stdlib is FileUtils
require 'fileutils' #I know, no underscore is not ruby-like
include FileUtils
# Gives you access (without prepending by 'FileUtils.') to
cd(dir, options)
cd(dir, options) {|dir| .... }
pwd()
mkdir(dir, options)
mkdir(list, options)
mkdir_p(dir, options)
mkdir_p(list, options)
rmdir(dir, options)
rmdir(list, options)
ln(old, new, options)
ln(list, destdir, options)
ln_s(old, new, options)
ln_s(list, destdir, options)
ln_sf(src, dest, options)
cp(src, dest, options)
cp(list, dir, options)
cp_r(src, dest, options)
cp_r(list, dir, options)
mv(src, dest, options)
mv(list, dir, options)
rm(list, options)
rm_r(list, options)
rm_rf(list, options)
install(src, dest, mode =
chmod(mode, list, options)
chmod_R(mode, list, options)
chown(user, group, list, options)
chown_R(user, group, list, options)
touch(list, options)
Friday, February 4, 2011
Is Ruby is a Scripting Language or Compiled Language?
In general, programming languages fall into one of two
categories: they're either compiled languages or scripting
languages. Let's explore what each of those terms means, and
understand the differences between them.
Compiled Languages: The language in which you write an
application is not actually something that your computer
understands. Your code needs to be translated into bits and
bytes that can be executed by your computer. This process of
translation is called compilation, and any language that
requires compilation is referred to as a compiled language.
Examples of compiled languages include C, C#, and Java.
For a compiled language, the actual compilation is the final
step in the development process. You invoke a compiler --
the software program that translates your final
hand-written, human-readable code into machine-readable code
-- and the compiler creates an executable file. This final
product is then able to execute independently of the
original source code.
Thus, if you make changes to your code, and you want those
changes to be incorporated into the application, you must
stop the running application, recompile it, then start the
application again.
Scripting Languages: On the other hand, a scripting language
such as Ruby, PHP, or Python, relies upon an application's
source code all of the time. Scripting languages don't have
a compiler or a compilation phase per se; instead, they use
an interpreter -- a program that runs on the web server --
to translate hand-written code into machine-executable code
on the fly. The link between the running application and
your hand-crafted code is never severed, because that
scripting code is translated every time it is invoked -- in
other words, for every web page that your application renders.
As you might have gathered from the name, the use of an
interpreter rather than a compiler is the major difference
between a scripting language and a compiled language.
The Great Performance Debate: If you've come from a
compiled-language background, you might be concerned by all
this talk of translating code on the fly -- how does it
affect the application's performance?
These concerns are valid -- translating code on the web
server every time it's needed is certainly more expensive,
performance-wise, than executing pre-compiled code, as it
requires more effort on the part of your machine's
processor. The good news is that there are ways to speed up
scripted languages, including techniques such as code
caching and persistent interpreters. However, both topics
are beyond the scope of this book.
There's also an upside to scripted languages in terms of
performance -- namely, your performance while developing an
application.
Imagine that you've just compiled a shiny new Java
application, and launched it for the first time ... and then
you notice a typo on the welcome screen. To fix it, you have
to stop your application, go back to the source code, fix
the typo, wait for the code to recompile, and restart your
application to confirm that it is fixed. And if you find
another typo, you'll need to repeat that process again.
Lather, rinse, repeat.
In a scripting language, you can fix the typo and just
reload the page in your browser -- no restart, no recompile,
no nothing. It's as simple as that.
categories: they're either compiled languages or scripting
languages. Let's explore what each of those terms means, and
understand the differences between them.
Compiled Languages: The language in which you write an
application is not actually something that your computer
understands. Your code needs to be translated into bits and
bytes that can be executed by your computer. This process of
translation is called compilation, and any language that
requires compilation is referred to as a compiled language.
Examples of compiled languages include C, C#, and Java.
For a compiled language, the actual compilation is the final
step in the development process. You invoke a compiler --
the software program that translates your final
hand-written, human-readable code into machine-readable code
-- and the compiler creates an executable file. This final
product is then able to execute independently of the
original source code.
Thus, if you make changes to your code, and you want those
changes to be incorporated into the application, you must
stop the running application, recompile it, then start the
application again.
Scripting Languages: On the other hand, a scripting language
such as Ruby, PHP, or Python, relies upon an application's
source code all of the time. Scripting languages don't have
a compiler or a compilation phase per se; instead, they use
an interpreter -- a program that runs on the web server --
to translate hand-written code into machine-executable code
on the fly. The link between the running application and
your hand-crafted code is never severed, because that
scripting code is translated every time it is invoked -- in
other words, for every web page that your application renders.
As you might have gathered from the name, the use of an
interpreter rather than a compiler is the major difference
between a scripting language and a compiled language.
The Great Performance Debate: If you've come from a
compiled-language background, you might be concerned by all
this talk of translating code on the fly -- how does it
affect the application's performance?
These concerns are valid -- translating code on the web
server every time it's needed is certainly more expensive,
performance-wise, than executing pre-compiled code, as it
requires more effort on the part of your machine's
processor. The good news is that there are ways to speed up
scripted languages, including techniques such as code
caching and persistent interpreters. However, both topics
are beyond the scope of this book.
There's also an upside to scripted languages in terms of
performance -- namely, your performance while developing an
application.
Imagine that you've just compiled a shiny new Java
application, and launched it for the first time ... and then
you notice a typo on the welcome screen. To fix it, you have
to stop your application, go back to the source code, fix
the typo, wait for the code to recompile, and restart your
application to confirm that it is fixed. And if you find
another typo, you'll need to repeat that process again.
Lather, rinse, repeat.
In a scripting language, you can fix the typo and just
reload the page in your browser -- no restart, no recompile,
no nothing. It's as simple as that.
Monday, January 31, 2011
How to Dowload Ruby for windows?
For windows you can download Ruby
from
http://rubyforge.org/frs/?group_id=167
from
http://rubyforge.org/frs/?group_id=167
How to Dowload Ruby for Linux?
For windows you can download Ruby
from
http://rubyforge.org/frs/?group_id=167
for Linux try
http://www.rpmfind.net.
from
http://rubyforge.org/frs/?group_id=167
for Linux try
http://www.rpmfind.net.
Saturday, January 29, 2011
Ruby scripting for beginners
Ruby Scripting for beginner
variables:-
We'll deal with variables in much more depth when we talk about classes and objects. For now, let's just say your basic local variable names should start with either a lower case letter or an underscore, and should contain upper or lower case letters, numbers, and underscore characters. Global variables start with a $.
Program flow:-
Ruby includes a pretty standard set of looping and branching constructs: if, while and case
For example, here's if in action:
a = 10 * rand
if a < 5 puts "#{a} less than 5" elsif a > 7
puts "#{a} greater than 7"
else
puts "Cheese sandwich!"
end
[As in other languages, the rand function generates a random number between 0 and 1]
There will be plenty more time to discuss conditional statements in later chapters. The above example should be pretty clear.
Ruby also includes a negated form of if called unless which goes something like
unless a > 5
puts "a is less than or equal to 5"
else
puts "a is greater than 5"
end
Generally speaking, Ruby keeps an if statement straight as long as the conditional (if ...) and the associated code block are on separate lines. If you have to smash everything together on one line, you'll need to place the then keyword after the conditional
if a < 5 then puts "#{a} less than 5" end if a < 5 then puts "#{a} less than 5" else puts "#{a} greater than 5" end Note that the if statement is also an expression; its value is the last line of the block executed. Therefore, the line above could also have been written as puts(if a < 5 then "#{a} less than 5" else "#{a} greater than 5" end) Ruby has also adopted the syntax from Perl where if and unless statements can be used as conditional modifiers after a statement. For example puts "#{a} less than 5" if a < 5 puts "Cheese sandwich" unless a == 4 while behaves as it does in other languages -- the code block that follows is run zero or more times, as long as the conditional is true while a > 5
a = 10*rand
end
And like if, there is also a negated version of while called until which runs the code block until the condition is true.
Finally there is the case statement which we'll just include here with a brief example. case is actually a very powerful super version of the if ... elsif... system
a = (10*rand).round
#a = rand(11) would do the same
case a
when 0..5
puts "#{a}: Low"
when 6
puts "#{a}: Six"
else
puts "#{a}: Cheese toast!"
end
There are some other interesting things going on in this example, but here the case statement is the center of attention.
functions:-
In keeping with Ruby's all-object-oriented-all-the-time design, functions are typically referred to as methods. No difference. We'll cover methods in much more detail when we get to objects and classes. For now, basic method writing looks something like this:
# Demonstrate a method with func1.rb
def my_function( a )
puts "Hello, #{a}"
return a.length
end
len = my_function( "Giraffe" )
puts "My secret word is #{len} long"
$ func1.rb
Hello, Giraffe
My secret word is 7 long
Methods are defined with the def keyword, followed by the function name. As with variables, local and class methods should start with a lower case letter.
In this example, the function takes one argument (a) and returns a value. Note that the input arguments aren't typed (i.e. a need not be a string) ... this allows for great flexibility but can also cause a lot of trouble. The function also returns a single value with the return keyword. Technically this isn't necessary -- the value of the last line executed in the function is used as the return value -- but more often than not using return explicitly makes things clearer.
As with other languages, Ruby supports both default values for arguments and variable-length argument lists, both of which will be covered in due time. There's also support for code blocks, as discussed below.
Blocks:-
One very important concept in Ruby is the code block. It's actually not a particularly revolutionary concept -- any time you've written if ... { ... } in C or Perl you've defined a code block, but in Ruby a code block has some hidden secret powers...
Code blocks in Ruby are defined either with the keywords do..end or the curly brackets {..}
do
print "I like "
print "code blocks!"
end
{
print "Me too!"
}
One very powerful usage of code blocks is that methods can take one as a parameter and execute it along the way.
[ed note: the Pragmatic Programmers actually want to point out that it's not very useful to describe it this way. Instead, the block of code behaves like a 'partner' to which the function occasionally hands over control]
The concept can be hard to get the first time it's explained to you. Here's an example:
$ irb --simple-prompt
>> 3.times { puts "Hi!" }
Hi!
Hi!
Hi!
=> 3
Surprise! You always thought 3 was just a number, but it's actually an object (of type Fixnum) As its an object, it has a member function times which takes a block as a parameter. The function runs the block 3 times.
Blocks can actually receive parameters, using a special notation |..|. In this case, a quick check of the documentation for times shows it will pass a single parameter into the block, indicating which loop it's on:
$ irb --simple-prompt
>> 4.times { |x| puts "Loop number #{x}" }
Loop number 0
Loop number 1
Loop number 2
Loop number 3
=> 4
The times function passes a number into the block. The block gets that number in the variable x (as set by the |x|), then prints out the result.
Functions interact with blocks through the yield. Every time the function invokes yield control passes to the block. It only comes back to the function when the block finishes. Here's a simple example:
# Script block2.rb
def simpleFunction
yield
yield
end
simpleFunction { puts "Hello!" }
$ block2.rb
Hello!
Hello!
The simpleFunction simply yields to the block twice -- so the block is run twice and we get two times the output. Here's an example where the function passes a parameter to the block:
# Script block1.rb
def animals
yield "Tiger"
yield "Giraffe"
end
animals { |x| puts "Hello, #{x}" }
$ block1.rb
Hello, Tiger
Hello, Giraffe
It might take a couple of reads through to figure out what's going on here. We've defined the function "animals" -- it expects a code block. When executed, the function calls the code block twice, first with the parameter "Tiger" then again with the parameter "Giraffe". In this example, we've written a simple code block which just prints out a greeting to the animals. We could write a different block, for example:
animals { |x| puts "It's #{x.length} characters long!" }
which would give:
It's 5 characters long!
It's 7 characters long!
Two completely different results from running the same function with two different blocks.
There are many powerful uses of blocks. One of the first you'll come across is the each function for arrays -- it runs a code block once for each element in the array -- it's great for iterating over lists.
variables:-
We'll deal with variables in much more depth when we talk about classes and objects. For now, let's just say your basic local variable names should start with either a lower case letter or an underscore, and should contain upper or lower case letters, numbers, and underscore characters. Global variables start with a $.
Program flow:-
Ruby includes a pretty standard set of looping and branching constructs: if, while and case
For example, here's if in action:
a = 10 * rand
if a < 5 puts "#{a} less than 5" elsif a > 7
puts "#{a} greater than 7"
else
puts "Cheese sandwich!"
end
[As in other languages, the rand function generates a random number between 0 and 1]
There will be plenty more time to discuss conditional statements in later chapters. The above example should be pretty clear.
Ruby also includes a negated form of if called unless which goes something like
unless a > 5
puts "a is less than or equal to 5"
else
puts "a is greater than 5"
end
Generally speaking, Ruby keeps an if statement straight as long as the conditional (if ...) and the associated code block are on separate lines. If you have to smash everything together on one line, you'll need to place the then keyword after the conditional
if a < 5 then puts "#{a} less than 5" end if a < 5 then puts "#{a} less than 5" else puts "#{a} greater than 5" end Note that the if statement is also an expression; its value is the last line of the block executed. Therefore, the line above could also have been written as puts(if a < 5 then "#{a} less than 5" else "#{a} greater than 5" end) Ruby has also adopted the syntax from Perl where if and unless statements can be used as conditional modifiers after a statement. For example puts "#{a} less than 5" if a < 5 puts "Cheese sandwich" unless a == 4 while behaves as it does in other languages -- the code block that follows is run zero or more times, as long as the conditional is true while a > 5
a = 10*rand
end
And like if, there is also a negated version of while called until which runs the code block until the condition is true.
Finally there is the case statement which we'll just include here with a brief example. case is actually a very powerful super version of the if ... elsif... system
a = (10*rand).round
#a = rand(11) would do the same
case a
when 0..5
puts "#{a}: Low"
when 6
puts "#{a}: Six"
else
puts "#{a}: Cheese toast!"
end
There are some other interesting things going on in this example, but here the case statement is the center of attention.
functions:-
In keeping with Ruby's all-object-oriented-all-the-time design, functions are typically referred to as methods. No difference. We'll cover methods in much more detail when we get to objects and classes. For now, basic method writing looks something like this:
# Demonstrate a method with func1.rb
def my_function( a )
puts "Hello, #{a}"
return a.length
end
len = my_function( "Giraffe" )
puts "My secret word is #{len} long"
$ func1.rb
Hello, Giraffe
My secret word is 7 long
Methods are defined with the def keyword, followed by the function name. As with variables, local and class methods should start with a lower case letter.
In this example, the function takes one argument (a) and returns a value. Note that the input arguments aren't typed (i.e. a need not be a string) ... this allows for great flexibility but can also cause a lot of trouble. The function also returns a single value with the return keyword. Technically this isn't necessary -- the value of the last line executed in the function is used as the return value -- but more often than not using return explicitly makes things clearer.
As with other languages, Ruby supports both default values for arguments and variable-length argument lists, both of which will be covered in due time. There's also support for code blocks, as discussed below.
Blocks:-
One very important concept in Ruby is the code block. It's actually not a particularly revolutionary concept -- any time you've written if ... { ... } in C or Perl you've defined a code block, but in Ruby a code block has some hidden secret powers...
Code blocks in Ruby are defined either with the keywords do..end or the curly brackets {..}
do
print "I like "
print "code blocks!"
end
{
print "Me too!"
}
One very powerful usage of code blocks is that methods can take one as a parameter and execute it along the way.
[ed note: the Pragmatic Programmers actually want to point out that it's not very useful to describe it this way. Instead, the block of code behaves like a 'partner' to which the function occasionally hands over control]
The concept can be hard to get the first time it's explained to you. Here's an example:
$ irb --simple-prompt
>> 3.times { puts "Hi!" }
Hi!
Hi!
Hi!
=> 3
Surprise! You always thought 3 was just a number, but it's actually an object (of type Fixnum) As its an object, it has a member function times which takes a block as a parameter. The function runs the block 3 times.
Blocks can actually receive parameters, using a special notation |..|. In this case, a quick check of the documentation for times shows it will pass a single parameter into the block, indicating which loop it's on:
$ irb --simple-prompt
>> 4.times { |x| puts "Loop number #{x}" }
Loop number 0
Loop number 1
Loop number 2
Loop number 3
=> 4
The times function passes a number into the block. The block gets that number in the variable x (as set by the |x|), then prints out the result.
Functions interact with blocks through the yield. Every time the function invokes yield control passes to the block. It only comes back to the function when the block finishes. Here's a simple example:
# Script block2.rb
def simpleFunction
yield
yield
end
simpleFunction { puts "Hello!" }
$ block2.rb
Hello!
Hello!
The simpleFunction simply yields to the block twice -- so the block is run twice and we get two times the output. Here's an example where the function passes a parameter to the block:
# Script block1.rb
def animals
yield "Tiger"
yield "Giraffe"
end
animals { |x| puts "Hello, #{x}" }
$ block1.rb
Hello, Tiger
Hello, Giraffe
It might take a couple of reads through to figure out what's going on here. We've defined the function "animals" -- it expects a code block. When executed, the function calls the code block twice, first with the parameter "Tiger" then again with the parameter "Giraffe". In this example, we've written a simple code block which just prints out a greeting to the animals. We could write a different block, for example:
animals { |x| puts "It's #{x.length} characters long!" }
which would give:
It's 5 characters long!
It's 7 characters long!
Two completely different results from running the same function with two different blocks.
There are many powerful uses of blocks. One of the first you'll come across is the each function for arrays -- it runs a code block once for each element in the array -- it's great for iterating over lists.
How Ruby XPath to find attribute ?
What Ruby library can be used to select attribute using XPath, and to use it as the starting point for other XPath queries.
Example:
Desired code:
get_pair "//*/@key", "../@value"
get_pair "//*/@foo", "../@bar"
Expected output:
"A" "B"
"C" "D"
"E" "F"
Pseudo implementation:
def get_pair(key, value)
xml_doc.select[key].each do |a|
puts [a, a.select[value]]
end
end
Example:
Desired code:
get_pair "//*/@key", "../@value"
get_pair "//*/@foo", "../@bar"
Expected output:
"A" "B"
"C" "D"
"E" "F"
Pseudo implementation:
def get_pair(key, value)
xml_doc.select[key].each do |a|
puts [a, a.select[value]]
end
end
Subscribe to:
Posts (Atom)