Watir usage environment construction
1. Watir environment tool installation package:
1) Download address: /rubyinstaller/
2) watir-1.5. Download address: /frs/?group_id=104&release_id=28016
3) rubygems-update-1.3. Download address: /frs/?group_id=126
2. Firewatir environment tool installation package:
1) Software package in step 1
2) Firefox2.0 download address: /Get/gjrj/
3) Firefox plugin: firbug1.05, JSSh. Jssh download address: Address
4) Firewatir-1.1 download address: /frs/?group_id=104&release_id=28017
3. Watir installation
1) Installation;
2) Upgrade gem, copy the gem package to the ruby installation directory, and enter the command on the command line: gem install rubygems-update 1.3. (gem package name). Reminder: After installation, enter the ruby directory: lib\ruby\gems\1.8\gems\rubygems-update-1.3.4, click on the file in this folder:, and upgrade gem.
3) Install the watir package, copy the watir package to the ruby installation directory, use the command line to enter the ruby installation directory, and enter the command: gem install watir-1.5.
4) Use the command gem list to check whether the installation is successful.
4. Install firewatir
1) Install firefox and firebug and Jssh plug-ins. Installation method: Open the firefox browser, click "File"/"Open", select the plug-in file name, and install it.
2) Install firewatir, use the command line to enter the directory where ruby is installed, and enter the command: gem install firewatir-1.
5. Test whether the 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 the program can be executed correctly, it means there is no problem with the installation. At this point, you can start the journey of automated test development.
6. 'nmake' appears during the installation of watir. It is not an internal or external command, nor is it a runnable program or batch file.
Use commands
gem install --local watir-1.5.
The installation was successful!
Read test parameterized data from various data sources
A commonly used technology in automated testing is parameterization. It is painful to not support parameterization testing frameworks. QTP itself has it, but it is not naturally supported by Ruby's Watir and Selenium, because these frameworks only provide the most basic automated driver class library, and execution management, data management, etc. other than drivers are another topic. Most of the execution frameworks used in selenium and watir similar projects are unit testing frameworks, and naturally they do not support parameterization. Now only the junit4 version supports parameterization, and testNG supports multiple parameterizations by default. If you start a project, you can prioritize the automation of these framework-like languages.
Although watir itself does not support parameterization and ruby unit tests do not support parameterization, parameterization also needs to be done. There is no way to think of solutions. So I wrote a parameterized class separately to supplement the shortcomings of the parameterized function. Its working method is to provide unified data reading from test data sources, call this interface in unit tests, but do not specify specific parameter rows, which are configured in a separate configuration file. This can uniformly manage the parameter line contents taken during each test execution. The following code is used to obtain test data from various 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..-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 = (dsn, user, password) ("use #{db}") ("SET NAMES UTF8") if (':')[1] == "Mysql" sth = (sql) arr = sth.fetch_hash do | row | arr << row end arr rescue DBI::DatabaseError => e puts "An error occurred" puts "Error code: #{}" puts "Error message: #{}" ensure 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 ==Fixnum all_data[row] else all_data end end end class Excel_Adapter def initialize(ds_connector, table_name, what=nil, where=nil) @connection = ('') @record_set = ('') @ds_connector = ds_connector @sql_str = generate_sql(table_name, what, where) end def get_pars(row=nil) t_arr = [] @(@ds_connector) @record_set.Open(@sql_str, @connection) @record_set. do | i | t_arr << @record_set.(i).name end all_data = @record_set. all_data = generate_hash(t_arr, all_data) if ==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
Calling method:
par = (Ds_mysql_connector, 'demo') p par.get_pars(0)
Configuration file configuration:
##String linking database in excelEXCEL_DSN = %{Excel_Adapter#Provider=.4.0;Data Source=%s;Extended Properties=Excel 5.0;} EXCEL_FILE = %{D:\\} ##Stand linking mysqlDs_mysql_connector = %{Mysql_Adapter#DBI:Mysql:shoppingcart:127.0.0.1#root#password#shoppingcart} ##Specify the line number of the accident parameter on the current run side, starting from 0PAR_ROW = 1
The corresponding file points to the path, ip address, database name, user name, password, etc. need to be modified