run all selenium ruby webdriver scripts at a time. - ruby

Currently, I'm running each my Selenium Ruby Webdriver script (*.rb) on Ruby command prompt window with the syntax, ex: ruby test.rb. It works well.
However, I also have some other scripts and now I want to run all scripts once instead of calling ruby test1.rb, then wait for this script done, then continue to run: ruby test2.rb.....then, ruby test3.rb.....
Anybody please guide me a way to run all scripts I created at a time? Thanks so much.

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.

What about making a feature file and running the entire feature?

Just create a ruby file like this:
require './Test1.rb'
require './Test2.rb'
Run it and see the result

Related

Automatically load Dotenv on my ruby console

I'd like to automatically run Dotenv.load('.env.development') whenever I launch up a ruby console, it could either be from bundle console or alternatively irb. I'm using Sinatra, not Rails, and I'm not sure how to run some commands on console start.. I'd prefer to do this without a bash script, instead using the internal capabilities of the tools.. If there's a place to put ruby code on the start of a ruby console that would solve my issue and also allow for future console customization.
You can create a .irbrc file in our project's directory which is loaded automatically when an IRB session is started. And add something like this to that file:
begin
require 'dotenv'
Dotenv.load('.env.development')
rescue => e
puts "loading Dotenv failed. because: #{e.message}"
end
Read more about the .irbrc file in the Ruby-Docs.
You try folliwing the documentation of gem(sorry my ignorance I don't know anything about sinatra)?:
Documentation dotenv
Install the gem:
$ gem install dotenv
By default, load will look for a file called .env in the current working directory. Pass in multiple files and they will be loaded in order. The first value set for a variable will win.
require 'dotenv'
Dotenv.load('file1.env', 'file2.env')
In your case i think should be:
require 'dotenv'
Dotenv.load('.env.development')
In ruby vanilla I dont know if possible, I think yes.
One option is to creating a ./bin/console script ala Bundler's gem.
I created this bin/console file as a temporary solution, but I'm curious whether I can get #spickermann's answer (which I incorporated here) with irbrc to work with a same-directory .irbrc
#!/usr/bin/env ruby
begin
require 'dotenv'
Dotenv.load('.env.development')
rescue => e
puts "loading Dotenv failed. because: #{e.message}"
end
require "irb"
IRB.start(__FILE__)

How to start Rack application with frozen string literals?

I'm trying to run our application under ruby 2.3 using the new ruby feature for automatic frozen strings turned on globally. (Ruby 2.3) This is normally done by passing the argument to a ruby script when starting as follows:
ruby --enable-frozen-string-literal ruby_code_file.rb
Unfortunately, our application is started using rackup, and I've tried the following command:
rackup --enable-frozen-string-literal
But this does not appear to work. How do I pass that parameter into Rack?
You can't pass parameters for ruby to rackup, unfortunately. However, rackup is really, really simple:
#!/usr/bin/env ruby
require "rack"
Rack::Server.start
The simplest solution, then, is to duplicate this file in your project (in, say, bin/frozen_rackup) but change the first line to this:
#!/usr/bin/env ruby --enable-frozen-string-literal
Then make sure the file is executable (chmod u+x bin/frozen_rackup) and run bin/frozen_rackup instead of rackup.
P.S. I'm guessing that --enable-frozen-string-literal doesn't apply to gems your script requires, since it would break a lot of gems, but I haven't tested this and YMMV.

running file ruby on whenever/crontjob ruby

how to running file ruby in whenever, in this case i'm not using rails. If in example rails code, i'm only must running this code and it's work :
example in rails :
every 3.hours do
runner "MyModel.some_process"
end
but if i want to running file with extenstion .rb without rails, how do that :
example similiar code like this :
every 3.hours do
runner "ruby test.rb"
end
thanks before
Use command instead of runner:
every 3.hours do
command "ruby test.rb"
end
Hope this helps.

Executing a .rb file (Ruby file) with PRY in Windows 7

I was wondering how I can load a Ruby file into PRY to use the debugger function on my Windows 7 computer with Command Prompt. I want to use PRY to go through my program step by step and following the tutorials online on how to do it aren't working for me (probably because all of them are using Mac Terminal)
I use SublimeText 2 to write everything up and then save it as a .rb file and I was told that if I wanted to debug the file I just made, I need to run it through IRB or PRY. Not, I already ran "gem install debugger". And the Ruby I have installed is 1.9.3 - p545. Do I need to add an extra line of code that says "binding.pry" (I saw that in some of the samples that I could find on stackoverflow). All I'm looking for is a simple step-by-step process. Thank you for reading this, I look forward to the responses.
Make sure you've installed pry and pry-debugger gems
At the top of your file, add statements for require 'pry' and require 'pry-debugger'
In your code, wherever you want to start ddebugging, just add a statement binding.pry
Now, you can run your file like ruby filename.rb and the debugger should open

Making executable file from Ruby program

I wrote a program in Ruby but I want to make an executable file from my program in order to run it in any computers( that they don't have ruby).How can I make executable file?
thanks
You could use RubyScript2Exe
http://www.erikveen.dds.nl/rubyscript2exe/
.. it collects all necessary files to run your application on an other machine: the Ruby application, the Ruby interpreter and the Ruby runtime library (stripped down for your application)
You should look at this list of options given your needs:
http://ruby-toolbox.com/categories/packaging_to_executables.html
They all have their strengths and drawbacks. NOTE: I have not used any of them.
Take a look on my rb2exe. It supports Rails and Gemfile.
gem install rb2exe
echo "puts 'Hello world'" > test.rb
rb2exe test.rb
./test
You can also check my detailed step-by-step how to, here:
http://www.learnwithdaniel.com/2016/08/ruby-to-portable-exe-app/

Resources