browsermob-proxy-rb wit watir/selenium - ruby

I'm searching to figure out what to put on the the next line of code on https://github.com/jarib/browsermob-proxy-rb:
server = BrowserMob::Proxy::Server.new("/path/to/download/browsermob-proxy")
so what to put on /path/to/download/browsermob-proxy and where is it or how to download and put it there? I'm on windows xp trying to setup and make har file.

path can be found in folder of gems and in my case it is:
'C:/Ruby193/lib/ruby/gems/1.9.1/gems/browsermob-proxy-0.1.3/lib/browsermob-proxy.rb'

The Ruby Browsermob gem is a wrapper to control the proxy written in Java from your Ruby script.
You need to provide the path to the proxy executable, so that the gem can start the server for you.
Example:
browsermob_bin = "/path/to/browsermob-proxy-2.1.4/bin/browsermob-proxy"
server = BrowserMob::Proxy::Server.new browsermob_bin
server.start
You can dowload the proxy binary from here: https://github.com/lightbody/browsermob-proxy/releases

Related

Can I upload a directory to a remote node via watir-webdriver?

I have a cucumber test that uploads a directory by entering the directory path into the file field. It works perfectly fine when I run the test on my machine but I'm getting the following error when I try to run it against my selenium grid setup:
you may only upload files: "/cucumber_tests/temp/uploads/Cuke1477494492767281" (Selenium::WebDriver::Error::WebDriverError)
(eval):1:in 'process_watir_call'
Full backtrace:
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/bridge.rb:432:in 'send_keys_to_element'
/.rvm/gems/ruby-2.2.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/common/element.rb:146:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'block in send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:621:in 'element_call'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/element.rb:319:in 'send_keys'
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:24:in 'value='
/.rvm/gems/ruby-2.2.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/elements/file_field.rb:13:in 'set'
(eval):1:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'instance_eval'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:1052:in 'process_watir_call'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/platforms/watir_webdriver/page_object.rb:846:in 'file_field_value_set'
/.rvm/gems/ruby-2.2.0/gems/page-object-1.1.1/lib/page-object/accessors.rb:1021:in 'block in file_field'
My code pretty much looks like this:
#browser.file_field(id: "assets").send_keys "/cucumber_tests/temp/uploads/Cuke1477494492767281"
Again, I'd like to emphasize that this works perfectly fine on my machine but not on the remote node. Also, single file uploads are fine for me on both my machine and on the grid. I'm wondering if any of you have had luck uploading directories on remote nodes or know if it's even possible (even if I have to install more gems). Thanks in advance!
Try passing in the absolute path to the file:
File.expand_path("/cucumber_tests/temp/uploads/Cuke1477494492767281")
Unless you are trying to upload something from your local computer to a remote computer via Watir. That you can't do.
No, Selenium & Watir are not designed to upload directories. You could loop through files, but they wouldn't be in a subdirectory.
Dir["/path/to/files/*"].each do |file|
#browser.file_field(id: "assets").set File.expand_path(file)
#browser.form.button.click
end

Puppet: generate statement fails when trying to retrieve default path of an executable

I have built a stanza to remove a ruby gem package from our servers. The problem is that the ruby gem executable is installed in different paths on the servers, so on one server it could be in /opt/ruby/bin/gem on other servers it's in /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
My stanza uses the generate function in puppet to pull out the default ruby gem installation as follows:
$ruby_gem_location = generate('which', 'gem')
exec { "remove-remote_syslog":
command => "gem uninstall remote_syslog",
path => "$ruby_gem_location:/opt/ruby/bin:/usr/bin:/usr/sbin",
onlyif => "$ruby_gem_location list|grep remote_syslog"
}
When I run puppet agent I get the following error:
Generators must be fully qualified at ****redacted*
I have also tried to provide a default path for the which command as follows:
$ruby_gem_location = generate('/usr/bin/which', 'gem')
and now the error says : Could not evaluate: Could not find command '/usr/bin/gem
I checked the target server and the gem command is in
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
What am I doing wrong?
How can I pull out the default ruby gem location on our servers?
Thank you in advance
Your code
$ruby_gem_location = generate('/usr/bin/which', 'gem')
will generate a full path to your gem command (if it succeeds). From the result you describe, I think it is generating '/usr/bin/gem', which is perhaps a symlink to the real gem command. You are putting that into your command path instead of just the directory part, and that will not be helpful. It is not, however, the source of the error message you report.
The real problem here is that generate(), like all DSL fucntions, runs during catalog building. I infer from your results that you are using a master / agent setup, so generate() is giving you a full path to gem -- evidently /usr/bin/gem -- on the master. Since the whole point is that different servers have gem installed in different places, this is unhelpful. The actual error message arises from an attempt to execute your onlyif command with the wrong path to gem.
Your best way forward is probably to create a custom fact with which each node can report the appropriate location of the gem binary. You can then use that fact's value in your Exec, maybe:
exec { "remove-remote_syslog":
command => "$::ruby_gem_path uninstall remote_syslog",
onlyif => "$::ruby_gem_path list | grep remote_syslog"
}
Note that you don't need a path attribute if you give a complete path to the executable in the first place.
Details on creating the $::ruby_gem_path custom fact depend on a number of factors, and in their full generality they are rather too broad for SO, but PL provides good documentation.

Tell selenium to look in my C:/Downloads folder (Ruby)

me again!!
I have a question based around the download of a file. I was helped with setting up a Firefox profile to set a download to save a file directly without a pop up window. Now I need to tell Selenium to confirm that the said downloaded file is in my downloads folder on C drive to complete the test. Is there a way to do this? I've trawled for answers and have gotten nothing.
I first tried by setting a path like so on my env.rb file but didn't get very far with it:
$download_location = 'C:/Users/User/Downloads'
def download_location(path)
$download_location + path
end
Then telling cucumber to visit this location and confirm the name of the file.
Any help on pointing selenium to the location and confirming the name of a csv file would be hugely appreciated
Thanks
If you want to use ruby instead of selenium, you can use the exists? method to check the downloads directory for a given file, and it will return a Boolean result. For example:
File.exists?('C:\Users\User\Downloads\foo.txt')
I have found a solution that worked for me:
puts Dir["C:/Users/OSAT TESTING/Downloads/**/fleet_#{export}_export_all_*.csv"]
This confirmed the download of the file by looking in my downloads folder and returning the file path + name of any file that contained "fleet_#{export}_export_all_*.csv" in cmd prompt.
Thank you all for your help
:-)

Error trying to run Selenium with IE 8

I am getting the following error:
Unable to find standalone executable. Please download the IEDriverServer from http://code.google.com/p/selenium/downloads/list and place the executable on your PATH. (Selenium::WebDriver::Error::WebDriverError)
I have read the wiki on PATH but I'm still confused as to what this means for me. Where do I place the .exe in the scheme of my project?
wiki: http://en.wikipedia.org/wiki/PATH_(variable)
I am using selenium and cucumber to test a website
Here is my code
require 'selenium-webdriver'
#driver = Selenium::WebDriver.for :ie
You need to download the IE driver from the downloads page, then include the path to the file (example : C:\Users\megaxelize\Desktop)i.e. the location where you have downloaded the IEdriver, in your environment path.
This is the way to update your env path vairable
Path specifies the directories in which executable programs are located on the machine that can be started without knowing and typing the whole path to the file on the command line.
More info here
You need IEDriverServer, which you can download from seleniumhq.org.Once your download is complete either you can mention the path to IEDriverServer.exe against your path variables (for which you need Admin access) or you can provide path to IEDriver.exe at command prompt using
java -Dwebdriver.ie.driver=E:\selinum\IEDriverServer_Win32_2.32.3\IEDriverserver.exe
or U can set system property in your script if you use Java using :
File file = new File("E:\\selinum\\IEDriverServer_Win32_2.31.0\\IEDriverServer.exe");//if this is the location of your IEDriverServer.exe
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
Download IEDriverserver
Extract the zipped folders and add them in Environment Variables path.
My Computer > (right click) properties > Advanced system settings > Environment Variables
Click path under system variables and choose Edit.
Paste the Driver location.
#driver = Selenium::WebDriver.for :ie
or|
#driver = Selenium::WebDriver.for :internet_explorer

How to setup mod_lua in Apache to access third party Lua modules?

I'm attempting to set up mod_lua module for Apache, but have encountered difficulty regarding accessing third party Lua modules. Say I have a hello_world.lua in Apache's htdocs folder that has something like this:
require "apache2"
function handle(r)
r.content_type = "text/html"
r:write "Hello World from <strong>mod_lua</strong>."
return apache2.OK
end
And I go to "http://localhost/hello_world.lua", that will function as expected. But if I try to add a line such as:
require "socket"
Or
require "cgilua"
I get the following output:
Error!
attempt to call a nil value
However, some modules do work, such as:
require "base"
That functions as expected.
If I navigate to base.lua in the filesystem (c:\program files\lua\5.1\lua\base.lua) and remove this file, then attempt to run my script I get the same error as stated above. So this must be the directory that mod_lua is checking for modules. Modules dlls are not in this folder, instead they are in c:\program files\lua\5.1\clibs\, which I set up the environment variable LUA_CPATH to point to.
Luasocket and cgilua are both present in this folder, yet they cause an error when I try to require them in my script.
From what I can gather, it works fine with any pure lua modules, but anything that has cmodules as well (socket, etc) causes problems.
Additional info:
OS: Windows 7 Home Premium
LUA_PATH = c:\program files\lua\5.1\lua\
LUA_CPATH = c:\program files\lua\5.1\clibs\
Apache version: 2.2.22
mod_lua version: http://www.corsix.org/content/mod-lua-win32#comment-3214
What needs to be done to be able to require modules in scripts run by mod_lua?
It looks like you need to add LuaPackageCPath and/or LuaPackagePath directives to your site configuration (in the global configuration file, or .htaccess, ...).
In your case, I'd assume that
LuaPackagePath c:\program files\lua\5.1\lua\
LuaPackageCPath c:\program files\lua\5.1\clibs\
should do the trick.

Resources