how to export results when running selenium ruby webdriver scripts to output files from command prompt ruby window
I run all my tests inside a unit framework. I use test-unit myself but you could also use rspec. This also gives you the ability to add assertions to your code and then have it be reported by the unit framework. If one test fails or errors you can move on to the next test.
a simplified version of my rakefile looks like this
require 'rake/testtask'
#this will run all tests in directory with no dependencies
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['FAL*.rb']
t.verbose = true
end
#or you could run individual files like this
task :FAL001 do
ruby "FAL001.rb"
end
and every test case looks like this
require "test-unit"
gem "test-unit"
require "selenium-webdriver"
class FAL001 < Test::Unit::TestCase
def testFAL001 #methods that begin with test are automatically run
#selenium code goes here
assert_true(1 == 1)
end
def test002
#another test goes here
end
end
how to write selenium ruby webdriver test results from Ruby terminal to output files
I have not tried this out, but I guess this should work
task :default do
FileList['test*.rb'].each { |file|
begin
system("ruby #{file} > #{file}.log")
rescue
puts "The following tests reported unexpected behavior:"
puts "#{file} \n"
end
}
end
Based on new requirements -
UPDATE
task :default do
logfile.new("console.out", "w")
FileList['test*.rb'].each { |file|
begin
system("ruby #{file} > #{file}.log")
rescue
logfile.puts("The following tests reported unexpected behavior:")
logfile.puts("#{file} \n")
end
}
end
How to generate results after selenium test in Ruby?
Looks like someone has already taken on the same challenge before. See this article how to export results when running selenium ruby webdriver scripts to output files from command prompt ruby window.
You may have to write up a rake file, but I believe it will be a good experience that will make you better acquainted with ruby and how to go about selenium testing with it.
run all selenium ruby webdriver scripts at a time.
You can use the rake gem
, for this you need to create a file named rakefile.rb
, and paste the below content:
task :default do
FileList['file*.rb'].each { |file| ruby file }
end
Now call rake
in your terminal, you should be good.
run some scripts in test suite with ruby rake on terminal window
Pass the test files you want to run as arguments of your rake task. How to pass arguments: How to pass command line arguments to a rake task
separate some selenum scripts by a space character to run them ruby rake
Rake will treat the second script as call to a task, so you need to group the arguments by enclosing them in quotes:
$ rake scripts='test1.rb test2.rb'
Then, you can call split
without arguments in your Rake task:
task :default do
if ENV['scripts']
scripts = ENV['scripts'].split
p scripts
end
end
This will produce:
$ rake scripts='test1.rb test2.rb'
["test1.rb", "test2.rb"]
Another option is to fiddle with the command line arguments yourself, and then dynamically defining tasks with the name of the command line arguments, so rake won't complain about missing tasks. I've extracted this into a method called with_args
here:
# expose command line arguments
def with_args &block
args = ARGV.dup
args.shift
block.call(args)
args.each{|arg| task(arg.to_sym) }
end
You can use it like this:
task :default => [:scripts]
task :scripts do
with_args do |files|
p files
end
end
And then invoke the rake task this way:
$ rake scripts test1.rb test2.rb
["test1.rb", "test2.rb"]
The initial idea came from this blog post.
run some scripts or all scripts in ruby rake
If I understand correctly, can you just use an if
statement?
task :default do
if ENV[scripts]
scripts = ENV[scripts].split(',')
FileList[scripts].each { |file|
system("ruby #{file} > #{directory_name}/#{file}.out")}
else
FileList['test*.rb'].each { |file|
system("ruby #{file} > #{directory_name}/#{file}.out")}
end
end
Print only numeric value from a string example (0 results returned) in Selenium
You can extract number using regex. For example,
String result="(0 results returned)";
String numericOnly= str.replaceAll("[^0-9]", "");
Related Topics
Upsert Multiple Records with Mongodb
How to Get Gmail Oauth or Xauth Tokens with Omniauth
How to Listen to Stdin Input Without Pausing My Script
Error Creating Rails Db Using Rake Db:Create
Ruby 'Gets' That Works Over Multiple Lines
Yaml::Load Raises Undefined Class/Module Error
How to Make a Ruby Enumerator That Does Lazy Iteration Through Two Other Enumerators
If 'Self' Is Always the Implied Receiver in Ruby, Why Doesn't 'Self.Puts' Work
Check If Folder Exist in S3 Bucket
What Is the Ruby Equivalent of the "This" Function in Java
Post Redirect Get Pattern in Rails
What Orm to Use in One Process Multiple Db Connections Sinatra Application
Ruby, Generate a Random Hex Color (Only Light Colors)
Gets.Chomp Without Moving to a New Line
Using Form_For Tag with Get Method
Can You 'Require' Ruby File in Irb Session, Automatically, on Every Command
Ruby on Rails. Bundler. Cucumber. Rake Aborted! Command Failed with Status (1)
Rails Form Object with Reform-Rails with Collections Not Working or Validating