Showing posts with label General Testing. Show all posts
Showing posts with label General Testing. Show all posts

Tuesday, February 22, 2011

What is TRM?

Web Application Testing in Ruby: What is stub?

TRM means Test Responsibility Matrix.

TRM: --- It indicates mapping between test factors and development stages...

Test factors like:
Ease of use, reliability, portability, authorization, access control, audit trail, ease of operates, maintainable... Like dat...
Development stages...
Requirement gathering, Analysis, design, coding, testing, and maintenance

Monday, February 21, 2011

What is release notes?

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.

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

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

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 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 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.

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.

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.

Tuesday, February 1, 2011

How to Create watir Frame work : Admin Module.rb

Web Application Testing in Ruby: How to Create watir Frame work : Customer Module.rb
require 'test/unit'

02 include Test::Unit::Assertions

03

04 module Admin

05 TITLE = 'ADMINISTER Pragprog Books Online Store'

06 URL = 'http://localhost:3000/admin/'

07

08 def Admin.log_on(browser, username, password)

09 browser.goto(URL)

10 if browser.link(:text,'Log out').exist? then #if already logged in

11 browser.link(:text,'Log out').click

12 end

13 browser.text_field(:id, 'user_name').set username

14 browser.text_field(:id, 'user_password').set password

15 browser.button(:value, ' LOGIN ').click

16 if browser.div(:id, 'notice').exist? then

17 return false,browser.div(:id, 'notice').text

18 else

19 return true,''

20 end

21 end

22

23 def Admin.ship_items(browser, name)

24 browser.goto(URL)

25 browser.link(:text, 'Shipping').click

26 num_orders = 0

27 index = 0

28 browser.form(:action,'/admin/ship').divs.each do |div|

29 if div.class_name == "olname"

30 index+=1

31 if div.text == name then

32 browser.form(:action,'/admin/ship').checkbox(:index, index).set

33 num_orders+=1

34 end

35 end

36 end

37

38 browser.button(:value, ' SHIP CHECKED ITEMS ').click

39

40 if num_orders == 1 then

41 assert_equal(browser.div(:id,"notice").text, "One order marked as shipped","Correct notice")

42 elsif num_orders > 1 then

43 assert_equal(browser.div(:id,"notice").text, "#{num_orders} orders marked as shipped","Correct notice")

44 end

45 return true, num_orders.to_s

46 end

47

48 end

How to Create watir Frame work : Customer Module.rb

Web Application Testing in Ruby: How to Create watir Frame work : Test Driver tc_main.rb

require 'test/unit'

002 include Test::Unit::Assertions

003

004 module Customer

005

006 TITLE = 'Pragprog Books Online Store'

007 URL = 'http://localhost:3000/store/'

008

009 # Description:: Adds a book named 'book_title' to cart

010 def Customer.add_book(browser, book_title)

011 browser.goto(URL)

012 # Check if title is already in cart - so we can check it was added correctly

013 browser.link(:text,'Show my cart').click

014 prev_cart_count = 0

015 prev_cart_total = 0.00

016 if not browser.div(:text,'Your cart is currently empty').exist? then

017 # We have a non-empty cart

018 for row in browser.table(:index,1)

019 if row[2].text == book_title then

020 prev_cart_count = row[1].text.to_i

021 break

022 end

023 end

024 prev_cart_total = browser.cell(:id, 'totalcell').text[1..-1].to_f #remove $ sign

025 browser.link(:text, 'Continue shopping').click

026 end

027

028 found = false

029 book_price = 0.00

030 1.upto(browser.divs.length) do |index|

031 if (browser.div(:index,index).attribute_value('className') == 'catalogentry') and (browser.div(:index,index).h3(:text,book_title).exists?) then

032 book_price = browser.div(:index,index).span(:class, 'catalogprice').text[1..-1].to_f #remove $ sign

033 browser.div(:index,index).link(:class,'addtocart').click

034 found = true

035 break

036 end

037 end

038 if not found then

039 return false,'Could not locate title in store'

040 end

041

042 new_cart_count = 0

043 for row in browser.table(:index,1)

044 if row[2].text == book_title then

045 new_cart_count = row[1].text.to_i

046 break

047 end

048 end

049 new_cart_total = browser.cell(:id, 'totalcell').text[1..-1].to_f # remove $ sign

050 assert_equal(new_cart_count,(prev_cart_count+1), "Ensure that new quantity is now one greater than previously")

051 assert_equal(new_cart_total,(prev_cart_total + book_price), "Ensure that new cart total is old cart total plus book price")

052 browser.link(:text, 'Continue shopping').click

053 return true,new_cart_total

054 end

055

056 def Customer.check_out(browser, customerName, customerEmail, customerAddress, customerPaymentMethod)

057 browser.goto(URL)

058 browser.link(:text,'Show my cart').click

059 if browser.div(:text,'Your cart is currently empty').exist? then

060 return false,'Your cart is currently empty'

061 end

062 browser.link(:text,"Checkout").click

063 browser.text_field(:id, 'order_name').set(customerName)

064 browser.text_field(:id, 'order_email').set(customerEmail)

065 browser.text_field(:id, 'order_address').set(customerAddress)

066 begin

067 browser.select_list(:id, 'order_pay_type').select(customerPaymentMethod)

068 rescue Watir::Exception::NoValueFoundException

069 flunk('Could not locate customer payment method in drop down list: '+customerPaymentMethod)

070 end

071 browser.button(:name, 'commit').click

072 if browser.div(:id,'errorExplanation').exist? then

073 error = ''

074 1.upto(browser.div(:id,'errorExplanation').lis.length) do |index|

075 error << (browser.div(:id,'errorExplanation').li(:index,index).text + ",")

076 end

077 browser.link(:text,'Continue shopping').click

078 return false, error

079 end

080 assert_equal(browser.div(:id,'notice').text, 'Thank you for your order.',"Thank you for your order should appear.")

081 return true,''

082 end

083

084 def Customer.empty_cart(browser)

085 browser.goto(URL)

086 browser.link(:text,"Show my cart").click

087 if browser.div(:text,"Your cart is currently empty").exist? then

088 assert('Cart was never empty')

089 else

090 browser.link(:text,'Empty cart').click

091 assert_equal(browser.div(:id, 'notice').text,'Your cart is now empty')

092 end

093 return true,''

094 end

095

096 def Customer.check_cart_total(browser, exp_total)

097 browser.goto(URL)

098 browser.link(:text,'Show my cart').click

099 if browser.div(:text,'Your cart is currently empty').exist? then

100 return false,'Your cart is currently empty'

101 end

102 act_total = browser.cell(:id, 'totalcell').text[1..-1].to_f

103 assert_equal(act_total,exp_total.to_f,"Check that cart total is as expected.")

104 return true,act_total

105 end

106 end

How to Create watir Frame work : Test Driver tc_main.rb

Web Application Testing in Ruby: How to Create watir Frame work ?


$:.unshift File.join(File.dirname(__FILE__), ".", "lib")

002 require 'watir'

003 require 'roo'

004 require 'test/unit'

005 require 'customer'

006 require 'admin'

007 $stdout = File.new('log.txt',File::WRONLY|File::APPEND|File::CREAT)

008 $stderr = File.new('log.txt',File::WRONLY|File::APPEND|File::CREAT)

009

010 class TC_WatirMelon < Test::Unit::TestCase

011 @@colmap = {:module_name=>0, :method_name=>1, :comments=>2, :exp_outcome=>3, :exp_error=>4, :first_param=>5}

012 @@ss_format = ARGV[0]

013 @@specified_browser = ARGV[1]

014

015 def setup

016 puts "[Starting at #{Time.now}]\n"

017 case @@ss_format

018 when "excel"

019 @ss = Excel.new("watirmelon.xls")

020 when "wiki"

021 @ss = Excel.new("http://localhost:8080/download/attachments/2097153/watirmelon.xls")

022 when "gdocs"

023 @ss = Google.new("0AtL3mPY2rEqmdEY3XzRqUlZKSmM5Z3EtM21UdFdqb1E")

024 else

025 @ss = Openoffice.new("watirmelon.ods")

026 end

027 @ss.default_sheet = @ss.sheets.first

028 case @@specified_browser

029 when "firefox"

030 Watir::Browser.default = 'firefox'

031 @browser = Watir::Browser.new

032 else

033 Watir::Browser.default = 'ie'

034 @browser = Watir::Browser.new

035 @browser.speed = :zippy

036 @browser.visible = true

037 end

038 end

039

040 def test_run_sheet()

041 @ss.first_row.upto(@ss.last_row) do |row|

042 #Read row into array

043 line = Array.new

044 @ss.first_column.upto(@ss.last_column) do |column|

045 line << @ss.cell(row, column).to_s.strip

046 end

047

048 module_name = line[@@colmap[:module_name]]

049 if module_name != "Function" then #if not a header

050 method_name = line[@@colmap[:method_name]].downcase.gsub(' ','_') #automatically determine ruby method name based upon data sheet

051 exp_outcome = line[@@colmap[:exp_outcome]]

052 exp_error = line[@@colmap[:exp_error]]

053 first_param = @@colmap[:first_param]

054 required_module = Kernel.const_get(module_name)

055 required_method = required_module.method(method_name)

056 arity = required_method.arity() # this is how many arguments the method requires, it is negative if a 'catch all' is supplied.

057 arity = ((arity * -1) - 1) if arity < 0 # arity is negative when there is a 'catch all'

058 arity = arity-1 # Ignore the first browser parameter

059 unless arity == 0

060 parameters = line[first_param..first_param+(arity-1)]

061 else

062 parameters = []

063 end

064 begin

065 act_outcome, act_output = required_method.call(@browser, *parameters)

066 rescue Test::Unit::AssertionFailedError => e

067 self.send(:add_failure, e.message, e.backtrace)

068 act_outcome = false

069 act_output = e.message

070 end

071 if (exp_outcome == 'Success') and act_outcome then

072 assert(true, "Expected outcome and actual outcome are the same")

073 result = 'PASS'

074 elsif (exp_outcome == 'Error') and (not act_outcome) and (exp_error.strip! == act_output.strip!)

075 assert(true, "Expected outcome and actual outcome are the same, and error messages match")

076 result = 'PASS'

077 else

078 result = 'FAIL'

079 begin

080 assert(false,"Row: #{row}: Expected outcome and actual outcome for #{method_name} for #{module_name} do not match, or error messages do not match.")

081 rescue Test::Unit::AssertionFailedError => e

082 self.send(:add_failure, e.message, e.backtrace)

083 end

084 end

085 puts "###########################################"

086 puts "[Running: #{module_name}.#{method_name}]"

087 puts "[Expected Outcome: #{exp_outcome}]"

088 puts "[Expected Error: #{exp_error}]"

089 puts "[Actual Outcome: Success]" if act_outcome

090 puts "[Actual Outcome: Error]" if not act_outcome

091 puts "[Actual Output: #{act_output}]"

092 puts "[RESULT: #{result}]"

093 puts "###########################################"

094 end

095 end

096 end

097

098 def teardown

099 @browser.close

100 puts "[Finishing at #{Time.now}]\n\n"

101 end

102

103 end

How to Create watir Frame work ?

One common challenge I see over and over again is people figuring out how to design a logical and maintainable automated testing framework. I have designed quite a few frameworks for various projects, but one thing that has consistently been a win for me is purposely separating test case and test execution design.

It’s therefore logical that the design of my Watir framework deliberately separates test case design and test execution design so that:

■test case design is done visually in spreadsheets; and
■test execution design is done in ruby methods, because code is the most efficient and maintainable way.
Since I last published details about my framework on this blog, I have started doing assertions using the Test::Unit ruby library. The reasons I chose Test::Unit are:

■it is easy to ‘mix-in’ Test::Unit assertions into modules of ruby code using include Test::Unit::Assertions;
■it is included with ruby;
■ruby scripts with Test::Unit::TestCase are instantly executable, in my case, from SciTE;
■its assertions are easy to understand and use.
I have also made some other improvements to my framework code, including:

■the ability to specify browser types, and spreadsheet sources, as command line arguments (with defaults);
■logging test output to a file;
■no longer attaching to an open browser, the same browser instance is used completely for all tests (and elegantly closed at the end).
The main design has been kept the same, in that a spreadsheet (either excel, openoffice or Google Docs) contains tests grouped by functional area, which call a method in a particular module.

The great thing about my framework is that adding a new test is a matter of designing the test case, and then writing the ruby method: as the methods are called dynamically from the spreadsheet, no extra glue is needed!

Enough talk, here’s the code. The Google spreadsheet is here. You can find a .zip file of all the required files to run it here. It runs on the depot app, which you get here. You will need two gems: Watir (oh duh), and Roo.

Friday, January 28, 2011

How to deal with Java scripts and frame?

I came across this difficulty when I was trying to automate a webpage that was primarily built in Javascript; this webpage also always had the same href (or web address) and also was built with many frames. The problem that I ran into was that I could find the links with the IE developer toolbar to get their ids, but whenever I tried to access them, I could not, I was given an error message saying that they did not exist. At this point in time I thought the issue I had was with javascript, but I was incorrect!

A lot of hunting on the interwebs led me, ironically, back to the watir main documentation, where I discovered that my issue was really with frames! When a website has frames, you need to specify what frame the link is in to actually access it, for example:
ie.frame(“main”).link(:id,”UW_CO_JOBTITLE_HL$”).click

Or in general terms:
ie.frame(“FRAMENAME”).link(:id, “LINKID”).click

And there we have, you can now access links that are in frames, hopefully this saves someone all of the hunting that I had to do! This is also a really good example of how difficult it is to find a solution to something when you are not sure what the problem was; I thought the problem was with JavaScript, so I was searching for that, but it was in fact as stated above with the frames!

IE Automation testing with Ruby: How to catch popup windows?

Firstly I need to define what I mean my pop-up Windows. The pop-up windows that cause trouble are not internet explorer based windows, they are actually ‘Windows’ windows, (sorry if thats confusing). The ones that I am referring to are the ones that come up when, for example, you click on a download link. These are inherently a pain because of the fact that they are not IE windows. Luckily there is a pretty simple work around that i have come up with.

Ruby has access to the WIN32OLE library , which is basically like an API for windows applications. What you can do is use this library to catch these pop up windows. Below is the code that you’ll need to run in a Ruby script:

require ‘win32ole’ #Loads the win32ole library
wsh = WIN32OLE.new(Wscript.Shell) #For more info click here
wsh.AppActivate(‘Connect’) #Focuses on a given application based on its Title

At this point you can manipulate the window, for example, with a SendKeys command:

wsh.SendKeys(“%{F4}”) #This would close the program with Alt-F4

This clearly has it’s limitations because during this time you cannot be doing things on your computer, because the AppActivate would fail. I am still looking for a lower level at which I can address this problem.

Now everyone likes to see code at work, so I have written a quick script that goes to the Notepad++ downloads page, clicks the download link, and then closes the pop-up download window. As a quick side note, if you do not already use notepad++ I highly recommend it!

require ‘win32ole’
require ‘watir’

wsh = WIN32OLE.new(‘Wscript.Shell’)

ie= Watir::IE.new
ie.goto(“http://notepad-plus.sourceforge.net/uk/site.htm”)
ie.frame(:name, “index”).link(:text, “Download”).click #Good example of how to execute a link in a Frame
ie.frame(:name, “index”).link(:text, “Download Notepad++ executable files”).click

sleep 20 #need to wait for source forge to load it is slow
ie1 = Watir::IE.attach(:title, /Source/)
ie1.link(:id, “showfiles_download_file_pkg0_1rel0_2″).click

wsh.AppActivate(“File Download – Security Warning”) #Focuses on the pop up window
wsh.SendKeys(“%{F4}”) #Sends the alt-F4 command to the window to close it

Watir::IE.close_all #Closes all open IE windows