Watir the use of the environment to build
1, Watir Environment Tool installation package:
1) ruby186-26.exe Download address: http://files.rubyforge.vm.bytemark.co.uk/rubyinstaller/
2) Watir-1.5.2.gem Download address: http://rubyforge.org/frs/?group_id=104&release_id=28016
3) Rubygems-update-1.3.7.gem Download address: http://rubyforge.org/frs/?group_id=126
2, Firewatir Environment Tool installation package:
1) The package in step 1
2) Firefox2.0 Download address: http://www.hacker.cn/Get/gjrj/06102608545293311.shtml
3 Firefox plugin: firbug1.05,jssh. JSSH Download Address: Address
4) Firewatir-1.1 Download address: http://rubyforge.org/frs/?group_id=104&release_id=28017
3, Watir Installation
1) installation of Ruby186-26.exe;
2 upgrade gem, copy gem package to Ruby installation directory, enter command at command line: Gem install rubygems-update 1.3.7.gem (Gem package name). Reminder: Enter Ruby directory after installation: lib\ruby\gems\1.8\gems\rubygems-update-1.3.4, click the file in this folder: SETUP.RB, upgrade gem
3 Install Watir package, copy Watir package to ruby installation directory, use command line to enter Ruby installation directory, enter command: Gem install Watir-1.5.2.gem.
4 Use the command gem list to see if the installation was successful.
4. Installation Firewatir
1 Install Firefox and Firebug,jssh plug-in, installation method: Open the Firefox browser, click "File"/"open", select the plug-in file name, installation can be.
2 Install Firewatir, use the command line to enter Ruby installed directory, enter the command: Gem install Firewatir-1.1.gem
5, test Firewatir is installed successfully?
Use the command line to enter the Firewatir installation path (\ruby\lib\ruby\gems\1.8\gems\firewatir-1.1), enter the Unittests folder, and enter the command: Ruby Mozilla_all_ TESTS.RB, if you can properly execute the program, the installation is correct, there is no problem, you can begin the journey of automated test development.
6. "NMAKE" is not an internal or external command or a running program or batch file during the installation Watir process.
Using commands
The installation is successful!
Reading test parameterized data from various data sources
the technology that is often used in automated testing is parameterized, and it is painful not to support a parameterized test framework. QTP itself, but similar to Ruby Watir, and selenium are not naturally supported, because these frameworks only provide the most basic automation-driven library, while the driver of executive management, data management, etc. is a topic. Most of the implementation frameworks for selenium and Watir similar projects are the framework for unit testing and are not naturally supported by parameterization. Only JUNIT4 versions now support parameterization, and testng default support for multiple parameterization. If you start a project, you can prioritize languages that are compatible with these similar frameworks for automation.
Watir Although it does not support parameterization, Ruby's unit tests do not support it, but parameterization also needs to be done, and there's no way to think about workarounds. So a parameterized class is written separately to complement the lack of parametric functionality. It works by providing a uniform test data source for data reading, calling this interface in a unit test, but not specifying a specific parameter row, which is configured in a separate configuration file. This allows for a unified management of the parameter rows that are taken each time the test is executed. The following code is used to fetch the test data from a variety of data sources.
#encoding: utf-8
require 'DBI'
require 'odbc_utf8'
def generate_sql(table, what=nil, where=nil)
what="*" unless what
where="1=1" unless where
"select %s from %s where %s" % [what, table, where]
end
def generate_hash(header, all_data)
t_arr = []
all_data.each do | row |
t_hash = {}
for i in 0..header.size-1 do
t_hash[header[i]] = row[i]
end
t_arr << t_hash
end
t_arr
end
def select_hash_db(dsn,user,password,db,sql)
begin
dbh = DBI.connect(dsn, user, password)
dbh.do("use #{db}")
dbh.do("SET NAMES UTF8") if dsn.split(':')[1] == "Mysql"
sth = dbh.execute(sql)
arr = Array.new
sth.fetch_hash do | row |
arr << row
end
sth.finish
arr
rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
dbh.disconnect if dbh
end
end
class Text_Adapter
def initialize(file_path, sep=" ", col_num=nil, row_num=nil)
end
def get_pars(row=nil)
end
end
class Mysql_Adapter
def initialize(ds_connector, table_name, what=nil, where=nil)
@sql_str = generate_sql(table_name, what, where)
@ds_connector = ds_connector
end
def get_pars(row=nil)
dsc_arr = @ds_connector.split("#")
all_data = select_hash_db(dsc_arr[0],dsc_arr[1],dsc_arr[2],dsc_arr[3],@sql_str)
if row.class==Fixnum
all_data[row]
else
all_data
end
end
end
class Excel_Adapter
def initialize(ds_connector, table_name, what=nil, where=nil)
@connection = WIN32OLE.new('ADODB.Connection')
@record_set = WIN32OLE.new('ADODB.Recordset')
@ds_connector = ds_connector
@sql_str = generate_sql(table_name, what, where)
end
def get_pars(row=nil)
t_arr = []
@connection.Open(@ds_connector)
@record_set.Open(@sql_str, @connection)
@record_set.Fields.count.times do | i |
t_arr << @record_set.Fields.Item(i).name
end
all_data = @record_set.GetRows.transpose
all_data = generate_hash(t_arr, all_data)
if row.class==Fixnum
all_data[row]
else
all_data
end
end
end
class Parameter
def initialize(ds_connector, table_name, what=nil, where=nil)
dsc_arr = ds_connector.split("#", 2)
eval("@adp = #{dsc_arr[0]}.new dsc_arr[1], table_name, what, where")
end
def get_pars(row=nil)
@adp.get_pars(row)
end
end
Call Method:
par = parameter.new (ds_mysql_connector, ' demo ')
p par.get_pars (0)
Configuration file configuration:
## Link to the database string in excel
EXCEL_DSN =% {Excel_Adapter # Provider = MicroSoft.Jet.OLEDB.4.0; Data Source =% s; Extended Properties = Excel 5.0;}
EXCEL_FILE =% {D: \\ 1.xlsx}
## link mysql string
Ds_mysql_connector =% {Mysql_Adapter # DBI: Mysql: shoppingcart: 127.0.0.1 # root # password # shoppingcart}
## Specify the line number of the current accident parameter, starting from 0
PAR_ROW = 1
The corresponding file points to the path, IP address, database name, user name, password, etc. need to modify