date · Ruby · Ruby 1.9

Date @ Ruby — In between dates during particular interval

Code:

require ‘date’

def check_weeks(dd1,dd2)
i=0
while dd1 <= dd2
dd1=dd1+0
if dd1+@interval < dd2
dd3=dd1+@interval
else
dd3=dd2
end
puts “Week from #{dd1} to #{dd3}”
dd1=dd3+1

i+=1
end
end

x=”2014/07/01″
y=”2014/07/30″

d1= Date.new(x.split(“/”)[0].to_i, x.split(“/”)[1].to_i,x.split(“/”)[2].to_i)
d2= Date.new(y.split(“/”)[0].to_i, y.split(“/”)[1].to_i,y.split(“/”)[2].to_i)

#Chnage the interval
@interval = 2

check_weeks(d1,d2)

 

Output:

 

>ruby helper.rb
Week from 2014-07-01 to 2014-07-03
Week from 2014-07-04 to 2014-07-06
Week from 2014-07-07 to 2014-07-09
Week from 2014-07-10 to 2014-07-12
Week from 2014-07-13 to 2014-07-15
Week from 2014-07-16 to 2014-07-18
Week from 2014-07-19 to 2014-07-21
Week from 2014-07-22 to 2014-07-24
Week from 2014-07-25 to 2014-07-27
Week from 2014-07-28 to 2014-07-30
>Exit code: 0

 

Change the @interval = 2 to any interval and implement it in your code

 

 

 

 

 

 

Blogroll

rubyzip — Ruby gem to zip the folder and files

rubyzip — Ruby gem to zip the folder and files

Requirement:

Zip the file for some folders and files

 

Steps:

1. Create a folder chrome and put some files in it.

2. create a ruby file in same location and paste the below code

a. >gem install rubyzip

def zip_it(path)
require ‘rubygems’
require ‘zip/zip’
require ‘zip/zipfilesystem’

path.sub!(%r[/$],”)
archive = File.join(path,File.basename(path))+’.zip’
FileUtils.rm archive, :force=>true

Zip::ZipFile.open(archive, ‘w’) do |zipfile|
Dir[“#{path}/**/**”].reject{|f|f==archive}.each do |file|
zipfile.add(file.sub(path+’/’,”),file)
end
end
end

zip_it(“chrome”)

3. save and run the ruby file.

4. Zipped file will be created with in the chrome folder.

Blogroll

Running Watir webdriver scripts in Browser Stack Environment

Running Watir webdriver scripts in Browser Stack Environment

Why it is required?:

If we need to run the scripts in more than 5 machines with different OS and browser versions then we may need to invest more in infrasturure. To aviod this, we will have Test server in Browserstack.

 

1. Create trail account in http://www.browserstack.com/

2. Copy the Authentication URL from your acoutn page

3. Run the below code

require ‘rubygems’
require ‘watir-webdriver’

include Selenium

caps = WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
caps.platform = :WINDOWS
caps[:name] = “Watir WebDriver”
caps[:browser] = “chrome”
caps.version = 20
caps[“browserstack.debug”] = “true”
caps[“browserstack.tunnel”] = true

browser = Watir::Browser.new(:remote,
:url => “PASTE BTASCK URL HERE”, # Sample http://raveendran:x6XqqrJzJ9gUZ7sr@hub.browserstack.com/wd/hub
:desired_capabilities => caps)

browser.goto “http://google.com/&#8221;

sleep 9 # You should use wait methods instead of sleep
puts browser.title
browser.quit

Pros:

Easy implementation with any exisitng framework

Cons:

The execution speed will be 2x~3x slow when comparing with your local machine execution.

Automation · Blogroll · firefox · QA · selenium · Selenium-webdriver · watir-webdriver

Watir / Selenium Web Driver – Browser Downloads — Solution to download pdf files automatically in firefox 20+ version

 

Solution to download pdf files automatically in firefox 20+ version using Selenium webdriver or Watir webdriver

 

Description:

I have tried to save PDF files automatically using the below link — http://watirwebdriver.com/browser-downloads/  and I have followed the same as per the mentioned page and reference website. But still the firefox browser not downloaded PDF files automatically.

Reason:

In Firefox latest versions, They have added new function called as ‘Portable Document Format’ which causes the issue

Solution:

Please try the below code for latest firefox versions.

download_directory = "#{Dir.pwd}/downloads"

download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2 # custom location
profile['browser.download.dir'] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"

profile[‘pdfjs.disabled’] = true
profile[‘pdfjs.firstRun’] = false

b = Watir::Browser.new :firefox, :profile => profile
Note:
profile[‘pdfjs.disabled’] = true
profile[‘pdfjs.firstRun’] = false
These 2 lines are added. Thats it 🙂
FF bookmarks

Ruby-hpricot –>Firefox bookmark url’s from bookmark.html file

jazzez-FFbookmark-urls.exe

1. Download “jazzez-FFbookmark-urls.exe” from — http://bit.ly/j_ffb

2.Export bookmarks.html from firefox browser

For Example,

a. click “Bookmarks” tab in FF browser

b. Click “Organize Bookmarks ”

c. Click “Import and backup” tab

d. Click “Export HTML”

e. Save the file in same path where “jazzez-FFbookmark-urls.exe” is placed

3.  Run the exe

4. check the output file “bookmarks.txt” file.

Jazzez

Jazzez

Hi Everybody,

Many of them asking to me What is the meaning of “Jazzez” . This is the time to publish the description about Jazzez.

1. Why you put title “Jazzez” for your blog?

Jazzez is my gang name in college life.

2. What is the meaning of “Jazzez”?

ya. good question. Come with me. In my college life, My gang named as “meaningless group” by Lecturers. So, Our friends decided to put a meaningless name for our gang. At that time our gem “Lakshu” gave an idea and also suggest the meaningless name “Jazzez”. So simply meaning of “Jazzez” is meaning less.

3. What is the status of Jazzez members? why u use that word in ur Technical blog?

Now all the meaningless members are becomes to a meaningful professionals. We all are growing day to day life. Now We all are meaningful except our gang name “Jazzez” . So, This is the try to make “Jazzez” is also a meaningful word. Then only I am using the word “Jazzez” in my technical blog. Nothing is impossible right?……….

4. Who are the members in “Jazzez” group?

*Laksmanan * Muthuselvan *Kesavan *Raveendran * Vijayakumar *Pandiaraja * Gopi *Vinayaga Moorthi * Silvan Ananiya * Marichamy *Gopala Krishnan *Muthukumar *Saravanakumar *Senthil kumaran *Bala subramanian *Ram Prasath *Peppin Shaju *Uma kanthan *Jayakanth *Dinesh ….

Our Gang members…

bench

We are not forgot the path which one is past………

At temple

Mari & myself


Regards,

P.Raveendran

Me