Wednesday, 25 February 2015

How to fail a test in selenium with Ruby and Cucumber

fail 'message to display in console'

This will fail the test when executed.

Saturday, 14 February 2015

Filesystem in Ruby - accessing parent files based on current folder/file path


puts File.expand_path(File.dirname(__FILE__) + "/../src/google_finance.rb")
puts File.dirname(__FILE__)

puts File.expand_path(File.dirname(__FILE__) + "/../../data")

#Webser            -- Root folder
#  +--data          --folder
#  +--sample         --folder
#    +--lib
#    +--src
#         +--google.rb
#         +--testing.rb
#    +--config.rb 
 

#to access data folder:
puts File.expand_path(File.dirname(__FILE__) + "/../../data")
#Output: C:/Users/user/workspace/WebservicesTest/data

#to access current folder:
puts File.dirname(__FILE__)
#C:/Users/user/workspace/WebservicesTest/sample/src

#to access google.rb file from testing.rb file:
puts File.expand_path(File.dirname(__FILE__) + "/../src/google_finance.rb")
#C:/Users/user/workspace/WebservicesTest/sample/src/google_finance.rb

#WE CAN REQUIRE LIKE THIS AS WELL
#require File.expand_path(File.dirname(__FILE__) + "/../lib/wrest")

Thursday, 12 February 2015

get parent or sibling folder/file based on current file location

def create_temp_file()
  @temp_fpath= ''  begin    @temp_fpath = File.absolute_path('..\src\features\data\tempfile.txt')
    create_file(@temp_fpath, 'Sample text')
  rescue Exception => e    puts e.message
  end  @temp_fpathend

rest client chrome/firefox plugins

Advance Rest Client
DHC Rest client
RestClient

Ruby Rest Service: get all the tags - api.del.icio.us api

require 'net/https'
http= Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
http.start do |http|
  req=Net::HTTP::Get.new('/v1/tags/get') 
  req.basic_auth 'myusername', 'password'
    @resp= http.request(req)
end

puts @resp.body

Output:
<?xml version="1.0" encoding="UTF-8"?>
<tags>
  <tag count="1" tag="!fromtwitter"/>
  <tag count="1" tag="social"/>
  <tag count="1" tag="ecommerce"/>
   <tag count="1" tag="flipkart"/>
</tags>


links:
http://www.rubyinside.com/nethttp-cheat-sheet-2940.html
https://github.com/augustl/net-http-cheat-sheet

Tuesday, 13 January 2015

Dir.pwd command

class RnD1
  puts 'testing'
  puts Dir.pwd
  base_path =  File.expand_path('basics/', Dir.pwd)
  x= File.open(base_path + '/RnD1.rb')
  puts x.inspect
end


testing
C:/Users/user/workspace/RubyRnD
#<File:C:/Users/user/workspace/RubyRnD/basics/RnD1.rb>

Tuesday, 23 December 2014

xpaths

First Row in a table:FIrst row is having class=odd

     $x("//tr[1][@class='odd']")

hyperlink in first row of a table:

     "//tr[1][@class='odd']/td[2]/a"  or    
     $x("//table/tbody/tr[1][@class='odd']/td[2]/a")    whole hierarchy.. test it in firebug console