Skip to content

Instantly share code, notes, and snippets.

View karthiks's full-sized avatar
🎯
Focusing

Karthik Sirasanagandla karthiks

🎯
Focusing
View GitHub Profile
@karthiks
karthiks / my_sample.rb
Created August 25, 2012 15:42
sleep vs. wait_until
#my_target_page.rb
def add_and_save_notes notes
fill_in("my_target_text_box", :with => notes)
click_button "Save" # This makes an AJAX request and adds new row to the table upon successfully saving
sleep(3) #<-- This is BAD code. You should have the line below in place of this one.
#wait_until { has_text?(notes) } #<-- This is GOOD practice that enables test stability and hence faith in test results
end
def has_note? notes
@karthiks
karthiks / automation_spec_helper.rb
Created August 25, 2012 16:35
Tweaking Firefox preference to automatically download files to custom location
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = "#{Rails.root}/tmp/webdriver-downloads"
profile['browser.download.folderList'] = 2 # implies custom location
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
Capybara::Selenium::Driver.new(app, :browser => :firefox ,:profile => profile)
#...
end
@karthiks
karthiks / my_target_page.rb
Created August 25, 2012 16:46
Expect for right elements in page
#my_target_page.rb
def add_and_save_notes notes
fill_in("my_target_text_box", :with => notes)
click_button "Save" # This makes an AJAX request and adds new row to the table upon successfully saving
wait_until { has_link?("Edit note") } #<-- This is BAD, esp. when the note to be added is yet another row in a table having "Edit note" link for every corresponding row in that table
#wait_until { has_text?(notes) } #<-- This is GOOD practice that enables test stability and hence faith in test results
end
@karthiks
karthiks / my_target_page.rb
Created August 25, 2012 17:58
DRY vs Soc 1
#my_target_page.rb
def verify_edit_link_presence
has_link?("Edit").should be_true
end
#my_target_spec
it "blah blah blah"
@my_target_page.do_some_action
@karthiks
karthiks / my_target_page.rb
Created August 25, 2012 18:12
DRY vs Soc - The right balance
#my_target_page.rb
def has_edit_link?
has_link?("Edit")
end
#my_target_spec
it "blah blah blah"
@my_target_page.do_some_action
@karthiks
karthiks / .vimrc
Created October 20, 2012 15:27 — forked from localshred/.vimrc
Vimrc
"-------------------------------------------------------------------[Vundle]----
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'kien/ctrlp.vim'
Bundle 'mileszs/ack.vim'
@karthiks
karthiks / Global.GitConfig
Created January 3, 2013 15:09
Global .gitconfig settings for external diff/merge tool (Note: The order is important)
[mergetool "kdiff3"]
path = /usr/local/bin/kdiff3
keepBackup = false
trustExitCode = false
[mergetool "diffmerge"]
cmd = /Applications/DiffMerge.app/Contents/MacOS/diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE
keepBackup = false
trustExitCode = false
[merge]
tool = diffmerge
@karthiks
karthiks / functionReturningValue.js
Last active January 1, 2016 03:18
Example of function returning value
function f() {
return 123;
}
f(); //returns 123
@karthiks
karthiks / functionWithoutReturnStatement.js
Last active January 1, 2016 03:18
Example of a function without a return statement
function f() {
// No return statement
}
f(); //returns "undefined"
@karthiks
karthiks / theFunctionDeclaration.js
Last active January 1, 2016 03:29
The Function Declaration Example
/*
The Pattern:
function name(param1, param2, .., paramN) {
//statements
}
*/
//Example function declaration
function add(x, y) {
return x + y;