Best Konacha code snippet using Konacha.initialize
runner.rb
Source:runner.rb
...5 def self.start6 new.run7 end8 attr_reader :io9 def initialize(options = {})10 @io = options[:output] || STDOUT11 end12 def run13 before = Time.now14 spec_runners.each { |spec_runner| spec_runner.run } # prints dots15 io.puts ""16 io.puts ""17 failure_messages.each { |msg| io.write("#{msg}\n\n") }18 seconds = "%.2f" % (Time.now - before)19 io.puts "Finished in #{seconds} seconds"20 io.puts "#{examples.size} examples, #{failed_examples.size} failures, #{pending_examples.size} pending"21 passed?22 end23 def examples24 spec_runners.map { |spec_runner| spec_runner.examples }.flatten25 end26 def pending_examples27 examples.select { |example| example.pending? }28 end29 def failed_examples30 examples.select { |example| example.failed? }31 end32 def passed?33 examples.all? { |example| example.passed? }34 end35 def failure_messages36 examples.map { |example| example.failure_message }.compact37 end38 def session39 @session ||= Capybara::Session.new(Konacha.driver, Konacha.application)40 end41 def spec_runners42 @spec_runners ||= Konacha::Spec.all.map { |spec| SpecRunner.new(self, spec) }43 end44 end45 class SpecRunner46 attr_reader :runner, :spec, :examples47 def initialize(runner, spec)48 @runner = runner49 @spec = spec50 end51 def session52 runner.session53 end54 def io55 runner.io56 end57 def colorize_dots(dots)58 dots = dots.chars.map do |d|59 case d60 when 'E', 'F'; d.red61 when 'P'; d.yellow62 when '.'; d.green63 else; d64 end65 end66 dots.join ''67 end68 def run69 session.visit(spec.url)70 dots_printed = 071 begin72 sleep 0.173 done, dots = session.evaluate_script('[Konacha.done, Konacha.dots]')74 if dots75 io.write colorize_dots(dots[dots_printed..-1])76 io.flush77 dots_printed = dots.length78 end79 end until done80 @examples = JSON.parse(session.evaluate_script('Konacha.getResults()')).map do |row|81 Example.new(row)82 end83 rescue => e84 msg = [e.inspect]85 msg << e.message unless e.message.blank?86 raise Konacha::Error, "Error communicating with browser process:\n#{msg.join("\n")}"87 end88 end89 class Example90 def initialize(row)91 @row = row92 end93 def passed?94 @row['passed']95 end96 def pending?97 @row['pending']98 end99 def failed?100 !(@row['passed'] || @row['pending'])101 end102 def failure_message103 if failed?104 msg = []...
engine_spec.rb
Source:engine_spec.rb
...7 end8 context "with a FORMAT environment variable" do9 before do10 class TestFormatter11 def initialize(io)12 end13 end14 ENV['FORMAT'] = 'Konacha::Formatter,TestFormatter'15 end16 after do17 Object.send(:remove_const, :TestFormatter)18 ENV.delete('FORMAT')19 end20 it "creates the specified formatters" do21 Konacha::Formatter.should_receive(:new).with(STDOUT) { :formatter }22 TestFormatter.should_receive(:new).with(STDOUT) { :test_formatter }23 Konacha::Engine.formatters.should == [:formatter, :test_formatter]24 end25 end...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!