I am new here. Is there any way to use headless in windows? I tried but it says :
:/Ruby193/lib/ruby/gems/1.9.1/gems/headless-1.0.1/lib/headless/cli_util.rb:4:in ``': No such file or directory - which Xvfb (Errno::ENOENT)
Please help...
Headless Tests in "WINDOWS7" using WATIR? You can use phantomjs which is super easy to configure.
Follow these easy steps:
Download phantomjs from here
Extract to desired folder, once extracted you just need phantomjs.exe
Now where ever you instantiating the browser, use it like this:
phantom_dir = "location of phantomjs.exe"
ENV['PATH'] = "#{ENV['PATH']}#{File::PATH_SEPARATOR}#{ghost_dir}"
browser = Watir::Browser.new :"phantomjs"
To run headless on other OS follow easy steps here
You have to run it on a linux box. Xvfb doesn't exist in Windows or Mac
Related
I ran a bundle update yesterday night and selenium-webdriver got updated to the latest version.
My watir-webdriver tests pointed to firefox are now broken.
The error message said to add geckodriver to the path. On my mac, I copied geckodriver to the /usr/bin and ran the tests again.
This is the error I am getting now
unable to connect to Mozilla geckodriver 127.0.0.1:4444 (Selenium::WebDriver::Error::WebDriverError)
The watir-webdriver documentation does not seem to be updated on how to do this?
Did anyone manage to fix this
There is no extra documentation because there is nothing extra to do with Watir. It's finding the geckodriver file , but can't run it. Check to make sure it is executable on your system.
If your test not only just stick to firefox, you can use chromedriver instead of geckodriver, which is much easy, as far as my experience goes.
1, Add gem watir to your gemfile.
2, Download file on this page https://sites.google.com/a/chromium.org/chromedriver/downloads, and copy chromedriver to /usr/bin path.
3, And then just run it:
browser = Watir::Browser.start(url)
html = Nokogiri::HTML.parse(browser.html)
browser.close
4, Also, you can use headless to start a virtual X screen to hide browser windows like this:
headless = Headless.new
headless.start
browser = Watir::Browser.start(url)
html = Nokogiri::HTML.parse(browser.html)
browser.close
headless.destroy
Is there a way I could confirm the download process of a file when using selenium-webdriver with cucumber/ruby?
When running headless, I use a simple rspec-expectation expect(response_headers['Content-Disposition']).to include("attachment;filename#{pdf_filename}")
When I run in Selenium (Chrome), this no longer works. I get the error:
Capybara::NotSupportedByDriverError: Capybara::Driver::Base#response_headers
Is there a way I can achieve this when running through Selenium?
You can check if the file you expected is present in the download directory:
File.exists? "/Users/mesutgunes/Downloads/#{pdf_filename}"
I know there is a documentation from CasperJS website about how to install CasperJS on Windows, but bear with me these guys only explained for the pros only.
If you are new to all this CasperJS and PhantomJS world, you dont stand a chance to understand not even spending two days trying to search the net for a better explanation.
I am working on a project that requires a screenshot of each website listed on my project website, looking around i found out that PhantomJS would be great for this task (website screenshot).
I downloaded PhantomJS and and pasted its phantomjs.exe file in system32 which is working well when i use cmd.exe to send command.
I even managed to grab screenshot with the phantomjs.exe only. but my problem came when i noticed the the workload could be easier when these two work together (CasperJS and PhantomJS) as i can even be able to reduce the size of the screenshot when using CasperJS.
In fact the only use that i want CasperJS for is the limiting of the shot size but since yesterday i have been trying to figure out how to make CasperJS work on Windows but with no avail.
I have downloaded CasperJS and tried to install it in many ways also trying to follow the documentation but nothing.
I changed the CasperJS folder name from its download name to CasperJS as the documantation suggest but when i check in the cmd trying to call some commands, nothing happens.
Anyway to cut the story shot can anyone help me in simple terms considering that i am a newbie to explain how CasperJS can be installed on window or if possible with PhantomJS only how can i re-size the iamge the the program produces lets say if i want a 960 to 400px.
Poor documentation for windows. http://casperjs.org/installation.html#windows
It starts off assuming you have already installed without telling you how to install.
So here it is if anyone else is confused about this. There is no actual install. It's just extracting zip contents to the right place.
download phantomjs for windows from the phantomjs site (it's a zip with binary inside)
extract the contents to C:\phantomjs
download the casperjs zip file from the casperjs website
extract the contents to C:\casperjs
Now you can add the following to the end your system or user PATH variable
;C:\phantomjs;C:\casperjs\batchbin
restart cmd.exe to pick up the new path variable or logout/login if you are running Console2 or Conemu terminal emulator (they won't pick up new paths by a simple close and re-open)
Now in the docs it says to run it like this
casperjs.bat myscript.js
Actually since both phantomjs.exe and casperjs.bat are now in the system PATH you can leave off the extension like this.
casperjs myscript.js
And when running phantomjs.exe just run
phantomjs
One more thing. It really doesn't matter where you install as long as you add that path to the system PATH. I installed to C:\usr\phantomjs and C:\usr\casperjs.
I itemize below the method that has served my needs on both my personal Windows and Ubuntu work PC. DO note that my method doesn't fiddle with PATH settings but involves a command you could save somewhere & copy and paste as needed:
Step 1: Gather the prerequisites
Download the casperjs and phantomjs versions you want to use
Make a directory to contain the things I want to list
Extract the downloaded phantomjs & copy its executable into the directory of step b
Extract casperjs and rename its folder to casperjs
Copy the renamed casperjs folder to the directory of step b
Create and save a file config.json to the directory of step b
config.json should contain phantomjs configurations as found here: http://phantomjs.org/api/command-line.html
Step 2: Running your script
Whenever you want to work with a file, follow the Step 1 details above
The next step assumes that you are in the directory created in step
b of Step 1 also have a file named first.js
On Windows: phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js
On Ubuntu: ./phantomjs --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js
Experimental config.js and first.js are listed below:
config.json
{"sslProtocol": "any", "cookiesFile": "biscuit", "maxDiskCacheSize": 1000, "diskCache": true}
first.js
var casper = require('casper').create({
pageSettings: {
loadImages: false,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
}
});
var url = "http://casperjs.org/";
casper.start(url).wait(60 * 1000 * 1, function() {
casper.echo('1 min has passed');
casper.capture('casperjs.png');
casper.exit();
});
casper.run();
Addendum: download and save the details of screenshots.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli screenshots.js http://phantomjs.org
Run Tests: download & save the details of picturefill-test.js and run it as
phantomjs.exe --config=config.json casperjs/bin/bootstrap.js
--casper-path=casperjs test --cli picturefill-test.js
As of CasperJS 1.1.0-DEV Beta 3 you should use this PATH: C:\casperjs\batchbin even though the documentation found here states you need to use C:\casperjs\bin
The reason to this is because C:\casperjs\batchbin includes a .BAT which C:\casperjs\bin does not include anything except some.js files.
after a 3days work, i managed to get it work the problem was with the path and the installation of phantom. i had made the path to a folder but the installation was pointing to the exe file all i had to do was to put the exe file into a folder phantomjs and that was it thank for your help all.
Many of the other answers are out of date. Since it seems like the correct install process keeps changing all the time, I suspect my answer will be out of date also in a few days, but as of March 19, 2015, this is the answer. The other answers, even highly upvoted ones, do not work, so don't waste your time. Good luck. Casperjs seems quite good.
If you download PhantomJS 2.0 and casperjs 1.1-beta3 zip file and put the batchbin directory in the path and put phantom exe in that same folder, then run casperjs, on Windows 8.1 I get the error "CasperJS needs PhantomJS v1.x".
So, I got the latest casperjs direct from github, which has no batchbin directory, so I put just the C:\casperjs\bin directory in the path instead and this worked (sort of, I mean it seems to work well enough for me - although running casperjs c:\casperjs\tests\selftest.js seems to have a number of failing tests).
So to recap, the bad news is only the very latest bleeding edge casperjs works. The good news is the install is 1,2,3 simple:
Clone latest casperjs from github into c:\casperjs.
Copy phantomjs.exe (ver 2.0) to c:\casperjs\bin
Add c:\casperjs\bin to your windows path
Just in case you're using a notebook with dual graphic cards like I do: choose one of them to prevent issues. This article helped me out:
casperJS not finishing on windows
the casperJS documentation is pretty clear about it but I had no clue what to do until I read the notice above.
Fast forward to 2015... 5-steps win7 howto:
choco: PS me> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
git: choco install git -y
phantomjs 2.0: choco install phantomjs -y
casperjs source: git clone https://github.com/n1k0/casperjs -b phantomjs-2
Add the location of casperjs/bin to PATH
Done. You can now casperjs --version and live happily ever after.
Ok guys. So I think this thread needs refreshing for 2018!
So with npm, the effort is reduced significantly. Given that you have npm installed, open terminal and go to your project:
cd your_project_name
Now install casperjs. Use --save-dev, --save, -g or none as needed:
npm install --save-dev casperjs
Now install phantomjs. To do this, you should install phantomjs-prebuilt, because PhantomJS team changed their package name:
npm install --save-dev phantomjs-prebuilt
Run your spec:
casperjs your_spec_name.js
IS there any way in Ruby to open a local HTML file in the user's default web browser? I could do something like:
system("open /path/to/file.html")
But that would only work on Mac OS X. Are there any solutions that work on any platform?
You can use the launchy gem.
First, install the gem:
$ [sudo] gem install launchy
Then, in your ruby code:
require 'rubygems'
require 'launchy'
Launchy::Browser.run("/path/to/file.html")
I think you will have to do system specific calls.
system() is like writing the command on the local system command line (that's my understanding anywayz)
I can't do what you have done on Windows 7. I have to call explorer and it opens in my default browser.
Windows 7 Example: (opens in Chrome, my default browser)
system("explorer file:///C:/path_to_file")
Note: I needed to put file:/// at the start otherwise it opens in Explorer instead of the browser.
I know it's not desirable, however worst case, you can check the value of RUBY_PLATFORM. This returns the operating system platform.
Semi-Pseudo Code:
cmd = case RUBY_PLATFORM
when /darwin/
"open /path/to/file.html"
when /windows/ #fix this, I'm not sure.
"explorer file:///C:/path_to_file"
else
"default"
end
system(cmd)
I am trying to automate my Chrome extension building process on OSX 10.5.
I am unable to find a similar command for OSX like this for Windows
chrome.exe --pack-extension=c:\myext
--pack-extension-key=c:\myext.pem
Is it even possible on OSX? As there is no mention of it in the documentation.
Please guide me.
Thanks in advance.
-Parimal Das
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --pack-extension...
Use the CRXMake gem.
Have a great day.
A complete example to run on the shell:
"/Users/varr/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --pack-extension="/Users/varr/Dropbox/Code/Projects/Bookmark Express/src"
Things to note:
Chrome will not display any output of success or failure but it will return an exit code
Your shell (ex. oh-my-zsh) may display exit codes so you can have an idea there
Chrome will generate two files, the .crx and a .pem
To automate this, I used Geb (and Groovy). In GebConfig.groovy, I tried using:
def chromePath = "/Users/varr/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
def packExtensionSwitch='--pack-extension="/Users/varr/Dropbox/Code/Projects/Bookmark Express/src"'
ProcessBuilder packExtension = new ProcessBuilder(chromePath, packExtensionSwitch)
Process process = packExtension.start()
But this returned an exit code 21 every time and no files were generated. I finalized my approach with:
def packageExtensionScript = '/Users/varr/package.sh'
ProcessBuilder packExtension = new ProcessBuilder(packageExtensionScript)
Process process = packExtension.start()
To finish it up, I made package.sh a one-line script with the command to run and it all worked!
You can use A node.js command line app for packing Google Chrome extensions too. Enjoy!