Skip to content

Instantly share code, notes, and snippets.

@bootstraponline
bootstraponline / fail.rb
Last active December 20, 2015 14:39
Rewrite block source with instance eval
require 'rubygems'
require 'method_source'
ary = []
class Test
def self.run &block
define_method :run_method do
# https://www.ruby-forum.com/topic/4416134#1117671
eval %(ary << 1; puts 'complete'), block.binding
@bootstraponline
bootstraponline / js_vs_rb.md
Last active December 20, 2015 03:28
JavaScript vs Ruby

Ruby

scroll_to('views').click
scroll_to('tabs').click
scroll_to('content by id').click
s_text(0).selected?.must_equal false
s_text(1).selected?.must_equal true
@bootstraponline
bootstraponline / xml_to_txt.rb
Last active December 20, 2015 01:09
XML to txt
# gem install nokogiri escape_utils
text = ''
reader = Nokogiri::XML::Reader(File.open(file))
reader.each do |n|
text += ' ' + n.value + ' ' if n.value?
end
# double unescape
text = EscapeUtils.unescape_html text
text = EscapeUtils.unescape_html text
@bootstraponline
bootstraponline / fail.rb
Last active December 19, 2015 21:58
Parallel minitest
require 'rubygems'
$at_once = '3'
$total = 6
ENV['N'] = $at_once
require 'selenium-webdriver'
require 'minitest'
require 'minitest/hell'
@bootstraponline
bootstraponline / appium_android.bash
Last active December 17, 2015 08:29
Start appium from source, open emulator, and cd into test folder.
# code goes in ~/.bash_profile
# tested on OS X
export APPIUM_HOME="$HOME/Desktop/appium"
export TEST_HOME="$HOME/path/to/tests"
export APPIUM_AVD="t18"
function three {
# does node exist?
[[ $(ps axo pid,command | grep "[0-9]\+ node" | wc -l) -gt 0 ]] && \
@bootstraponline
bootstraponline / export.js
Created February 27, 2013 23:09
Export devices that pass 100% from AppThwack.
// device name : result
var pairs = $x('//*[@id="by_device"]/div/div/div');
for (var a = 0, len = pairs.length / 2; a < len; a+=2) {
if (all_passed(pairs[a+1])) {
console.log(device_name(pairs[a]));
}
}
// device name. pairs[0]
[9] pry(main)> @driver.execute_script 'mobile: tap', :tapCount => 1, :touchCount => 1, :duration => 0.1, :x => 0.8, :y => 0.4
:post
"session/6279234c-cd7c-40cb-8549-69c294c66147/execute"
{:script=>"mobile: tap", :args=>[{:tapCount=>1, :touchCount=>1, :duration=>0.1, :x=>0.8, :y=>0.4}]}
Selenium::WebDriver::Error::WebDriverError: unexpected response, code=400, content-type="text/html"
Parameters for mobile method did not match the definition. Required params must be sent as script args in this order: ["tapCount","touchCount","duration","x","y"]
from /selenium-webdriver-2.29.0/lib/selenium/webdriver/remote/http/common.rb:66:in 'create_response'
[10] pry(main)> a = {:script=>"mobile: tap", :args=>[{:tapCount=>1, :touchCount=>1, :duration=>0.1, :x=>0.8, :y=>0.4}]}.to_json; puts a
@bootstraponline
bootstraponline / app_installation_hooks.rb
Created January 23, 2013 00:02
Use clear_app_data to install apk once instead of after each scenario. export RESET_BETWEEN_SCENARIOS=1
require 'calabash-android/management/app_installation'
AfterConfiguration do |config|
FeatureNameMemory.feature_name = nil
end
$first_run = true
Before do |scenario|
@scenario_is_outline = (scenario.class == Cucumber::Ast::OutlineTable::ExampleRow)
# Implement is focused app using dumpsys window windows
def is_focused_app app
output = `#{adb_command} shell dumpsys window windows`
return false if output.nil?
target = nil
output.each_line do |line|
if line.include? 'mFocusedApp'
target = line