Understanding the Framework of Automation with Ruby and Cucumber - ruby

Can someone explain or send me some material so I can understand the meaning of each directory in this structure?
specs = I understand
step_definitions = I understand
support\env = I have doubts
cucumber.yml = I have doubts
Rakefile = I have doubts
Helper.rb = I have doubts

Related

We are using jekyll for building our static site and plugins in ruby . How to write unit test cases for them?

Our plugins are written in ruby , want to write unit test cases for them but most of our function use site data .
My question how to access the site data in rspec?
Example function:-
def getTranslatedTitle(input , url , title)
site = #context.registers[:site]
globalmeta = site.data['global-meta']
i18n_folder = site.data['i18n']
return title
end
How to access the #context.registers when we run bundle exec rspec ?

osquery extension in Ruby - create new table

I'm trying to implement an extension for osquery in Ruby.
I found some libs and examples doing the same in Java, Node and Python, but nothing helpful implemented in Ruby language.
According to this documention, it's possible generating the code using Thrift: https://osquery.readthedocs.io/en/stable/development/osquery-sdk/#thrift-api
The steps I did, so far:
Generated the code using thrift -r --gen rb osquery.thrift
Created a class and some code to connect to the server and register the extension
This is the code of the class
# include thrift-generated code
$:.push('./gen-rb')
require 'thrift'
require 'extension_manager'
socket = Thrift::UNIXSocket.new(<path_to_socket>)
transport = Thrift::FramedTransport.new(socket)
protocol = Thrift::BinaryProtocol.new(transport)
client = ExtensionManager::Client.new(protocol)
transport.open()
info = InternalExtensionInfo.new
info.name = "zzz"
info.version = "1.0"
extension = ExtensionManager::RegisterExtension_args.new
extension.info = info
client.registerExtension(extension, {'table' => {'zzz' => [{'name' => 'TEXT'}]}})
To get the <path_to_socket> you can use:
> osqueryi --nodisable_extensions
osquery> select value from osquery_flags where name = 'extensions_socket';
+-----------------------------------+
| value |
+-----------------------------------+
| /Users/USERNAME/.osquery/shell.em |
+-----------------------------------+
When I try to get this table using osqueryi, I don't see the table when I run select * from osquery_registry;.
Have anybody by any chance implemented an osquery extension already? I'm stuck and I don't know how to proceed from here.
I don't think I've seen anyone make a ruby extension, but once you have the thrift side, it should be pretty simple.
As a tool, osquery supports a lot of options. So there's no single way to do this. Generally speaking, extensions run as their own process and the communicate over that thrift socket.
Usually, they're very simple and osquery invokes extensions directly with appropriate command line arguments. This is alluded to in the doc you linked with the example accepting --interval, --socket, and --timeout. If you do this, you'll want to look at osquery's --extensions_autoload and --extensions_require option. (I would recommend this route)
Less common, is to start osquery with a specified socket path using --extensions_socket. And then your extension can use that. This way is more common is the extension cannot be a simple binary, and instead is a large complex system.
I find myself playing around with thrift via ruby. And it seems to work if I used a BufferedTransport:
socket = Thrift::UNIXSocket.new('/tmp/osq.sock')
transport = Thrift::BufferedTransport.new(socket)
protocol = Thrift::BinaryProtocol.new(transport)
client = ExtensionManager::Client.new(protocol)
transport.open()
client.ping()
client.query("select 1")

DEPRECATION: HTTParty will no longer override `response#nil?`. What does this Deprecation warning mean?

This question is probably poorly structured so please bear with me, I'm new at this.
I'm trying to build a simple web scraper but every time i run my code i get this warning in terminal. I have tried to follow the link to the github issues hoping i would get a clearer explanation but i didn't understand it there either. Tried googling, but nothing there either.
[DEPRECATION] HTTParty will no longer override `response#nil?`.
This functionality will be removed in future versions.
Please, add explicit check `response.body.nil? || response.body.empty?`.
For more info refer to: https://github.com/jnunemaker/httparty/issues/568
I guess what i want to know is, in basic terms, what does this warning mean? and is there something i should do different from now on when using the HTTParty gem?
This was annoying me as well. You are probably passing the response from HTTParty.get to some other code that is testing for nil. I was passing the body to Nokogiri::HTML and that code was eventually calling HTTParty.response.nil?. To fix, I started sending the "body" to Nokogiri instead of the response object. Quite a few people will probably run into this as the Nokogiri example code with this pattern is all over the place.
I now use this:
doc = HTTParty.get('https://some/site')
parsed ||= Nokogiri::HTML(doc.body)
instead of before when getting the warning it was:
doc = HTTParty.get('https://some/site')
parsed ||= Nokogiri::HTML(doc)
url = "https://www.startech.com.bd/laptop-notebook/laptop"
unparsed_page = HTTParty.get(url)
parsed_page = Nokogiri::HTML(unparsed_page)
I was facing same error as yours
[DEPRECATION] HTTParty will no longer override `response#nil?`. This functionality will be removed in future versions. Please, add explicit check `response.body.nil? || response.body.empty?`. For more info refer to: https://github.com/jnunemaker/httparty/issues/568
/home/abir/.rvm/gems/ruby-2.7.2/gems/nokogiri-1.11.1-x86_64-linux/lib/nokogiri/html/document.rb:209:in `parse'
So changed the code as Jeremy Mullin said and it is working fine now.
url = "https://www.startech.com.bd/laptop-notebook/laptop"
unparsed_page = HTTParty.get(url)
parsed_page = Nokogiri::HTML(unparsed_page.body)

What's the best practice to store variables for Cucumber tests?

What's the best practice to store variables for Cucumber tests?
I'm using Cucumber and Capybara to test a Java application.
In the application there are many types of users and other data that I need to pass into my Capybara step definitions. So my question is what is the best practice to store these variables/users IDs?
I do have some variables (#instance_variabless) that I've stored all in the env.rb file.
But is there a more clean/elegant way to do this? Like have a dedicated file just for variables that I can call, if so how would such a file be setup?
Please provide examples of solutions?
You can use hooks for set-up and tear-down in hooks.rb file:
#user_ids_and_passwords = YAML.load(File.open('features/config/users.yml'))
#my_heavy_object = HeavyObject.new
#my_heavy_object.do_it
at_exit do
#my_heavy_object.undo_it
end
AfterConfiguration do |config|
puts "Features dwell in #{config.feature_dirs}"
#instance_variable = 'my variable'
end
Before('#some_features') do
#feature_instance_variable = 'something else'
end

Data Driven Testing with Ruby's Test::Unit for Selenium

I'm pretty new to both Ruby and Selenium and I'm just trying to figure out the best way to build my test harness. I'm using Rake, Rake::TestTask, and Test::Unit to power this. I have a suite that I'd like to run once for each browser/os combination. I can't figure out how to parameterize my tests though, something I've become accustomed to with Junit4 and TestNG.
require 'rake'
require 'rake/testtask'
browsers = ['IE on Windows', 'Firefox on Windows', 'Firefox on Mac', 'Safari on Mac']
task :default => [:run_tasks]
task :create_tasks do
browsers.each do |browser|
Rake::TestTask.new("selenium_units:#{browser}") do |t|
t.libs << "lib"
t.pattern = 'test/*_test.rb'
t.verbose = true
t.warning = true
t.opts = "BROWSER=\"#{browser}\""
end
end
end
task :run_tasks => [:create_tasks]
task :run_tasks => browsers.map { |e| "selenium_units:"+ e }
I'd really like to be able to read that BROWSER= in the setup of my Suites or Cases. Any suggestions or is there plainly a better way of doing this in Ruby?
After a lot of digging through the source I found a not so documented feature. The Test::Unit test runner doesn't do anything besides executing your test cases on the commandline relying on an autorunner to run any case cases of that class specific class. So, when they say anything after -- will be passed as options, they mean command line options, not some variable or parameter.
so...
adding
t.options = '-- -foo -bar=baz'
Will actually pass those into your ARGV and you are expected to process them manually. Taking those args and throwing them into a factory class to grab the appropriate Selenium instance will work for me.
This may not be what you are asking. But I've solved the exact same problem in Python and blogged about it in
Parameterizing Your Tests. I am sure you can use the same approach in Ruby, not sure how it compares with what you've done. I am interested to know how others have solved this problem though, and haven't found much documentation.

Resources