Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View abotalov's full-sized avatar

Andrei Botalov abotalov

View GitHub Profile
@abotalov
abotalov / conftest.py
Created March 21, 2018 13:08
Pytest issue
from xdist.scheduler import LoadScopeScheduling
def pytest_xdist_make_scheduler(config, log):
return LoadScopeScheduling(config, log)
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/xml" }, [html] ] }
session = Capybara::Session.new(:selenium, $app)
session.visit("/")
puts "Capybara text: #{session.all('div').map { |el| el.text.codepoints }}" # => [[97, 32, 98], [97, 32, 98], [97, 32, 98]]
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
session = Capybara::Session.new(:selenium, $app)
session.visit("/")
puts "Capybara text: #{session.all('div').map { |el| el.text.codepoints }}" # => [[97, 32, 98], [97, 32, 98], [97, 32, 98]]
@abotalov
abotalov / check_racktest_text.rb
Created May 20, 2014 21:33
Check speed of text in rack_test
require 'capybara'
require 'benchmark'
[
'http://www.stackoverflow.com',
'http://www.google.com',
'http://www.facebook.com',
'http://www.github.com',
].each do |url|
sess = Capybara::Session.new(:selenium)
@abotalov
abotalov / first.rb
Last active August 29, 2015 13:57
Check performance of first, match: :first
require 'capybara'
require 'benchmark'
html = DATA.read
$app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
def benchmark_average
sum = 0
session = Capybara::Session.new(:selenium, $app)
require "capybara"
require 'selenium-webdriver'
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
Capybara.register_driver :chrome do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => [ "start-maximized" ]})
Capybara::Selenium::Driver.new(app, {:browser => :chrome, :desired_capabilities => caps})
end
@abotalov
abotalov / test.rb
Created November 4, 2013 20:30
Attempt to reproduce issue from http://stackoverflow.com/q/19733271/841064
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
sleep 1 # Just to verify that file isn't chosen
sess.attach_file('file_upload', '/tmp/temp.txt')
sleep 1 # Just to verify that file is chosen
@abotalov
abotalov / with_capybara.rb
Created August 19, 2013 22:33
Method that allows to run a couple of Capybara methods in a block. See http://stackoverflow.com/q/18293303/841064
require 'capybara'
class Capybara::Selenium::Driver
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
end
@browser
end
end
@abotalov
abotalov / test.rb
Created August 19, 2013 22:24
Capybara: quit browser manually, see http://stackoverflow.com/q/18293303/841064
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
class Capybara::Selenium::Driver
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
end
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
sess.find(:xpath,"//a[contains(text(),'Foo')]").click # Element looks like clicked after that
sleep 3