Created
August 28, 2014 05:46
-
-
Save d3zorg/b913fb13576ba263c626 to your computer and use it in GitHub Desktop.
env.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
HTTP_TIMEOUT = 30 | |
def change_separator directories | |
dir_path = directories.join(File::SEPARATOR) | |
dir_path.gsub! File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR | |
end | |
def includeScripts | |
$:.unshift(File.dirname(__FILE__)) | |
$:.unshift(File.dirname(__FILE__) + '/../..') | |
$:.unshift(File.dirname(__FILE__) + '/../../..') | |
require 'rubygems' | |
begin | |
require 'rspec/expectations' | |
rescue LoadError | |
require 'spec/expectations' | |
end | |
require 'cucumber/formatter/unicode' | |
require 'capybara/cucumber' | |
require 'capybara/poltergeist' | |
require 'platformtestkit' | |
require 'selenium/client' | |
require 'selenium-webdriver' | |
require 'securerandom' | |
require 'constant' | |
end | |
def setupCapybara | |
Capybara.register_driver :firefox_driver do |app| | |
profile = Selenium::WebDriver::Firefox::Profile.new | |
profile['browser.download.folderList'] = 2 # custom location | |
profile['browser.download.dir']= change_separator [Dir.pwd, "features", "tmp"] | |
profile['browser.helperApps.neverAsk.saveToDisk']= "application/pdf, application/x-pkcs7, text/xml, text/csv, text/plain, text/log, application/zip, application/x-gzip, text/html, application/excel, application/vnd.ms-excel, application/x-excel, application/x-msexcel" | |
profile['pdfjs.disabled'] = true | |
profile['capability.policy.default.Window.print'] = "noAccess" | |
profile['permissions.default.image'] = 2 | |
profile['plugin.state.npcades'] = 2 | |
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile) | |
end | |
Capybara.default_driver = :firefox_driver | |
Capybara.current_session.driver.browser.manage.window.resize_to(1920, 1024) | |
Capybara.default_wait_time = HTTP_TIMEOUT | |
Capybara.default_selector = :xpath | |
end | |
def addKits | |
World(PlatformTestKit) | |
end | |
includeScripts | |
setupCapybara | |
addKits | |
TEST_DATE = Time.now.strftime('%Y-%m-%d-%H-%M-%S') | |
LOG_PATH = "./test_errors/#{TEST_DATE}" | |
def onError scenario | |
require 'fileutils' | |
feature, secenario_name, error = [scenario.description, scenario.title, scenario.exception.message] | |
name = "#{LOG_PATH}/#{feature}_#{secenario_name}" | |
begin | |
FileUtils.mkdir_p LOG_PATH unless File.exists?(LOG_PATH) | |
page.save_screenshot "#{name}.png" | |
file = File.open("#{name}.log", "w") | |
file.write(error) | |
Capybara.save_page "#{name}.html" | |
rescue Exception => e | |
puts "Error while loging #{e.to_s}" | |
end | |
end | |
After do |scenario| | |
onError scenario if scenario.failed? | |
end | |
AfterStep do | |
sleep (ENV['PAUSE'] || 0).to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment