Skip to content

Instantly share code, notes, and snippets.

View p0deje's full-sized avatar
👶
Slow to respond

Alex Rodionov p0deje

👶
Slow to respond
View GitHub Profile
@p0deje
p0deje / yardtest.html
Created February 7, 2014 12:59
Generated YARD doc using macros for watir/watir-webdriver#215
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documentation by YARD 0.8.7.3</title>
<style type="text/css">
body {
padding: 0 20px;
font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif;
@p0deje
p0deje / Vagrantfile
Last active August 29, 2015 13:57
Vagrantfile to develop and test Vagrant for Linux using DigitalOcean
# I'm running OS X and I need to develop and test Vagrant features
# which are specific to Linux-only, i.e. I need "physical" Linux machine.
# I've finally stuck with creating DigitalOcean VM and installing
# everything necessary for development there. It's magical
# Vagrant-powered Vagrant-development Vagrantfile.
#
# First, start the VM which will be the host:
# $ vagrant up host --provider=digital_ocean
#
# Now, you can start VM in VM which will be used for Vagrant testing:
require 'watir-webdriver'
browser = Watir::Browser.new
browser.goto 'http://google.com'
browser.button(name: 'btnK').disabled?
#=> false
browser.button(name: 'btnK').enabled?
#=> true
require 'benchmark'
require 'selenium-webdriver'
old_locator = ".//input[not(@type) or (@type!='file' and @type!='radio' and @type!='checkbox' and @type!='submit' and @type!='reset' and @type!='image' and @type!='button' and @type!='hidden' and @type!='datetime' and @type!='date' and @type!='month' and @type!='week' and @type!='time' and @type!='datetime-local' and @type!='range' and @type!='color')]"
new_locator = ".//input[not(@type) or (translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='file' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='radio' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='checkbox' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='submit' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='reset' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='image' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','ab
@p0deje
p0deje / scroll.rb
Created December 10, 2012 05:59
Selenium wrapped select
require 'selenium-webdriver'
browser = Selenium::WebDriver.for :firefox
browser.get 'http://www.commonfloor.com/'
# first open up drop down
browser.find_element(xpath: '//div[@id="city_chzn"]/a').click
# now click necessary element (note that it won't work with selenium 2.27)
browser.find_element(xpath: '//div[@id="city_chzn"]//li[contains(.,"Bangalore")]').click
@p0deje
p0deje / output
Created December 10, 2012 06:15
Test case for Selenium #4890
❯ ruby selenium_scroll_issue.rb
/Users/p0deje/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.1/lib/selenium/webdriver/remote/bridge.rb:516:in `getElementLocationOnceScrolledIntoView': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/p0deje/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.1/lib/selenium/webdriver/common/element.rb:215:in `location_once_scrolled_into_view'
from selenium_scroll_issue.rb:5:in `<main>'
@p0deje
p0deje / elementFromPoint.md
Last active November 19, 2015 05:34
Inconsistencies in elementFromPoint

elementFromPoint inconsistencies

Steps to reproduce:

  1. Open the HTML page.
  2. Execute snippet in console.

Browsers:

  1. Firefox 38.3.0.
require 'watir-webdriver'
begin
browser = Watir::Browser.new
browser.goto "data:text/html,#{DATA.read}"
rows = browser.table.rows
rows.each do |tr|
p tr.td(index: 2).text
end
ensure
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps)
browser = Watir::Browser.new(driver)
@p0deje
p0deje / example.rb
Last active December 17, 2015 16:49
DOM-based waiting API for Watir
class Page
#
# Waits until DOM subtree changes in element.
#
# @param [Watir::Element] element
#
def wait_for_dom(element)
browser.execute_script File.read('wait_for_dom.js'), element
Watir::Wait.until { browser.execute_script('return Watir.DOMReady;').to_i == 0 }