Multiple concurrent browser analyzes using watir-webdriver across various browsers

so I am working on a website here, and I would like to run several browser tests at a time. I mean, it should run my smoke tests like firefox and chrome and report the results of each browser. I am currently only testing with rpsec and watir-webdriver, but would like to automate for the other 2 browsers. Are there any existing gems (I could not find them) if not for the best way to solve this problem?

+4
source share
4 answers

You should try WatirGrid .

This will not do all the work for you, but it will give you a platform to run several tests at once. You can run the same test 3 times by changing the target browser, and the grid will process where they will be executed.

+3
source

Why do you need nothing but watir-webdriver to run multiple browsers on the same computer.

ie = Watir::Browser.new :ie firefox = Watir::Browser.new :firefox chrome = Watir::Browser.new :chrome opera = Watir::Browser.new :opera 
+2
source

If you have multiple machines or virtual machines to work with, Jenkins is the answer. My approach is similar to Chuck, but instead of a flat configuration file, I let Jenkins request these values ​​through a drop-down menu, etc. Jenkins is easy to configure and can automatically distribute test cases to any available testing machine.

So, I click "Google Search Test" and select "Internet Explorer" ... then I do the same and select a different browser. Parallel tests in different browsers with HTML / email output and a large log history.

I will write about it too, but I'm still on vacation!

Here is an example configuration file (they assign default values ​​if, for example, Jenkins is not used to run them). NOTE: "|| =" means "if nil, use this value. If not nil, use the current value". I only set values ​​if Jenkins hasn't done it yet.

 ENV['BROWSER'] ||= "firefox" ENV['ENVIRONMENT'] ||= "qa" ENV['LIMIT'] ||= "10" ENV['DISTRICT'] ||= "any" ENV['TYPE'] ||= "pkg-new" # Not necessary, but added for sanity/cleanliness: $type = ENV['TYPE'].downcase $browser = ENV['BROWSER'].downcase $env = ENV['ENVIRONMENT'].downcase $district = ENV['DISTRICT'].downcase puts "\t** Testing #{$env.upcase} using #{$browser.upcase}... **" 

Jenkins part is surprisingly simple - so easy that I didn’t think it was set up. You create a variable for your script, and everything you call a variable becomes ENV ["VariableName"] - and is immediately available to your script.

So, I have a variable called "BROWSER" that is set using the options Firefox, IE and Chrome. The user has no room for confusing the script with free text, and they can run their own test whenever they want. My Devs / PM / Users love me: D.

+2
source

If you want to run the same test code for tests, you will need to supplant the browser type as an environment variable, or a YAML file or something similar.

There are some things in Ruby that simplify working with yaml files (I need to write a blog entry on this) so that you can place something at the top of your script that calls the method to get configuration information, and then set the type accordingly browser.

In my testconfig.yml YAML file, I have:

 global: browser: ie #possible values: ie, ff, chrome 

note. I am not currently testing the opera (the market segment is too small) or it will be on the list of possible values. Commentary is just to make life easier for those who could edit this file.

I have a read_config method defined in readconfig.rb file that looks (partially) like this

 require 'yaml' def read_config config = YAML.load_file('testconfig.yml') $browser_type = config['global']['browser'] end 

And at the top of my tests there is such code

 require 'rubygems' require 'readconfig' require 'watir-webdriver' read_config $browser = Watir::Browser.new $browser_type.to_sym 

Thus, I can have a different configuration file in each system (which also sets many other things, such as current passwords (changes regularly), the testing environment used and settings for each environment for others, for example, the URL of the test server, the base server data and name, etc. When developing tests, a simple change in the configuration file allows me to run all the tests facing this browser.If I want to work in parallel, I can configure the systems using their own custom th configuration file, let them pull the current scripts from the source control, and then run them against any browser, server, etc. it is configured in the configuration file.

This is probably simple stuff for any folded ruby ​​developer, but it looks like magic for any of us new to rubies, and especially for getting hard-coded values ​​outside of my scripts and in one place where I can control and modify them.

+1
source

Source: https://habr.com/ru/post/1388465/


All Articles