Skip to content

Instantly share code, notes, and snippets.

View karlosmid's full-sized avatar

Karlo Smid karlosmid

View GitHub Profile
@karlosmid
karlosmid / us_week_number.rb
Created January 31, 2015 17:23
us week number in pure ruby
def us_week_number us_date
week = Time.local(us_date.year,us_date.month,us_date.day).strftime("%U").to_i
if week == 0
Time.local(us_date.year - 1,12,31).strftime("%U").to_i
else
week
end
end
@karlosmid
karlosmid / cucumber_embed_screenshot_base64.rb
Created February 13, 2015 12:39
How to embed screenshot in Cucumber report across various environments
After do |scenario|
if scenario.failed?
encoded_img = @browser.screenshot.base64
embed("data:image/png;base64,#{encoded_img}",'image/png')
end
@browser.close
Cucumber.wants_to_quit = true if scenario.failed?
end
@karlosmid
karlosmid / task_tech_2.md
Last active August 29, 2015 14:15
Task, technical part for Tentamen job interview

This is technical part for Tentamen job interview.

  1. You need to automate firefox browser for following scenarios:

Successfull send contact at https://www.tentamen.hr/contacts/new Wrong email
Wrong email but different than first one.

Every scenario must have check part in the end. You can choose check that you want.

@karlosmid
karlosmid / http_proxy_fail.rb
Created February 21, 2015 10:12
selenium-webdriver and http_proxy environment variable fail
require 'watir-webdriver'
ENV['http_proxy'] = '31.25.187.202:3128'
b = Watir::Browser.new
@karlosmid
karlosmid / http_proxy_exception.md
Created February 21, 2015 10:13
selenium-webdriver and http_proxy environment variable exception
Selenium::WebDriver::Error::WebDriverError: unexpected response, code=503, content-type="text/html"

from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:66:in `create_response'
from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'
from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:101:in `create_session'
from /Users/karlosmid/.rvm/gems/ruby-2.1.2@lawfirmmatrix/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
from /Users/karlos
@karlosmid
karlosmid / rspec_matchers_cucmber.rb
Created March 7, 2015 10:05
where to put rspec matchers in cucumber project
Then /^login box is visible$/ do
expect(on(LoginPage).is_login_box_visible).to be_truthy
end
@karlosmid
karlosmid / rspec_matcher_exception_page_object.rb
Created March 7, 2015 10:09
rspec matcher exception in page object
undefined method `expect` for #\<LoginPage:0x007fef0c9d2a80\> (NoMethodError)
@karlosmid
karlosmid / add_unique_index.rb
Created March 21, 2015 15:05
Add unique index
class AddUniqueIndexToProviders < ActiveRecord::Migration
def change
add_index :providers, [:name, :url], :unique => true
end
end
@karlosmid
karlosmid / check_unique.rb
Created March 21, 2015 15:09
Check for PG::UniqueViolation exception
def create
@provider = Provider.new(provider_params)
begin
if @provider.save
redirect_to @provider
else
render 'new'
end
rescue Exception => what
if what.message.include? "PG::UniqueViolation"
@karlosmid
karlosmid / phantomjs_console_log.rb
Last active August 29, 2015 14:17
suppress phantomjs console log
switches = ["--webdriver-loglevel=NONE"]
browser = Watir::Browser.new :phantomjs, :args => switches